Skip to content

Commit

Permalink
aarch64: setup_gnu_properties only creates the notes section when non…
Browse files Browse the repository at this point in the history
…e exists

The creation of .note.gnu.property section should not be based on the
presence of GNU properties, but rather on whether this section exits
or not.
However, there is one exception to this: PR23900 [1]. Old linkers were
treating .note.gnu.property as a generic note section, so old objects
might contain properties inside .note instead of .note.gnu.property. In
this case, the section won't be detected but the properties are still
parsed. So the absence of the .note.gnu.property section is necessary
but not enough to create the section. The condition of the creation of
the section has also to include the absence of GNU properties.

[1] PR23900: https://sourceware.org/bugzilla/show_bug.cgi?id=23900
  • Loading branch information
Matthieu Longo committed Mar 4, 2025
1 parent c5f3649 commit 2cf9acb
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions bfd/elfxx-aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,29 +704,29 @@ _bfd_aarch64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_ty
static bfd *
_bfd_aarch64_elf_find_1st_bfd_input_with_gnu_property (
struct bfd_link_info *info,
bool *has_gnu_property)
bool *has_note_section)
{
BFD_ASSERT (has_gnu_property);
const struct elf_backend_data *obfd = get_elf_backend_data (info->output_bfd);
const struct elf_backend_data *be = get_elf_backend_data (info->output_bfd);
bfd *pbfd = info->input_bfds;
bfd *prev = NULL;
bfd *prev_bfd = NULL;
for (; pbfd != NULL; pbfd = pbfd->link.next)
if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
&& bfd_count_sections (pbfd) != 0
&& (pbfd->flags & (DYNAMIC | BFD_PLUGIN | BFD_LINKER_CREATED)) == 0
&& (obfd->elf_machine_code
&& (be->elf_machine_code
== get_elf_backend_data (pbfd)->elf_machine_code)
&& (obfd->s->elfclass == get_elf_backend_data (pbfd)->s->elfclass))
&& (be->s->elfclass == get_elf_backend_data (pbfd)->s->elfclass))
{
prev_bfd = pbfd;

/* Does the input have a list of GNU properties ? */
if (elf_properties (pbfd) != NULL)
{
*has_gnu_property = true;
return pbfd;
}
prev = pbfd;
break;
}
return prev;
if (prev_bfd != NULL)
*has_note_section =
bfd_get_section_by_name (prev_bfd, NOTE_GNU_PROPERTY_SECTION_NAME) != NULL;
return prev_bfd;
}

/* Create a GNU property section for the given bfd input. */
Expand Down Expand Up @@ -861,19 +861,28 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info)
struct elf_aarch64_obj_tdata *tdata = elf_aarch64_tdata (info->output_bfd);
uint32_t outprop = tdata->gnu_property_aarch64_feature_1_and;

bool has_gnu_property = false;
bool has_note_section = false;
bfd *ebfd =
_bfd_aarch64_elf_find_1st_bfd_input_with_gnu_property (info,
&has_gnu_property);
&has_note_section);

/* If ebfd != NULL it is either an input with property note or the last input.
Either way if we have an output GNU property that was provided, we should
add it (by creating a section if needed). */
if (ebfd != NULL)
{
/* If no GNU property node was found, create the GNU property note
section. */
if (!has_gnu_property)
/* If no GNU property note section was found, create one.
Note: If there is no .gnu.note.property section, we might think that
elf_properties (ebfd) is always NULL. However, this is not always
true. In PR23900: old linkers were treating .note.gnu.property as a
generic note section, so old objects might contain properties inside
.note instead of .note.gnu.property. In this case, the section won't be
detected but the properties are still parsed. Consequently,
elf_properties (ebfd) is populated and different from NULL (see
https://sourceware.org/bugzilla/show_bug.cgi?id=23900 for more
details). */
if (!has_note_section && elf_properties (ebfd) == NULL)
_bfd_aarch64_elf_create_gnu_property_section (info, ebfd);

/* Merge the found input property with output properties. Note: if no
Expand Down

0 comments on commit 2cf9acb

Please sign in to comment.