BFD: Make `bfd_finalize_section_relocs' return status

Update `bfd_finalize_section_relocs' to return status so that backends
can fail in this interface and propagate that to the respective callers.
Add suitable error reporting there.  No failure cases in the existing
handlers though.
This commit is contained in:
Maciej W. Rozycki
2026-01-14 22:28:43 +00:00
parent e9499dfeb3
commit ca2186f9ca
16 changed files with 54 additions and 26 deletions

View File

@@ -2613,7 +2613,7 @@ long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
long bfd_canonicalize_reloc
(bfd *abfd, asection *sec, arelent **loc, asymbol **syms);
void bfd_finalize_section_relocs
bool bfd_finalize_section_relocs
(bfd *abfd, asection *sec, arelent **rel, unsigned int count);
#define bfd_finalize_section_relocs(abfd, asect, location, count) \
@@ -7664,7 +7664,7 @@ typedef struct bfd_target
long (*_get_reloc_upper_bound) (bfd *, sec_ptr);
long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **,
struct bfd_symbol **);
void (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
bool (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
unsigned int);
/* See documentation on reloc types. */
reloc_howto_type *

View File

@@ -2202,7 +2202,7 @@ FUNCTION
bfd_finalize_section_relocs
SYNOPSIS
void bfd_finalize_section_relocs
bool bfd_finalize_section_relocs
(bfd *abfd, asection *sec, arelent **rel, unsigned int count);
DESCRIPTION

View File

@@ -314,7 +314,7 @@ elf64_sparc_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
/* Install a new set of internal relocs. */
static void
static bool
elf64_sparc_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
asection *asect,
arelent **location,
@@ -326,6 +326,7 @@ elf64_sparc_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
asect->flags |= SEC_RELOC;
else
asect->flags &= ~SEC_RELOC;
return true;
}
/* Write out the relocs. */

View File

