From: "H.J. Lu" <hjl.tools@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: x86-64-abi <x86-64-abi@googlegroups.com>,
Binutils <binutils@sourceware.org>,
GNU C Library <libc-alpha@sourceware.org>
Subject: Re: PT_NOTE alignment, NT_GNU_PROPERTY_TYPE_0, glibc and gold
Date: Thu, 16 Aug 2018 06:39:26 -0700 [thread overview]
Message-ID: <CAMe9rOo2Qw7UV8ApqtN79=L47wtWGnvzakfFveQmoUyjK=jpew@mail.gmail.com> (raw)
In-Reply-To: <480f513b-cfee-311a-0793-55eec81cd0fa@redhat.com>
On Thu, Aug 16, 2018 at 6:31 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 08/16/2018 03:19 PM, H.J. Lu wrote:
>>
>> On Thu, Aug 16, 2018 at 6:00 AM, Florian Weimer <fweimer@redhat.com>
>> wrote:
>>>
>>> On 08/07/2018 10:41 PM, H.J. Lu wrote:
>>>>
>>>>
>>>> The .note.gnu.property section with NT_GNU_PROPERTY_TYPE_0 has been
>>>> added to Linux Extensions to gABI:
>>>>
>>>> https://github.com/hjl-tools/linux-abi
>>>>
>>>> GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED are
>>>> processor-specific program property types for i386 and x86-64.
>>>
>>>
>>>
>>> The specification is incomplete as far as alignment matters are
>>> concerned.
>>
>>
>> https://github.com/hjl-tools/linux-abi/wiki/linux-abi-draft.pdf
>>
>> has
>>
>> 2.1.7 Alignment of Note Sections
>>
>> All entries in a PT_NOTE segment have the same alignment which equals to
>> the
>> p_align field in program header.
>> According to gABI, each note entry should be aligned to 4 bytes in 32-bit
>> objects or 8 bytes in 64-bit objects. But .note.ABI-tag section (see
>> Section 2.1.6) and .note.gnu.build-id section (see Section 2.1.4) are
>> aligned
>> to 4 bytes in both 32-bit and 64-bit objects. Note parser should use
>> p_align for
>> note alignment, instead of assuming alignment based on ELF file class.
>
>
> This is still ambiguous, particularly based on your comments below.
https://github.com/hjl-tools/linux-abi/wiki/linux-abi-draft.pdf
conforms to gABI unless stated otherwise.
>>> Is the link editor supposed to maintain separate segments for notes with
>>> different alignments? Or is it possible to merge the notes into a single
>>> segment, potentially after adjusting alignment?
>>>
>>
>> It is possible. We just need to place 4-byte aligned notes after 8-byte
>> aligned notes.
>
>
> Based on section 2.1.7, this would not be valid by itself because the
> section needs to have 8-byte alignment (to satisfy the property notes
> requirement). All notes in the segment need to have the same alignment
> (because p_align is supposed to be used for parsing). So reordering alone
> will not produce a valid segment.
>
> Part of the problem is that the note header is 12 bytes (not a multiple of
> 8), and that the name and descriptor lengths do not include the padding
> (which makes sense), so you really need a correct source of alignment.
>
> If we want to generate a single segment (and I think we should), we need to
> realign the notes to a common alignment, either 4 or 8 bytes. That's what
> gold seems todo right now, with 4-byte alignment.
I was wrong. We need 2 NOTE segments one fore 8-byte alignment and
one for 4-byte alignment.
>>> Is the link editor *required* to produce 8-byte alignment for notes in
>>> ELFCLASS64 objects?
>>
>>
>> It is decided by the alignment of NOTE section, not by linker.
>>
>>> Currently, we do not have agreement between binutils (particularly gold)
>>> and
>>> the glibc dynamic loader when it comes to alignment of PT_NOTE segments.
>>> glibc will disregard property notes in ELFCLASS64 objects which have
>>> 4-byte
>>> alignment, but gold produces such notes. This needs to be fixed.
>>
>>
>> I don't believe this is true. See above.
>
>
> Which part? I see the 4-byte segment alignment with gold from
> binutils-2.31.1-11.fc29.x86_64.
>
glibc only discards 4-byte aligned NT_GNU_PROPERTY_TYPE_0 note
since NT_GNU_PROPERTY_TYPE_0 note follows gABI. If gold
generates 4 byte alignment, it is a gold bug.
>> After this commit:
>>
>> commit 8d81ce0c6d6ca923571e8b2bac132929f9a02973
>> Author: H.J. Lu <hjl.tools@gmail.com>
>> Date: Tue Nov 28 09:56:47 2017 -0800
>>
>> Properly compute offsets of note descriptor and next note [BZ #22370]
>
> …
>>
>> glibc can handle both 4 byte and 8 byte NOTE alignments.
>
>
> There's still this code in glibc, in sysdeps/x86/dl-prop.h:
>
> /* The NT_GNU_PROPERTY_TYPE_0 note must be aliged to 4 bytes in
> 32-bit objects and to 8 bytes in 64-bit objects. Skip notes
> with incorrect alignment. */
> if (align != (__ELF_NATIVE_CLASS / 8))
> return;
>
This code is correct. NT_GNU_PROPERTY_TYPE_0 follows gABI.
--
H.J.
next prev parent reply other threads:[~2018-08-16 13:39 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAMe9rOrrayKnc_cPm4SmnDnUGLbBUmOYMBTMOM8KLAHVmb=rUQ@mail.gmail.com>
2018-08-16 13:00 ` PT_NOTE alignment, NT_GNU_PROPERTY_TYPE_0, glibc and gold (was: Re: [PATCH] Document GNU_PROPERTY_X86_ISA_1_[USED|NEEDED]) Florian Weimer
2018-08-16 13:19 ` H.J. Lu
2018-08-16 13:29 ` H.J. Lu
2018-08-16 13:31 ` PT_NOTE alignment, NT_GNU_PROPERTY_TYPE_0, glibc and gold Florian Weimer
2018-08-16 13:39 ` H.J. Lu [this message]
2018-08-16 14:01 ` Florian Weimer
2018-08-16 14:43 ` H.J. Lu
2018-08-16 14:21 ` Florian Weimer
2018-08-16 17:46 ` H.J. Lu
2018-08-16 19:16 ` Mark Wielaard
2018-08-16 19:36 ` H.J. Lu
2018-08-17 6:04 ` Mark Wielaard
2018-08-17 6:20 ` Florian Weimer
2018-08-17 6:41 ` Mark Wielaard
2018-08-17 15:10 ` H.J. Lu
2018-08-17 21:05 ` Mark Wielaard
2018-08-21 23:02 ` Cary Coutant
2018-08-22 9:39 ` Florian Weimer
2018-08-22 10:08 ` Mark Wielaard
2018-08-22 23:36 ` Cary Coutant
2018-08-24 18:39 ` Florian Weimer
2018-08-23 14:41 ` Michael Matz
2018-08-23 14:43 ` Florian Weimer
2018-08-17 15:13 ` H.J. Lu
2018-09-19 19:22 ` Florian Weimer
2018-09-21 12:55 ` Michael Matz
2018-09-21 13:04 ` Florian Weimer
2018-09-26 17:39 ` Cary Coutant
2018-09-26 18:36 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMe9rOo2Qw7UV8ApqtN79=L47wtWGnvzakfFveQmoUyjK=jpew@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=binutils@sourceware.org \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=x86-64-abi@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).