[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #22 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by H.J. Lu : https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=80f3ac5d61a5d01d7cf951de0e24ecdc71c545cb commit 80f3ac5d61a5d01d7cf951de0e24ecdc71c545cb Author: H.J. Lu Date: Mon Oct 8 05:14:02 2018 -0700 x86: Don't add GNU_PROPERTY_X86_FEATURE_2_NEEDED for -z separate-code With commit 64029e93683a266c38d19789e780f3748bd6a188 Author: Alan Modra Date: Fri Oct 5 11:40:54 2018 +0930 Separate header PT_LOAD for -z separate-code there is no need to add a GNU_PROPERTY_X86_ISA_1_USED note to force program header in in non-code PT_LOAD segment when -z separate-code is used. bfd/ PR ld/23428 * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Don't add GNU_PROPERTY_X86_FEATURE_2_NEEDED to force program header in non-code PT_LOAD segment. ld/ PR ld/23428 * testsuite/ld-i386/property-x86-4a.d: Updated. * testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-4a.d: Likewise. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 H.J. Lu changed: What|Removed |Added CC||felix-glibc at fefe dot de --- Comment #21 from H.J. Lu --- *** Bug 23561 has been marked as a duplicate of this bug. *** -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #20 from cvs-commit at gcc dot gnu.org --- The binutils-2_31-branch branch has been updated by H.J. Lu : https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=28a27bdbb9500797e6767f80c8128b09112aeed5 commit 28a27bdbb9500797e6767f80c8128b09112aeed5 Author: H.J. Lu Date: Sat Aug 11 06:41:33 2018 -0700 x86: Properly add X86_ISA_1_NEEDED property Existing properties may be removed during property merging. We avoid adding X86_ISA_1_NEEDED property only if existing properties won't be removed. bfd/ PR ld/23428 * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Don't add X86_ISA_1_NEEDED property only if existing properties won't be removed. ld/ PR ld/23428 * testsuite/ld-elf/dummy.s: New file. * testsuite/ld-elf/linux-x86.S: Add X86_FEATURE_1_AND property. * testsuite/ld-elf/linux-x86.exp: Add dummy.s to pr23428. (cherry picked from commit ab9e342807d132182892de1be1a92d6e91a5c1da) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #19 from Evangelos Foutras --- (In reply to H.J. Lu from comment #18) > (In reply to Evangelos Foutras from comment #16) > > The test case from comment #14 is still reproducible for me with both > > binutils master (1dc9e2d6) and binutils-2_31-branch (6ee91b1e). No change at > > all in the resulting binary, compared to just the patch from comment #4. > > Please try master branch again. Your latest commit fixes the issue I was experiencing. Thanks! -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #18 from H.J. Lu --- (In reply to Evangelos Foutras from comment #16) > The test case from comment #14 is still reproducible for me with both > binutils master (1dc9e2d6) and binutils-2_31-branch (6ee91b1e). No change at > all in the resulting binary, compared to just the patch from comment #4. Please try master branch again. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #17 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by H.J. Lu : https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ab9e342807d132182892de1be1a92d6e91a5c1da commit ab9e342807d132182892de1be1a92d6e91a5c1da Author: H.J. Lu Date: Sat Aug 11 06:41:33 2018 -0700 x86: Properly add X86_ISA_1_NEEDED property Existing properties may be removed during property merging. We avoid adding X86_ISA_1_NEEDED property only if existing properties won't be removed. bfd/ PR ld/23428 * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Don't add X86_ISA_1_NEEDED property only if existing properties won't be removed. ld/ PR ld/23428 * testsuite/ld-elf/dummy.s: New file. * testsuite/ld-elf/linux-x86.S: Add X86_FEATURE_1_AND property. * testsuite/ld-elf/linux-x86.exp: Add dummy.s to pr23428. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #16 from Evangelos Foutras --- The test case from comment #14 is still reproducible for me with both binutils master (1dc9e2d6) and binutils-2_31-branch (6ee91b1e). No change at all in the resulting binary, compared to just the patch from comment #4. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #12 from H.J. Lu --- (In reply to Evangelos Foutras from comment #11) > > Does the above indicate that the fix to binutils needs to be tweaked? > Please provide a small and host-independent testcase. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #11 from Evangelos Foutras --- Created attachment 11174 --> https://sourceware.org/bugzilla/attachment.cgi?id=11174=edit Test case with Arch's and Debian's GCC-provided crt{begin,end}.o (In reply to nsz from comment #10) > i'd try to verify that the right ld is used (e.g. strace -f -e execve > musl-gcc ...) > then i'd try to reproduce the issue outside of musl-gcc (e.g. manually > invoking > ld with the options seen in the strace and look for the NOTE program header) Thanks for the suggestion. I was able to reduce my test case to something that is reproducible on both Arch and Debian. The attached test case indicates that it's some difference between Debian's and Arch's crt{begin,end}.o (as provided by GCC) that's causing ld to add the NOTE program header and .note.gnu.property section to the produced binary. Comparing them using 'objdump -h', I notice that Arch's crt{begin,end}.o have a .note.gnu.property section and Debian's don't. If I use 'objcopy -R .note.gnu.property' on the Arch ones, then those produce a working executable too! Does the above indicate that the fix to binutils needs to be tweaked? = [pr23428-test]$ make cc-c -o test.o test.c ld -static -o test-arch arch-crts/* arch-musl/* test.o ld -static -o test-debian debian-crts/* arch-musl/* test.o pr23428-test$ grep gnu.property test-* Binary file test-debian matches [pr23428-test]$ ./test-debian [pr23428-test]$ ./test-arch Segmentation fault (core dumped) [pr23428-test]$ objcopy -R .note.gnu.property arch-crts/crtbegin.o [pr23428-test]$ objcopy -R .note.gnu.property arch-crts/crtend.o [pr23428-test]$ make -Bs test-arch [pr23428-test]$ gdb -q -ex run ./test-arch Reading symbols from ./test-arch...(no debugging symbols found)...done. Starting program: /home/../desktop/pr23428-test/test-arch [Inferior 1 (process 17284) exited normally] = -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #10 from nsz at port70 dot net --- * evangelos at foutrelis dot com [2018-08-10 02:14:57 +]: > I also checked on Debian testing and the musl-gcc command produces a working > binary there (even after removing the --build-id workaround from > musl-gcc.specs). For some weird reason though, it still segfaults on Arch with > patched binutils. :| i'd try to verify that the right ld is used (e.g. strace -f -e execve musl-gcc ...) then i'd try to reproduce the issue outside of musl-gcc (e.g. manually invoking ld with the options seen in the strace and look for the NOTE program header) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #9 from Evangelos Foutras --- (In reply to nsz from comment #8) > it works for me, please post the readelf -aW ./a.out somewhere (e.g. musl > list) https://paste.xinu.at/igNNdz/ -- but as mentioned below, it's the same as unpatched binutils. > (you should see a .note.gnu.property section and an appropriate NOTE program > header.) This is really weird and I'm not sure what's going on: The output from 'readelf -aW' is exactly the same with both patched and unpatched binutils 2.31 when using the musl-gcc example. However, it does change when using your original example of linking t.o; with patched binutils I see a .note.gnu.property section and a NOTE program header. I also checked on Debian testing and the musl-gcc command produces a working binary there (even after removing the --build-id workaround from musl-gcc.specs). For some weird reason though, it still segfaults on Arch with patched binutils. :| -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #8 from nsz at port70 dot net --- * evangelos at foutrelis dot com [2018-08-09 07:37:19 +]: > @Szabolcs, Rich: Is the musl-gcc issue fixed for you guys? [1] > > I'm still getting a segfault with current binutils master (6404ab9937): > > $ ld -v > GNU ld (GNU Binutils) 2.31.51.20180809 > > $ musl-gcc -ggdb3 -O0 -static -xc - <<<"int main() { return 0; }" > $ gdb -q --batch -ex run -ex bt ./a.out > > Program received signal SIGSEGV, Segmentation fault. > 0x0040140f in static_init_tls () > #0 0x0040140f in static_init_tls () > #1 0x in ?? () it works for me, please post the readelf -aW ./a.out somewhere (e.g. musl list) (you should see a .note.gnu.property section and an appropriate NOTE program header.) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 Evangelos Foutras changed: What|Removed |Added CC||evangelos at foutrelis dot com --- Comment #7 from Evangelos Foutras --- @Szabolcs, Rich: Is the musl-gcc issue fixed for you guys? [1] I'm still getting a segfault with current binutils master (6404ab9937): $ ld -v GNU ld (GNU Binutils) 2.31.51.20180809 $ musl-gcc -ggdb3 -O0 -static -xc - <<<"int main() { return 0; }" $ gdb -q --batch -ex run -ex bt ./a.out Program received signal SIGSEGV, Segmentation fault. 0x0040140f in static_init_tls () #0 0x0040140f in static_init_tls () #1 0x in ?? () [1] http://www.openwall.com/lists/musl/2018/07/18/5 -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #5 from cvs-commit at gcc dot gnu.org --- The binutils-2_31-branch branch has been updated by H.J. Lu : https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6737a6b34f4823deb7142f27b4074831a37ac1e1 commit 6737a6b34f4823deb7142f27b4074831a37ac1e1 Author: H.J. Lu Date: Fri Jul 20 09:18:47 2018 -0700 x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed When -z separate-code, which is enabled by default for Linux/x86, is used to create executable, ld won't place any data in the code-only PT_LOAD segment. If there are no data sections placed before the code-only PT_LOAD segment, the program headers won't be mapped into any PT_LOAD segment. When the executable tries to access it (based on the program header address passed in AT_PHDR), it will lead to segfault. This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if there may be no data sections before the text section so that the first PT_LOAD segment won't be code-only and will contain the program header. Testcases are adjusted to either pass "-z noseparate-code" to ld or discard the .note.gnu.property section. A Linux/x86 run-time test is added. bfd/ PR ld/23428 * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the separate code program header is needed, make sure that the first read-only PT_LOAD segment has no code by adding a GNU_PROPERTY_X86_ISA_1_USED note. ld/ PR ld/23428 * testsuite/ld-elf/linux-x86.S: New file. * testsuite/ld-elf/linux-x86.exp: Likewise. * testsuite/ld-elf/pr23428.c: Likewise. * testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld for Linux/x86 targets. * testsuite/ld-i386/abs-iamcu.d: Likewise. * testsuite/ld-i386/abs.d: Likewise. * testsuite/ld-i386/pr12718.d: Likewise. * testsuite/ld-i386/pr12921.d: Likewise. * testsuite/ld-x86-64/abs-k1om.d: Likewise. * testsuite/ld-x86-64/abs-l1om.d: Likewise. * testsuite/ld-x86-64/abs.d: Likewise. * testsuite/ld-x86-64/pr12718.d: Likewise. * testsuite/ld-x86-64/pr12921.d: Likewise. * testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property section. * testsuite/ld-scripts/print-memory-usage.t: Likewise. * testsuite/ld-scripts/size-2.t: Likewise. * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld to create executable if language is "asm". (cherry picked from commit 241e64e3b42cd9eba514b8e0ad2ef39a337f10a5) -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 H.J. Lu changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #6 from H.J. Lu --- Fixed for 2.32 and on 2.31 branch. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #4 from cvs-commit at gcc dot gnu.org --- The master branch has been updated by H.J. Lu : https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=241e64e3b42cd9eba514b8e0ad2ef39a337f10a5 commit 241e64e3b42cd9eba514b8e0ad2ef39a337f10a5 Author: H.J. Lu Date: Fri Jul 20 09:18:47 2018 -0700 x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed When -z separate-code, which is enabled by default for Linux/x86, is used to create executable, ld won't place any data in the code-only PT_LOAD segment. If there are no data sections placed before the code-only PT_LOAD segment, the program headers won't be mapped into any PT_LOAD segment. When the executable tries to access it (based on the program header address passed in AT_PHDR), it will lead to segfault. This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if there may be no data sections before the text section so that the first PT_LOAD segment won't be code-only and will contain the program header. Testcases are adjusted to either pass "-z noseparate-code" to ld or discard the .note.gnu.property section. A Linux/x86 run-time test is added. bfd/ PR ld/23428 * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the separate code program header is needed, make sure that the first read-only PT_LOAD segment has no code by adding a GNU_PROPERTY_X86_ISA_1_USED note. ld/ PR ld/23428 * testsuite/ld-elf/linux-x86.S: New file. * testsuite/ld-elf/linux-x86.exp: Likewise. * testsuite/ld-elf/pr23428.c: Likewise. * testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld for Linux/x86 targets. * testsuite/ld-i386/abs-iamcu.d: Likewise. * testsuite/ld-i386/abs.d: Likewise. * testsuite/ld-i386/pr12718.d: Likewise. * testsuite/ld-i386/pr12921.d: Likewise. * testsuite/ld-x86-64/abs-k1om.d: Likewise. * testsuite/ld-x86-64/abs-l1om.d: Likewise. * testsuite/ld-x86-64/abs.d: Likewise. * testsuite/ld-x86-64/pr12718.d: Likewise. * testsuite/ld-x86-64/pr12921.d: Likewise. * testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property section. * testsuite/ld-scripts/print-memory-usage.t: Likewise. * testsuite/ld-scripts/size-2.t: Likewise. * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld to create executable if language is "asm". -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #3 from Rich Felker --- I don't object to the patch as-is, but wouldn't it make more sense to make the program headers a first-class section with attribute alloc, so that they're semantically forced to be visible at runtime rather than just happening to fall into a load segment that exists due to other sections? This fix would be target-agnostic and would prevent the issue from ever arising for other targets. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 --- Comment #2 from H.J. Lu --- A patch is posted at https://sourceware.org/ml/binutils/2018-07/msg00321.html -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 Florian Weimer changed: What|Removed |Added CC||fweimer at redhat dot com -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug ld/23428] ld does not put program headers in a code-only load segment
https://sourceware.org/bugzilla/show_bug.cgi?id=23428 H.J. Lu changed: What|Removed |Added Assignee|unassigned at sourceware dot org |hjl.tools at gmail dot com Target Milestone|--- |2.32 Summary|ld does not put program |ld does not put program |headers in a load segment |headers in a code-only load |when static linking an |segment |executable | -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils