From 9917b5596a372317c9708c7166cff9dd69b62d5e Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 14 Apr 2021 05:30:59 -0700 Subject: [PATCH] elf: Set p_memsz to p_filesz for loadable PT_NOTE segment Since p_memsz of the loadable PT_NOTE segment should be the same as p_filesz, set p_memsz on the loadable PT_NOTE segment when updating p_filesz. bfd/ PR binutils/27708 * elf.c (assign_file_positions_for_non_load_sections): Set p_memsz to p_filesz for the loadable PT_NOTE segment. binutils/ PR binutils/27708 * testsuite/binutils-all/x86-64/pr27708.dump: New file. * testsuite/binutils-all/x86-64/pr27708.exe.bz2: Likewise. * testsuite/binutils-all/x86-64/x86-64.exp: Run binutils/27708 test. --- bfd/ChangeLog | 6 +++ bfd/elf.c | 5 +++ binutils/ChangeLog | 8 ++++ .../binutils-all/x86-64/pr27708.dump | 33 +++++++++++++++ .../binutils-all/x86-64/pr27708.exe.bz2 | Bin 0 -> 5815 bytes .../testsuite/binutils-all/x86-64/x86-64.exp | 38 ++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 binutils/testsuite/binutils-all/x86-64/pr27708.dump create mode 100644 binutils/testsuite/binutils-all/x86-64/pr27708.exe.bz2 diff --git a/bfd/ChangeLog b/bfd/ChangeLog index d03929ae619..6c89655664f 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2021-04-14 H.J. Lu + + PR binutils/27708 + * elf.c (assign_file_positions_for_non_load_sections): Set + p_memsz to p_filesz for the loadable PT_NOTE segment. + 2021-04-14 Frederic Cambus * elf.c (elfcore_grok_netbsd_note): Remove unneeded #ifdef diff --git a/bfd/elf.c b/bfd/elf.c index ef2193b07e9..11ae2f3a81b 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -6300,6 +6300,11 @@ assign_file_positions_for_non_load_sections (bfd *abfd, { p->p_filesz = (sect->filepos - m->sections[0]->filepos + hdr->sh_size); + /* NB: p_memsz of the loadable PT_NOTE segment + should be the same as p_filesz. */ + if (p->p_type == PT_NOTE + && (hdr->sh_flags & SHF_ALLOC) != 0) + p->p_memsz = p->p_filesz; break; } } diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 8929c0700fa..b109e3e5c2a 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,11 @@ +2021-04-14 H.J. Lu + + PR binutils/27708 + * testsuite/binutils-all/x86-64/pr27708.dump: New file. + * testsuite/binutils-all/x86-64/pr27708.exe.bz2: Likewise. + * testsuite/binutils-all/x86-64/x86-64.exp: Run binutils/27708 + test. + 2021-04-14 Mark Harmstone PR 27686 diff --git a/binutils/testsuite/binutils-all/x86-64/pr27708.dump b/binutils/testsuite/binutils-all/x86-64/pr27708.dump new file mode 100644 index 00000000000..e9123df9c42 --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/pr27708.dump @@ -0,0 +1,33 @@ + +Elf file type is DYN (Shared object file) +Entry point 0x5f0 +There are 11 program headers, starting at offset 64 + +Program Headers: + Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align + PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x000268 0x000268 R 0x8 + INTERP 0x0002a8 0x00000000000002a8 0x00000000000002a8 0x00001c 0x00001c R 0x1 + [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] + LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000938 0x000938 R E 0x1000 + LOAD 0x000da0 0x0000000000001da0 0x0000000000001da0 0x000278 0x000279 RW 0x1000 + DYNAMIC 0x000db0 0x0000000000001db0 0x0000000000001db0 0x000210 0x000210 RW 0x8 + NOTE 0x0002e8 0x00000000000002e8 0x00000000000002e8 0x000030 0x000030 R 0x8 + NOTE 0x0002c4 0x00000000000002c4 0x00000000000002c4 0x000078 0x000078 R 0x4 + GNU_EH_FRAME 0x0008ec 0x00000000000008ec 0x00000000000008ec 0x00004c 0x00004c R 0x4 + GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 + TLS 0x000da0 0x0000000000001da0 0x0000000000001da0 0x000000 0x000009 R 0x8 + GNU_RELRO 0x000da0 0x0000000000001da0 0x0000000000001da0 0x000260 0x000260 RW 0x8 + + Section to Segment mapping: + Segment Sections... + 00 + 01 .interp + 02 .interp .note.ABI-tag .note.gnu.property .note.gnu.build-id .dynsym .dynstr .gnu.hash .hash .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame .eh_frame_hdr + 03 .fini_array .init_array .dynamic .got .got.plt .data .bss + 04 .dynamic + 05 .note.gnu.property + 06 .note.ABI-tag .note.gnu.property .note.gnu.build-id + 07 .eh_frame_hdr + 08 + 09 .tbss + 10 .fini_array .init_array .dynamic .got diff --git a/binutils/testsuite/binutils-all/x86-64/pr27708.exe.bz2 b/binutils/testsuite/binutils-all/x86-64/pr27708.exe.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..94063c6c2852dcb6e782807d13422d2345b72137 GIT binary patch literal 5815 zcmV;o7D(wrT4*^jL0KkKSt3l@>i`x@fB*mg|NsC0|NsC0|NsC0|NsC0|K9)l*8ly- z|NsC0|Nr0>FS)qO0N(X9!ca9mXTI&(-QR7Q=`Lv6W9%DdWDIF*vp@g}05mnSL3g2% z5RD0mrX<8Y0-l>HpOZ>{LrLk0r8lXmvk6aX6ZI#l`kO(OJsyoD(VnNNqt!oBZ&dWe z$`47Vk5T16RP{Yg8InCFo~NngjWTHbs1Hv{Jdac~(NGu1(m|=BWW*W}ObIhY z^rz~ciRee^1bIWyn^0%~$)Gd?BSS#Y007Wwrhouw00w{n0000027nC)nh`XOCMKZT zlOgG$F)^0078fnqYv?FpUP9XaE2W27oeRXc(FUMvM`FIshI} z0001J0000000000000000000D0000000000002mlGzbZhX`mGHG6JWHev{OPspBen zsigf)p-lkM4Fhx=%igPpI-*XV zKw29PrRHtdoL<)J8qG1*{4!E);=o*4lkg98Ob}-VXX-JA& ztic z%cm2uv8Ro#%}u4MxIF$c%P37P?C0QBvqz#;(5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h6mB(mG=?)MQoMjrlCH6?B7}`+l%HTLnA+I5ieg)4 z*epeq)_@?yF+?`Oj83z06N9;HDJ8i68Iu{hjv^{g2pRI0!k(+#10Ai6RA#yuG!~mc z!z_tZwj`3XF|f5wwAJP@S4awpK+AefEx}7yg&}lQmJY?Sm5$Vu+nP;RAkEt5H^oQm|?Q(v0gRQlzS%OA?gCkbQa+ zI~FD^L!ojQYfOFlif%CRu`s}pllVHbY9_a2*Gp@rA#b6NK`DsYLS#=QAdYn#``j)l zDYPPix8+_!$4vg32I$Voh!GJH9tT~aI{hc$YNli>iTNZ4j6oA%1dEjE-$Eiv5x$({ zS8pLNKz8QiqUItTIaP$p#P=1D(;y8NJ_Jih&TNE)9Enq3oAK7{s^yp4O{=9$Dpn^- z(@Om#D(ZHojI3CUj@0WOkboA|pvg{ka-~a7(4Gu!tt-y-ca7cn{~K+a?*D#AWixSU{Hb%>ywAgN2pMJ60BjLZ2zzj!PBiNZTWmC@ zfh=?p0|VFX $tempfile\""] != 0} { } } } + +set t $srcdir/$subdir/pr27708.exe.bz2 +# We need to strip the ".bz2", but can leave the dirname. +set test $subdir/[file tail $t] +set testname [file rootname $test] +verbose $testname +if {[catch "system \"bzip2 -dc $t > $tempfile\""] != 0} { + untested "bzip2 -dc ($testname)" +} else { + send_log "$STRIP $tempfile -o ${tempfile}.strip\n" + verbose "$STRIP $tempfile -o ${tempfile}.strip" 1 + set got [catch "system \"$STRIP $tempfile -o ${tempfile}.strip\""] + if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then { + fail $testname + } else { + send_log "$READELF -lW ${tempfile}.strip > tmpdir/pr27708.out 2> /dev/null\n" + verbose "$READELF -lW ${tempfile}.strip > tmpdir/pr27708.out 2> /dev/null" 1 + set got [catch "system \"$READELF -lW ${tempfile}.strip > tmpdir/pr27708.out 2> /dev/null\""] + + if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then { + fail $testname + } else { + send_log "cmp tmpdir/pr27708.out $srcdir/$subdir/pr27708.dump\n" + verbose "cmp tmpdir/pr27708.out $srcdir/$subdir/pr26808.dump" 1 + set status [remote_exec build cmp "tmpdir/pr27708.out $srcdir/$subdir/pr27708.dump"] + set exec_output [lindex $status 1] + set exec_output [prune_warnings $exec_output] + + if [string match "" $exec_output] then { + pass "strip ($testname)" + } else { + send_log "$exec_output\n" + verbose "$exec_output" 1 + fail "strip ($testname)" + } + } + } +} -- 2.30.2