unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Cary Coutant <ccoutant@gmail.com>, Mark Wielaard <mark@klomp.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>,
	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: Wed, 22 Aug 2018 11:39:02 +0200	[thread overview]
Message-ID: <101e7bf8-0270-5b53-61f0-6b852bb8666e@redhat.com> (raw)
In-Reply-To: <CAJimCsHSNZxG37PMj6_V4Tv2b0sNjntokn61GJSBhvdMDUPeRA@mail.gmail.com>

On 08/22/2018 01:02 AM, Cary Coutant wrote:
>>>>> But like you, I don't yet see the value of the 8-byte alignment.  We could
>>>>> decide that the current gold behavior is valid, fix glibc, and move on.
>>>>
>>>> Right. gold seems to produce normal GNU abi ELF Notes, which should
>>>> be accepted as is.
>>>
>>> NT_GNU_PROPERTY_TYPE_0 should stay to follow gABI.
>>
>> That doesn't make any sense. gABI doesn't have a concept of 32bit word
>> ELF notes that are 8-byte aligned. That is just a bug in ld when it
>> generates the note. It also doesn't make sense to generate GNU ELF notes
>> with slightly different padding added depending on type in the same ELF
>> file. That just creates confusion, causes you to define different
>> alignments of notes resulting in extra PT_LOAD segments and results in
>> bugs like we are discussing now where ELF note parsers fail to parse
>> some (valid) notes. Lets just agree that the gold linker is correct and
>> produces consistent GNU abi ELF notes. And lets just fix ld to do the same.
> 
> I thought the outcome of the old discussion on the gABI/psABI mailing
> lists was that there was no value in breaking compatibility by
> introducing an 8-byte aligned note section.

The code for generating them is still in BFD ld and has been there for 
several binutils releases.  <cet.h> in GCC 8 generates 8-byte-aligned 
notes, too.

glibc 2.28 assumes that no 4-byte-aligned PT_NOTE segments contain GNU 
property notes and will search for such notes in 8-byte aligned segments 
only.  The glibc changes were formally reviewed and checked for 
interoperability with BFD ld.  I think we have (had) community consensus 
for them.

We have built and hundreds (if not thousands) of binaries with 
8-byte-aligned notes and shipped them (in Fedora), assuming that there 
was upstream consensus about this x86-64 psABI extension.

> As it is, the psABI definition of the gnu properties note is a
> definitional disaster: like a proper note, it's got three 4-byte words
> (namesz, descsz, and type), followed by the name field (which happens
> to be 4 bytes long in this case), then a desc field. For this note,
> the desc field contains a properties array, where each property has
> two 4-byte values (pr_type and pr_datasz) and a data field padded to a
> multiple of 8 bytes. But it describes the properties array as an array
> of 8-byte words, even though it's really composed of the two 4-byte
> words and an arbitrary-length buffer (which according to the spec, is
> always 8 bytes). Why an 8-byte alignment, though? It doesn't provide
> any conceivable benefit.
> 
> I think gold is doing the right thing by placing the output in a
> 4-byte aligned note section, and combining it with other note sections
> in a 4-byte aligned PT_NOTE segment.

Based on what I've seen, this is a technically feasible option.

But we have existing binaries with 8-byte-aligned notes, and those won't 
go away soon.  There is a cost to having 8-byte-aligned notes (gold 
fixes, elfutils fixes, plenty of other fixes), and to having 
4-byte-aligned notes only (CET-compatible binaries will not be treated 
as such because their 8-byte-aligned PT_NOTE section is invalid).

I don't know if there is anything else that is coming down the pipe 
which would benefit from 8-byte-aligned notes.  Nick has been working on 
.gnu.build.attributes non-allocated note sections.  They are nominally 
4-byte-aligned, but contain 64-bit relocations, but so far, the linker 
has not complained, so maybe this is okay.

> As long as HJ is planning on breaking compatibility with his new
> definition of the x86 properties [1], why not just throw it away and
> do it right? Let's stop using NOTE sections for something they weren't
> designed for, and instead use a special section type and segment type
> (in keeping with existing models like Sun, HP, MIPS, and Arm).

This, too, would invalidate existing binaries.

> Why should the loader have to go parsing everything in a generic PT_NOTE
> segment anyway?

With 8-byte alignment, in practice, it is currently quite fast to 
discover the new notes because the other notes have 4-byte alignment, so 
the PT_NOTE segment with the property notes should be pleasantly short.

Again, maybe we shouldn't have built all those binaries, but we thought 
the binutils community at least was in favor of the 8-byte-aligned 
notes,  This puts me in a difficult decision: The technical facts seem 
to favor 4-byte-aligned notes (but again, there might be further 
features that actually need 8-byte alignment).  But the existing 
binaries with 8-byte-aligned notes provide a strong business 
justification for Red Hat to keep support for the 8-byte-aligned notes.

Thanks,
Florian

  reply	other threads:[~2018-08-22  9: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
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 [this message]
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=101e7bf8-0270-5b53-61f0-6b852bb8666e@redhat.com \
    --to=fweimer@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=ccoutant@gmail.com \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=mark@klomp.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).