timberdoodle / # cat a.c int main(){} timberdoodle / # powerpc-unknown-linux-gnu-gcc a.c -o a /usr/lib/gcc/powerpc-unknown-linux-gnu/6.4.0/../../../../powerpc-unknown-linux-gnu/bin/ld: warning: creating a DT_TEXTREL in a shared object. timberdoodle / # gdb --quiet ./a Reading symbols from ./a...done. (gdb) run Starting program: /a Program received signal SIGSEGV, Segmentation fault. _dl_lookup_symbol_x (undef_name=0x206c6b66 <error: Cannot access memory at address 0x206c6b66>, undef_map=undef_map@entry=0xf7ffe900, ref=ref@entry=0xffffd038, symbol_scope=symbol_scope@entry=0xf7ffeac0, version=0x0, type_class=0, flags=flags@entry=1, skip_map=skip_map@entry=0x0) at dl-lookup.c:811 811 dl-lookup.c: No such file or directory. (gdb) bt #0 _dl_lookup_symbol_x (undef_name=0x206c6b66 <error: Cannot access memory at address 0x206c6b66>, undef_map=undef_map@entry=0xf7ffe900, ref=ref@entry=0xffffd038, symbol_scope=symbol_scope@entry=0xf7ffeac0, version=0x0, type_class=0, flags=flags@entry=1, skip_map=skip_map@entry=0x0) at dl-lookup.c:811 #1 0xf7fcb1ac in elf_machine_rela (skip_ifunc=<optimized out>, reloc_addr_arg=0x200004aa <got_label+46>, version=<optimized out>, sym=<optimized out>, reloc=0x20000390, map=0xf7ffe900) at ../sysdeps/powerpc/powerpc32/dl-machine.h:315 #2 elf_dynamic_do_Rela (skip_ifunc=<optimized out>, lazy=<optimized out>, nrelative=<optimized out>, relsize=<optimized out>, reladdr=<optimized out>, map=0xf7ffe900) at do-rel.h:137 #3 _dl_relocate_object (scope=0xf7ffeac0, reloc_mode=<optimized out>, consider_profiling=<optimized out>, consider_profiling@entry=0) at dl-reloc.c:259 #4 0xf7fc39c8 in dl_main (phdr=<optimized out>, phdr@entry=0x20000034, phnum=<optimized out>, phnum@entry=8, user_entry=user_entry@entry=0xffffe188, auxv=<optimized out>) at rtld.c:2170 #5 0xf7fd722c in _dl_sysdep_start (start_argptr=start_argptr@entry=0xffffe490, dl_main=0xf7fc15f0 <dl_main>) at ../elf/dl-sysdep.c:253 #6 0xf7fc0c60 in _dl_start_final (arg=arg@entry=0xffffe490, info=info@entry=0xffffe1e8) at rtld.c:399 #7 0xf7fc1030 in _dl_start (arg=0xffffe490) at rtld.c:507 #8 0xf7fd9424 in _start () at ../sysdeps/powerpc/powerpc32/dl-start.S:38 Backtrace stopped: frame did not save the PC
binutils-2.26.1 generates working binary, binutils-2.29.1 does not work.
Tried more binutils targets to see what immediately breaks 'int main(){}' example: [1] powerpc-unknown-linux-gnu-2.25.1 OK [2] powerpc-unknown-linux-gnu-2.26.1 OK [3] powerpc-unknown-linux-gnu-2.27 BROKEN [4] powerpc-unknown-linux-gnu-2.28.1 BROKEN [5] powerpc-unknown-linux-gnu-2.29.1 BROKEN Looks like regression was introduced around 2.26.1 - 2.27 times.
Compared readelf output for 'int main(){}' linked with binutils-2.26.1 and 2.27. The main difference is 2 relocation in '.rela.dyn' (dynamic symbols) section: Good (2.26.1): 0000050a 00000806 R_PPC_ADDR16_HA 00020024 _end + 20020 00000512 00000804 R_PPC_ADDR16_LO 00020024 _end + 20020 0000053e 00000806 R_PPC_ADDR16_HA 00020024 _end + 20020 00000546 00000804 R_PPC_ADDR16_LO 00020024 _end + 20020 Bad (2.27): 000004aa 00000806 R_PPC_ADDR16_HA 000004b2 00000804 R_PPC_ADDR16_LO 000004de 00000806 R_PPC_ADDR16_HA 000004e6 00000804 R_PPC_ADDR16_LO (for 2.27 readelf can't recognize relocation type and complains about the symbol type)
Bisected it down to 6b3b0ab89663306d17927d630304dbbd36e84570 is the first bad commit commit 6b3b0ab89663306d17927d630304dbbd36e84570 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Feb 23 05:18:43 2016 -0800 Make linker assigned symbol dynamic only for shared object Linker assigned symbols should be made dynamic by default only when creating shared object or relocatable executable. bfd/ * elflink.c (bfd_elf_record_link_assignment): Check for shared library, instead of PIC, and don't check PDE when making linker assigned symbol dynamic. ld/ * testsuite/ld-frv/fdpic-pie-6.d: Updated. * testsuite/ld-mips-elf/pie-n32.d: Likewise. * testsuite/ld-mips-elf/pie-n64.d: Likewise. * testsuite/ld-mips-elf/pie-o32.d: Likewise. :040000 040000 1815fe304ea13706d5a945a28068683414c3d5c4 e59fd268e5bdad0d4c58784298ebae1c3e4bb8f9 M bfd :040000 040000 09b9e50f4624715c59b2dc42ed6078e0a1b7edaf 7efb992565b9f49a4c6c4197e1274d611792883e M ld
Reported upstream: https://sourceware.org/bugzilla/show_bug.cgi?id=22626
In https://sourceware.org/bugzilla/show_bug.cgi?id=22626#c5 Alan pointed at gcc fixes already present in -6, -7 and -HEAD branches to use proper startup files. We will need to pull those to unbreak powerpc.
Created attachment 510578 [details] gcc-6.4.0-0001-RS6000-linux-startfile-endfile.patch
(In reply to Sergei Trofimovich from comment #7) > Created attachment 510578 [details] > gcc-6.4.0-0001-RS6000-linux-startfile-endfile.patch xgcc: fatal error: braced spec 'shared:; pg|p|profile:gcrt1.o%s; static:crt1.o%s; no-pie|static|r|shared:;:Scrt1.o%s; :crt1.o%s} %{mnewlib:ecrti.o%s;:crti.o%s} %{sta tic:crtbeginT.o%s; shared|no-pie|static|r|shared:;:crtbeginS.o%s; :crtbegin.o%s} %{fvtable-verify=none:%s; fvtable-verify=preinit:vtv_start_preinit.o%s; fvtable-verify= std:vtv_start.o%s} ' is invalid at ' ' compilation terminated. make[3]: *** [Makefile:950: libgcc_s.so] Error 1 Does not work as-is. Will need more fixes.
Created attachment 510580 [details, diff] gcc-6.4.0-0001-PR-driver-81523-Make-static-override-pie.patch
With both patches applied powerpc generates working PIE files.
Queued both patches for gcc/6.4.0 and gcc/7.2.0 as: """ gcc/6.4.0, gcc/7.2.0: fix --default-pie to use proper startup files, bug #641474 The change adds two patches to patchset: - gentoo/95_all_static_override_pie.patch - gentoo/96_all_powerpc_pie.patch First fixes -static handling for --default-pie compiler. Second fixes to use proper startup files for --default-pie on powerpc. Otherwise binutils-2.27 and upper generates invalid ELF files. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22626 Bug: https://bugs.gentoo.org/641474 """ Please test it a bit before we cut new gcc patchset off them.
commit 4207f3a916969991e9c19a6e27ba504d9e42da6e Author: Alan Modra <amodra@gmail.com> Date: Mon Dec 18 22:27:08 2017 +1030 PR22626, invalid dynindx used for dynamic relocs against section syms ^ queued for binutils-2.29.1 patchset
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ecb2d0bf2d0195efe753abb3f32e7ee1599c12ce commit ecb2d0bf2d0195efe753abb3f32e7ee1599c12ce Author: Sergei Trofimovich <slyfox@gentoo.org> AuthorDate: 2018-01-06 19:54:31 +0000 Commit: Sergei Trofimovich <slyfox@gentoo.org> CommitDate: 2018-01-06 19:55:00 +0000 sys-devel/gcc: bump 6.4.0 and 7.2.0 patchsets, bug #641474 Two new patches for a single issue: - 95_all_static_override_pie.patch - 96_all_powerpc_pie.patch First fixes -static handling for --default-pie compiler. Second fixes to use proper startup files for --default-pie on powerpc. This should unbreak 17.0 profiles at least for powerpc. Dropped keywords until minimal testing is done for other arches. Bug: https://bugs.gentoo.org/641474 Package-Manager: Portage-2.3.19, Repoman-2.3.6 sys-devel/gcc/Manifest | 2 ++ sys-devel/gcc/gcc-6.4.0-r1.ebuild | 25 +++++++++++++++++++++++++ sys-devel/gcc/gcc-7.2.0-r1.ebuild | 25 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+)}
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fe331fe6a6ce98f906685c43576b81e398ef6dbc commit fe331fe6a6ce98f906685c43576b81e398ef6dbc Author: Sergei Trofimovich <slyfox@gentoo.org> AuthorDate: 2018-01-12 08:02:25 +0000 Commit: Sergei Trofimovich <slyfox@gentoo.org> CommitDate: 2018-01-12 08:04:11 +0000 sys-devel/gcc: restore ~arch keywords for static+pie fixes, bug #641474 Bug: https://bugs.gentoo.org/641474 Package-Manager: Portage-2.3.19, Repoman-2.3.6 sys-devel/gcc/gcc-6.4.0-r1.ebuild | 3 +-- sys-devel/gcc/gcc-7.2.0-r1.ebuild | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)}
(In reply to Larry the Git Cow from comment #14) > The bug has been referenced in the following commit(s): > > https://gitweb.gentoo.org/repo/gentoo.git/commit/ > ?id=fe331fe6a6ce98f906685c43576b81e398ef6dbc > > commit fe331fe6a6ce98f906685c43576b81e398ef6dbc > Author: Sergei Trofimovich <slyfox@gentoo.org> > AuthorDate: 2018-01-12 08:02:25 +0000 > Commit: Sergei Trofimovich <slyfox@gentoo.org> > CommitDate: 2018-01-12 08:04:11 +0000 > > sys-devel/gcc: restore ~arch keywords for static+pie fixes, bug #641474 > > Bug: https://bugs.gentoo.org/641474 > Package-Manager: Portage-2.3.19, Repoman-2.3.6 > > sys-devel/gcc/gcc-6.4.0-r1.ebuild | 3 +-- in https://github.com/gentoo/gentoo/commit/fe331fe6a6ce98f906685c43576b81e398ef6dbc#commitcomment-26813297 hydrapolic pointed out i've restored then from KEYWORDS="" straight to stable. That was not intended but should not be harmful (especially on 17.0 profile). I'll revert back to ~arch if we get any reports of regression. But otherwise accidentally RESOLVED it.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a48596f11cd6b5ecfeb994b9ea9678f3499955f6 commit a48596f11cd6b5ecfeb994b9ea9678f3499955f6 Author: Sergei Trofimovich <slyfox@gentoo.org> AuthorDate: 2018-02-28 23:03:59 +0000 Commit: Sergei Trofimovich <slyfox@gentoo.org> CommitDate: 2018-02-28 23:04:09 +0000 sys-devel/gcc: stable 6.4.0-r1 for arm, bug #641474 Bug: https://bugs.gentoo.org/641474 Package-Manager: Portage-2.3.24, Repoman-2.3.6 sys-devel/gcc/gcc-6.4.0-r1.ebuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)}