bf6d7087de0a7351fd1dfd5f41522a7f4f576180 is the first bad commit commit bf6d7087de0a7351fd1dfd5f41522a7f4f576180 (HEAD) Author: Nick Clifton <nickc@redhat.com> Date: Thu Sep 19 16:45:30 2024 +0100 ld: Move the .note.build-id section to near the start of the memory map. This helps GDB to locate the debug information associated with a core dump. Core dumps include the first page of an executable's image, and if this page include the .note.build-id section then GDB can find it and then track down a debug info file for that build-id. caused: FAIL: Build pr22393-2a.so FAIL: Build pr22393-2a-now.so FAIL: Build pr22393-2 FAIL: Build pr22393-2 (PIE) FAIL: Build pr22393-2 (static) FAIL: Build pr22393-3a.so FAIL: Build pr22393-3a-now.so FAIL: Build pr22393-3 FAIL: Build pr22393-3 (PIE) FAIL: Build pr22393-3 (static) on Linux/x86-64 when binutils is configured with --enable-rosegment.
cc -B/export/build/gnu/tools-build/binutils/build-x86_64-linux/ld/tmpdir/ld/ -I/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf -g -O2 -fno-sanitize=all -c -fno-lto -fPIC -c /export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf/pr22393-2a.c -o tmpdir/pr22393-2a.o Executing on host: sh -c {cc -B/export/build/gnu/tools-build/binutils/build-x86_64-linux/ld/tmpdir/ld/ -I/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf -g -O2 -fno-sanitize=all -c -fno-lto -fPIC -c /export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf/pr22393-2a.c -o tmpdir/pr22393-2a.o 2>&1} /dev/null ld.tmp (timeout = 300) spawn [open ...]^M cc -B/export/build/gnu/tools-build/binutils/build-x86_64-linux/ld/tmpdir/ld/ -L=/usr/local/x86_64-pc-linux-gnu/lib64 -L=/usr/local/lib64 -L=/lib64 -L=/usr/lib64 -L=/usr/local/x86_64-pc-linux-gnu/lib -L=/usr/local/lib -L=/lib -L=/usr/lib -o tmpdir/pr22393-2a.so -L/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf -shared -Wl,-z,separate-code tmpdir/pr22393-2a.o Executing on host: sh -c {cc -B/export/build/gnu/tools-build/binutils/build-x86_64-linux/ld/tmpdir/ld/ -L=/usr/local/x86_64-pc-linux-gnu/lib64 -L=/usr/local/lib64 -L=/lib64 -L=/usr/lib64 -L=/usr/local/x86_64-pc-linux-gnu/lib -L=/usr/local/lib -L=/lib -L=/usr/lib -o tmpdir/pr22393-2a.so -L/export/gnu/import/git/sources/binutils-gdb/ld/testsuite/ld-elf -shared -Wl,-z,separate-code tmpdir/pr22393-2a.o 2>&1} /dev/null ld.tmp (timeout = 300) spawn [open ...]^M /export/build/gnu/tools-build/binutils/build-x86_64-linux/ld/../binutils/readelf -lW tmpdir/pr22393-2a.so > dump.out fail if no difference output is Elf file type is DYN (Shared object file) Entry point 0x0 There are 10 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0003e9 0x0003e9 R E 0x1000 LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x0002f0 0x0002f0 R 0x1000 LOAD 0x001dc0 0x0000000000002dc0 0x0000000000002dc0 0x000248 0x000250 RW 0x1000 DYNAMIC 0x001dd8 0x0000000000002dd8 0x0000000000002dd8 0x0001f0 0x0001f0 RW 0x8 NOTE 0x000270 0x0000000000000270 0x0000000000000270 0x000030 0x000030 R 0x8 NOTE 0x0002a0 0x00000000000002a0 0x00000000000002a0 0x000024 0x000024 R 0x4 GNU_PROPERTY 0x000270 0x0000000000000270 0x0000000000000270 0x000030 0x000030 R 0x8 GNU_EH_FRAME 0x001258 0x0000000000001258 0x0000000000001258 0x000024 0x000024 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 GNU_RELRO 0x001dc0 0x0000000000002dc0 0x0000000000002dc0 0x000240 0x000240 R 0x1 Section to Segment mapping: Segment Sections... 00 .note.gnu.property .note.gnu.build-id .init .plt .plt.got .text .fini 01 .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .rodata .eh_frame_hdr .eh_frame 02 .init_array .fini_array .data.rel.ro .dynamic .got .got.plt .bss 03 .dynamic 04 .note.gnu.property 05 .note.gnu.build-id 06 .note.gnu.property 07 .eh_frame_hdr 08 FAIL: Build pr22393-2a.so Since -z separate-code is passed to linker, there shouldn't be mixed rodata and text section in a page.
Hi H.J. Personally I think that this is a case where the test itself should be changed. Or at least made conditional upon --rosegment not being in effect. Or changed so that it does not complain about .note.build-id and .note.gnu.property sections being present in the read-execute segment. > Since -z separate-code is passed to linker, there shouldn't be mixed rodata > and text section in a page. True - but - the rodata that is there are notes rather than program data, and whilst it is still theoretically possible that these notes will mimic valid instructions, possibly even exploitable instruction sequences, the chances of this happening are very low. The reason for the commit is that GDB has been relying upon the fact that the linker would place the .note.build-id section in the first page of the executable image. This matters because when the kernel generates a core dump, it includes the first page of the executable in the dump. If the .note.build-id section is present in this page then GDB can locate it and use the information to track down the debug info file associated with the executable whose failure triggered the core dump. Of course it would be nice if there was another way for GDB to discover this information, but I do not think that it is a practical solution. It would probably involve kernel changes, gdb changes, and maybe even linker changes. All of which would have to be coordinated and all of which would probably not be backwards compatible. What do you think - are you willing to accept a change to the test itself ? Cheers Nick
(In reply to Nick Clifton from comment #2) ... > What do you think - are you willing to accept a change to the test itself ? > I will check in this: https://sourceware.org/pipermail/binutils/2024-September/136855.html
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ae6a4c3f1d5caeba962d2c1748a8d2b3bebb1007 commit ae6a4c3f1d5caeba962d2c1748a8d2b3bebb1007 Author: H.J. Lu <hjl.tools@gmail.com> Date: Sat Sep 21 03:44:22 2024 +0800 ld: Use --no-rosegment to ld for PR ld/22393 tests The commit bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory map moves the .note.build-id section before text sections. When --rosegment and -z separate-code are used together, the .note.gnu.property section is placed between the .note.build-id section and text sections in the same PT_LOAD segment by orphan placement. Pass --no-rosegment to ld for PR ld/22393 tests to avoid linker test failures. PR ld/32190 * testsuite/ld-elf/pr22393-2a.rd: Pass --no-rosegment to ld. * testsuite/ld-elf/pr22393-2b.rd: Likewise. * testsuite/ld-elf/shared.exp: Pass --no-rosegment to ld when building pr22393-2 tests. * testsuite/ld-x86-64/pr22393-3a.rd: Pass --no-rosegment to ld. * testsuite/ld-x86-64/pr22393-3b.rd: Likewise. * testsuite/ld-x86-64/x86-64.exp: Pass --no-rosegment to ld when building pr22393-3 tests. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Thanks H.J.