978e96
commit c259196b5005812aa3294dbf4eeca29b266a4522
978e96
Author: Florian Weimer <fweimer@redhat.com>
978e96
Date:   Fri Mar 1 18:53:03 2019 +0100
978e96
978e96
    elf/tst-big-note: Improve accuracy of test [BZ #20419]
978e96
    
978e96
    It is possible that the link editor injects an allocated ABI tag note
978e96
    before the artificial, allocated large note in the test.  Note parsing
978e96
    in open_verify stops when the first ABI tag note is encountered, so if
978e96
    the ABI tag note comes first, the problematic code is not actually
978e96
    exercised.
978e96
    
978e96
    Also tweak the artificial note so that it is a syntactically valid
978e96
    4-byte aligned note, in case the link editor tries to parse notes and
978e96
    process them.
978e96
    
978e96
    Improves the testing part of commit 0065aaaaae51cd60210ec3a7e13.
978e96
    
978e96
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
978e96
978e96
(Minor adjustment for Makefile conflict.)
978e96
978e96
diff --git a/elf/Makefile b/elf/Makefile
978e96
index b46b3a0e3542a06f..2b2662d5cf96c437 100644
978e96
--- a/elf/Makefile
978e96
+++ b/elf/Makefile
978e96
@@ -244,8 +244,8 @@ extra-test-objs += $(addsuffix .os,$(strip $(modules-names)))
978e96
 # We need this variable to be sure the test modules get the right CPPFLAGS.
978e96
 test-extras += $(modules-names)
978e96
 
978e96
-# filtmod1.so has a special rule
978e96
-modules-names-nobuild := filtmod1
978e96
+# filtmod1.so, tst-big-note-lib.so have special rules.
978e96
+modules-names-nobuild := filtmod1 tst-big-note-lib
978e96
 
978e96
 ifneq (no,$(multi-arch))
978e96
 tests-static += ifuncmain1static ifuncmain1picstatic \
978e96
@@ -1239,3 +1239,8 @@ $(objpfx)tst-audit12mod1.so: $(objpfx)tst-audit12mod2.so
978e96
 LDFLAGS-tst-audit12mod2.so = -Wl,--version-script=tst-audit12mod2.map
978e96
 
978e96
 $(objpfx)tst-big-note: $(objpfx)tst-big-note-lib.so
978e96
+# Avoid creating an ABI tag note, which may come before the
978e96
+# artificial, large note in tst-big-note-lib.o and invalidate the
978e96
+# test.
978e96
+$(objpfx)tst-big-note-lib.so: $(objpfx)tst-big-note-lib.o
978e96
+	$(LINK.o) -shared -o $@ $(LDFLAGS.so) $<
978e96
diff --git a/elf/tst-big-note-lib.S b/elf/tst-big-note-lib.S
978e96
index 6b514a03cc686141..c97590ccb05e9b2e 100644
978e96
--- a/elf/tst-big-note-lib.S
978e96
+++ b/elf/tst-big-note-lib.S
978e96
@@ -20,7 +20,13 @@
978e96
    On a typical Linux system with 8MiB "ulimit -s", that was enough
978e96
    to trigger stack overflow in open_verify.  */
978e96
 
978e96
+#define NOTE_SIZE 8*1024*1024
978e96
+
978e96
 .pushsection .note.big,"a"
978e96
-.balign 4
978e96
-.fill 8*1024*1024, 1, 0
978e96
+	.balign 4
978e96
+	.long 5 		/* n_namesz.  Length of "GLIBC".  */
978e96
+	.long NOTE_SIZE		/* n_descsz.  */
978e96
+	.long 0			/* n_type.  */
978e96
+	.ascii "GLIBC\0\0\0"	/* Name and alignment to four bytes.  */
978e96
+	.fill NOTE_SIZE, 1, 0
978e96
 .popsection