@@ -447,7 +447,7 @@ extern long _bfd_norelocs_get_reloc_upper_bound
(bfd *, asection *) ATTRIBUTE_HIDDEN;
extern long _bfd_norelocs_canonicalize_reloc
(bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
extern void _bfd_norelocs_finalize_section_relocs
extern bool _bfd_norelocs_finalize_section_relocs
(bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN;
extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup
(bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;

View File

@@ -199,13 +199,13 @@ _bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED,
return 0;
}
void
bool
_bfd_norelocs_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
asection *sec ATTRIBUTE_UNUSED,
arelent **relptr ATTRIBUTE_UNUSED,
unsigned int count ATTRIBUTE_UNUSED)
{
/* Do nothing. */
return true;
}
bool

View File

@@ -453,7 +453,7 @@ extern long _bfd_norelocs_get_reloc_upper_bound
(bfd *, asection *) ATTRIBUTE_HIDDEN;
extern long _bfd_norelocs_canonicalize_reloc
(bfd *, asection *, arelent **, asymbol **) ATTRIBUTE_HIDDEN;
extern void _bfd_norelocs_finalize_section_relocs
extern bool _bfd_norelocs_finalize_section_relocs
(bfd *, asection *, arelent **, unsigned int) ATTRIBUTE_HIDDEN;
extern reloc_howto_type *_bfd_norelocs_bfd_reloc_type_lookup
(bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN;
@@ -3530,7 +3530,7 @@ bfd_byte *bfd_generic_get_relocated_section_contents
bool relocatable,
asymbol **symbols) ATTRIBUTE_HIDDEN;
void _bfd_generic_finalize_section_relocs
bool _bfd_generic_finalize_section_relocs
(bfd *abfd,
sec_ptr section,
arelent **relptr,

View File

@@ -8365,7 +8365,7 @@ INTERNAL_FUNCTION
_bfd_generic_finalize_section_relocs
SYNOPSIS
void _bfd_generic_finalize_section_relocs
bool _bfd_generic_finalize_section_relocs
(bfd *abfd,
sec_ptr section,
arelent **relptr,
@@ -8375,7 +8375,7 @@ DESCRIPTION
Installs a new set of internal relocations in SECTION.
*/
void
bool
_bfd_generic_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
sec_ptr section,
arelent **relptr,
@@ -8387,6 +8387,7 @@ _bfd_generic_finalize_section_relocs (bfd *abfd ATTRIBUTE_UNUSED,
section->flags |= SEC_RELOC;
else
section->flags &= ~SEC_RELOC;
return true;
}
/*

View File

@@ -438,7 +438,7 @@ BFD_JUMP_TABLE macros.
. long (*_get_reloc_upper_bound) (bfd *, sec_ptr);
. long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **,
. struct bfd_symbol **);
. void (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
. bool (*_bfd_finalize_section_relocs) (bfd *, sec_ptr, arelent **,
. unsigned int);
. {* See documentation on reloc types. *}
. reloc_howto_type *

View File

@@ -4555,7 +4555,10 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
}
if (relsize == 0)
bfd_finalize_section_relocs (obfd, osection, NULL, 0);
{
if (!bfd_finalize_section_relocs (obfd, osection, NULL, 0))
return false;
}
else
{
if (isection->orelocation != NULL)
@@ -4596,8 +4599,10 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
*w_relpp = 0;
}
bfd_finalize_section_relocs (obfd, osection,
relcount == 0 ? NULL : relpp, relcount);
if (!bfd_finalize_section_relocs (obfd, osection,
relcount == 0 ? NULL : relpp,
relcount))
return false;
}
return true;
}

View File

@@ -685,7 +685,13 @@ write_coff_file (const char *filename, const char *target,
return false;
}
bfd_finalize_section_relocs (abfd, sec, cwi.relocs, cwi.reloc_count);
if (!bfd_finalize_section_relocs (abfd, sec, cwi.relocs, cwi.reloc_count))
{
bfd_nonfatal ("bfd_finalize_section_relocs");
bfd_close_all_done (abfd);
free (cwi.relocs);
return false;
}
offset = 0;
for (d = cwi.dirs.d; d != NULL; d = d->next)

View File

@@ -1517,13 +1517,14 @@ coff_frob_file_after_relocs (void)
/* Set relocations for the section and then store the number of relocations
in its aux entry. */
void
bool
obj_coff_finalize_section_relocs (asection *sec, arelent **relocs,
unsigned int n)
{
symbolS *sect_sym;
bfd_finalize_section_relocs (stdoutput, sec, n ? relocs : NULL, n);
if (!bfd_finalize_section_relocs (stdoutput, sec, n ? relocs : NULL, n))
return false;
sect_sym = section_symbol (sec);
#ifdef OBJ_XCOFF
if (S_GET_STORAGE_CLASS (sect_sym) == C_DWARF)
@@ -1531,6 +1532,7 @@ obj_coff_finalize_section_relocs (asection *sec, arelent **relocs,
else
#endif
SA_SET_SCN_NRELOC (sect_sym, n);
return true;
}
/* Implement the .section pseudo op:

View File

@@ -296,7 +296,7 @@ extern void coff_pop_insert (void);
/* We need to store the number of relocations in the section aux entry. */
#define FINALIZE_SECTION_RELOCS(sec, relocs, n) \
obj_coff_finalize_section_relocs (sec, relocs, n)
extern void obj_coff_finalize_section_relocs (asection *, arelent **,
extern bool obj_coff_finalize_section_relocs (asection *, arelent **,
unsigned int);
extern int S_SET_DATA_TYPE (symbolS *, int);

View File

@@ -1879,7 +1879,7 @@ obj_mach_o_frob_file_after_relocs (void)
/* Reverse relocations order to make ld happy. */
void
bool
obj_mach_o_reorder_section_relocs (asection *sec, arelent **rels, unsigned int n)
{
unsigned int i;
@@ -1891,7 +1891,7 @@ obj_mach_o_reorder_section_relocs (asection *sec, arelent **rels, unsigned int n
rels[i] = rels[n - i - 1];
rels[n - i - 1] = r;
}
bfd_finalize_section_relocs (stdoutput, sec, rels, n);
return bfd_finalize_section_relocs (stdoutput, sec, rels, n);
}
/* Relocation rules are different in frame sections. */

View File

@@ -101,7 +101,7 @@ extern void obj_mach_o_frob_file_after_relocs (void);
#define FINALIZE_SECTION_RELOCS(sec, relocs, n) \
obj_mach_o_reorder_section_relocs (sec, relocs, n)
extern void obj_mach_o_reorder_section_relocs (asection *, arelent **,
extern bool obj_mach_o_reorder_section_relocs (asection *, arelent **,
unsigned int);
/* Emit relocs for local subtracts, to cater for subsections-via-symbols. */

View File

@@ -1419,7 +1419,8 @@ write_relocs (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
}
#endif
FINALIZE_SECTION_RELOCS (sec, relocs, n);
if (!FINALIZE_SECTION_RELOCS (sec, relocs, n))
as_bad (_("%s: unable to finalize relocations"), sec->name);
#ifdef DEBUG3
{

View File

@@ -10640,7 +10640,13 @@ copy_section (bfd *ibfd, sec_ptr isection, void *p)
}
if (relsize == 0)
bfd_finalize_section_relocs (obfd, osection, NULL, 0);
{
if (!bfd_finalize_section_relocs (obfd, osection, NULL, 0))
{
err = _("unable to finalize relocations");
goto loser;
}
}
else
{
relpp = (arelent **) xmalloc (relsize);
@@ -10651,8 +10657,14 @@ copy_section (bfd *ibfd, sec_ptr isection, void *p)
goto loser;
}
bfd_finalize_section_relocs (obfd, osection,
relcount == 0 ? NULL : relpp, relcount);
if (!bfd_finalize_section_relocs (obfd, osection,
relcount == 0 ? NULL : relpp,
relcount))
{
free (relpp);
err = _("unable to finalize relocations");
goto loser;
}
if (relcount == 0)
free (relpp);
}