This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] gold: Properly align the NT_GNU_PROPERTY_TYPE_0 note
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Cc: Cary Coutant <ccoutant at gmail dot com>
- Date: Thu, 16 Aug 2018 10:46:05 -0700
- Subject: [PATCH] gold: Properly align the NT_GNU_PROPERTY_TYPE_0 note
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
The NT_GNU_PROPERTY_TYPE_0 note conforms to gABI and should be aligned
to 8 bytes for 64-bit ELF.
OK for master branch?
H.J.
---
PR gold/22914
PR gold/23535
* layout.cc (Layout::create_note): Align the NT_GNU_PROPERTY_TYPE_0
note to 8 bytes for 64-bit ELF.
* testsuite/Makefile.am (gnu_property_test.stdout): Pass -hSWn
to $(TEST_READELF).
* 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.
---
gold/layout.cc | 7 ++++++-
gold/testsuite/Makefile.am | 2 +-
gold/testsuite/Makefile.in | 2 +-
gold/testsuite/gnu_property_test.sh | 18 ++++++++++++++++++
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/gold/layout.cc b/gold/layout.cc
index 66162a253d..00eab37d5b 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -3182,6 +3182,11 @@ 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 align_size
+ = ((note_type == elfcpp::NT_GNU_PROPERTY_TYPE_0)
+ ? parameters->target().get_size()
+ : size);
// The contents of the .note section.
size_t namesz = strlen(name) + 1;
@@ -3245,7 +3250,7 @@ Layout::create_note(const char* name, int note_type,
return NULL;
Output_section_data* posd = new Output_data_const_buffer(buffer, notehdrsz,
- size / 8,
+ align_size / 8,
"** note header");
os->add_output_section_data(posd);
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index ede706442a..5f86da30eb 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -3268,7 +3268,7 @@ if DEFAULT_TARGET_X86_64
check_SCRIPTS += gnu_property_test.sh
check_DATA += gnu_property_test.stdout
gnu_property_test.stdout: gnu_property_test
- $(TEST_READELF) -n $< >$@
+ $(TEST_READELF) -hSWn $< >$@
gnu_property_test: gcctestdir/ld gnu_property_a.o gnu_property_b.o gnu_property_c.o
gcctestdir/ld -o $@ gnu_property_a.o gnu_property_b.o gnu_property_c.o
gnu_property_main.o: gnu_property_main.c
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 52e8f5421b..fa918eb23c 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -9479,7 +9479,7 @@ uninstall-am:
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_x86_64_bnd_2.o: exception_test_2.cc gcctestdir/as
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -Bgcctestdir/ -Wa,-madd-bnd-prefix -o $@ $<
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@gnu_property_test.stdout: gnu_property_test
-@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -n $< >$@
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -hSWn $< >$@
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@gnu_property_test: gcctestdir/ld gnu_property_a.o gnu_property_b.o gnu_property_c.o
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -o $@ gnu_property_a.o gnu_property_b.o gnu_property_c.o
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@gnu_property_main.o: gnu_property_main.c
diff --git a/gold/testsuite/gnu_property_test.sh b/gold/testsuite/gnu_property_test.sh
index 79286d4721..ed3653c231 100755
--- a/gold/testsuite/gnu_property_test.sh
+++ b/gold/testsuite/gnu_property_test.sh
@@ -53,6 +53,24 @@ check_count()
fi
}
+check_alignment ()
+{
+ if egrep -q "Class:[ \t]+ELF64" "$1"
+ then
+ align=8
+ else
+ align=4
+ fi
+ if ! egrep -q ".note.gnu.property[ \t]+NOTE.*$align$" "$1"
+ then
+ echo "Wrong .note.gnu.property alignment in $1:"
+ egrep ".note.gnu.property[ \t]+NOTE.*$align" "$1"
+ exit 1
+ fi
+}
+
+check_alignment gnu_property_test.stdout
+
check_count gnu_property_test.stdout "GNU\s*0x[0-9a-f]*\s*NT_GNU_PROPERTY_TYPE_0" 1
check gnu_property_test.stdout "stack size: 0x111100"
--
2.17.1