On Tue, Aug 19, 2025 at 10:31 AM H.J. Lu <
hjl....@gmail.com> wrote:
>
> On Tue, Aug 19, 2025 at 1:36 AM Jan Beulich <
jbeu...@suse.com> wrote:
> >
> > PR ld/33291
> >
> > As indicated in other recent commits, the three properties can be
> > largely independent (ELF generally being the target here): Entry size
> > doesn't require either of merge/strings, and strings also doesn't
> > require merge. Commit 98e6d3f5bd4e ("gas/ELF: allow specifying entity
> > size for arbitrary sections") uncovered issues with ld's handling.
> >
> > Zap entry size when it doesn't match between input sections. In that
> > case SEC_MERGE and SEC_STRINGS also need to be removed, as their
> > underlying granularity is lost. Then deal with SEC_MERGE and
> > SEC_STRINGS separately.
> >
> > Otoh record entry size from the first input independent of SEC_MERGE.
> > ---
> > The handling of the three attributes still isn't correct when it comes
> > to data allocation statements within the section, or position changes
> > (including alignment other than at the start): These would all need to
> > clear entry size (for not coming with an entry size themselves), and
> > hence also SEC_MERGE and SEC_STRINGS.
> >
> > --- a/ld/ldlang.c
> > +++ b/ld/ldlang.c
> > @@ -2857,14 +2857,24 @@ lang_add_section (lang_statement_list_ty
> > /* Only set SEC_READONLY flag on the first input section. */
> > flags &= ~ SEC_READONLY;
> >
> > - /* Keep SEC_MERGE and SEC_STRINGS only if they are the same. */
> > - if ((output->bfd_section->flags & (SEC_MERGE | SEC_STRINGS))
> > - != (flags & (SEC_MERGE | SEC_STRINGS))
> > - || ((flags & SEC_MERGE) != 0
> > - && output->bfd_section->entsize != section->entsize))
> > + /* Keep entry size, SEC_MERGE, and SEC_STRINGS only if entry sizes are
> > + the same. */
> > + if (output->bfd_section->entsize != section->entsize)
> > {
> > - output->bfd_section->flags &= ~ (SEC_MERGE | SEC_STRINGS);
> > - flags &= ~ (SEC_MERGE | SEC_STRINGS);
> > + output->bfd_section->entsize = 0;
> > + flags &= ~(SEC_MERGE | SEC_STRINGS);
> > + }
> > +
> > + /* Keep SEC_MERGE and SEC_STRINGS (each) only if they are the same. */
> > + if ((output->bfd_section->flags ^ flags) & SEC_MERGE)
> > + {
> > + output->bfd_section->flags &= ~SEC_MERGE;
> > + flags &= ~SEC_MERGE;
> > + }
> > + if ((output->bfd_section->flags ^ flags) & SEC_STRINGS)
> > + {
> > + output->bfd_section->flags &= ~SEC_STRINGS;
> > + flags &= ~SEC_STRINGS;
> > }
> > }
> > output->bfd_section->flags |= flags;
> > @@ -2879,8 +2889,7 @@ lang_add_section (lang_statement_list_ty
> > link_info.output_bfd,
> > output->bfd_section,
> > &link_info);
> > - if ((flags & SEC_MERGE) != 0)
> > - output->bfd_section->entsize = section->entsize;
> > + output->bfd_section->entsize = section->entsize;
> > }
> >
> > if ((flags & SEC_TIC54X_BLOCK) != 0
>
> A testcase is needed to verify that ld does the right thing.
>
> --
> H.J.
gABI has
sh_entsize
Some sections hold a table of fixed-size entries, such as a symbol
table. For such a section, this member gives the size in bytes of each
entry. The member contains 0 if the section does not hold a table of
fixed-size entries.
SHF_MERGE
The data in the section may be merged to eliminate duplication. Unless
the SHF_STRINGS flag is also set, the data elements in the section are
of a uniform size. The size of each element is specified in the
section header's sh_entsize field. If the SHF_STRINGS flag is also
set, the data elements consist of null-terminated character strings.
The size of each character is specified in the section header's
sh_entsize field.
Each element in the section is compared against other elements in
sections with the same name, type and flags. Elements that would have
identical values at program run-time may be merged. Relocations
referencing elements of such sections must be resolved to the merged
locations of the referenced values. Note that any relocatable values,
including values that would result in run-time relocations, must be
analyzed to determine whether the run-time values would actually be
identical. An ABI-conforming object file may not depend on specific
elements being merged, and an ABI-conforming link editor may choose
not to merge specific elements.
SHF_STRINGS
The data elements in the section consist of null-terminated character
strings. The size of each character is specified in the section
header's sh_entsize field.
If sh_entsize != 0 and SHF_MERGE or SHF_STRINGS bits are't set, ELF tools
may not work properly. I think
commit 98e6d3f5bd4e7e3cbd2718151cc54692f6740b65
Author: Jan Beulich <
jbeu...@suse.com>
AuthorDate: Fri Aug 15 12:19:59 2025 +0200
Commit: Jan Beulich <
jbeu...@suse.com>
CommitDate: Fri Aug 15 12:19:59 2025 +0200
gas/ELF: allow specifying entity size for arbitrary sections
The spec doesn't tie entity size to just SHF_MERGE and SHF_STRINGS
sections. Introduce a new "section letter" 'E' to allow recording (and
checking) of entity size even without 'M' or 'S'.
should be reverted. If we want to allow non-0 entity size for
arbitrary sections,
it should be discussed at gABI group first:
https://groups.google.com/g/generic-abi
which is CCed.
--
H.J.