[PATCH 1/5] gold: Properly align the NT_GNU_PROPERTY_TYPE_0 note
H.J. Lu
hjl.tools@gmail.com
Sun Oct 11 00:36:08 GMT 2020
On Sat, Oct 10, 2020 at 5:20 PM Fangrui Song <i@maskray.me> wrote:
>
>
> On 2020-10-10, H.J. Lu via Binutils wrote:
> >The NT_GNU_PROPERTY_TYPE_0 note should be aligned to 8 bytes for 64-bit
> >ELF as specified by gABI. A note section can be only placed in a PT_NOTE
> >segment with the same alignment.
> >
> > PR gold/22914
> > PR gold/23535
> > * layout.cc (Layout::attach_allocated_section_to_segment): Place
> > a note section in a PT_NOTE segment with the same alignment. Set
> > the alignment of the PT_NOTE segment from the alignment of the
> > note section.
> > (Layout::create_note): Align the NT_GNU_PROPERTY_TYPE_0 note to 8
> > bytes for 64-bit ELF.
> > (Layout::segment_precedes): Place segments with larger alignments
> > first.
> > * output.cc (Output_segment::Output_segment): Initialize align_.
> > * output.h (Output_segment): Add align, set_align and align_.
> > * testsuite/Makefile.am (gnu_property_test.stdout): Pass -lhSWn
> > to $(TEST_READELF).
> > (gnu_property_test): Pass --build-id to ld.
> > * testsuite/Makefile.in: Regenerated.
> > * testsuite/gnu_property_test.sh (check_alignment): New.
> > Use check_alignment to check the NT_GNU_PROPERTY_TYPE_0 note
> > alignment. Verify that there are 2 PT_NOTE segments.
> >---
> > gold/layout.cc | 15 ++++++++++++++-
> > gold/output.cc | 1 +
> > gold/output.h | 12 ++++++++++++
> > gold/testsuite/Makefile.am | 4 ++--
> > gold/testsuite/Makefile.in | 4 ++--
> > gold/testsuite/gnu_property_test.sh | 20 ++++++++++++++++++++
> > 6 files changed, 51 insertions(+), 5 deletions(-)
> >
> >diff --git a/gold/layout.cc b/gold/layout.cc
> >index 13e533aaf21..6948ff7214c 100644
> >--- a/gold/layout.cc
> >+++ b/gold/layout.cc
> >@@ -2062,12 +2062,15 @@ Layout::attach_allocated_section_to_segment(const Target* target,
> > // segment.
> > if (os->type() == elfcpp::SHT_NOTE)
> > {
> >+ uint64_t os_align = os->addralign();
> >+
> > // See if we already have an equivalent PT_NOTE segment.
> > for (p = this->segment_list_.begin();
> > p != segment_list_.end();
> > ++p)
> > {
> > if ((*p)->type() == elfcpp::PT_NOTE
> >+ && (*p)->align() == os_align
> > && (((*p)->flags() & elfcpp::PF_W)
> > == (seg_flags & elfcpp::PF_W)))
> > {
> >@@ -2081,6 +2084,7 @@ Layout::attach_allocated_section_to_segment(const Target* target,
> > Output_segment* oseg = this->make_output_segment(elfcpp::PT_NOTE,
> > seg_flags);
> > oseg->add_output_section_to_nonload(os, seg_flags);
> >+ oseg->set_align(os_align);
> > }
> > }
>
> LG. I used the same approach for LLD: there will be two PT_NOTE if there are
> SHT_NOTE of mixed alignments.
>
> >@@ -3184,6 +3188,10 @@ Layout::create_note(const char* name, int note_type,
> > #else
> > const int size = 32;
> > #endif
> >+ // The NT_GNU_PROPERTY_TYPE_0 note conforms to gABI.
> >+ const int addralign = ((note_type == elfcpp::NT_GNU_PROPERTY_TYPE_0
> >+ ? parameters->target().get_size()
> >+ : size) / 8);
>
> This comment may be incorrect. gABI uses 64-bit integers on ELFCLASS64.
> A NT_GNU_PROPERTY_TYPE_0 has an alignment of 8 but its elements still do
> not conform to gABI. This can be Linux ABI or GNU ABI.
>
Changed to
// The NT_GNU_PROPERTY_TYPE_0 note is aligned to the pointer size.
--
H.J.
More information about the Binutils
mailing list