https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96190
Bug ID: 96190 Summary: --enable-default-pie on sparc uses crtbeginS.o (correct) and crtend.o (incorrect) Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at inbox dot ru Target Milestone: --- The side-effect of the crtbeginS.o/crtend.o mismatch are: - R_SPARC_NONE relocations in final executables: https://sourceware.org/PR26236 - TEXTRELs in binaries Simple reproducer: $ echo 'int main(){}' | sparc-unknown-linux-gnu-gcc -x c - -o a /usr/libexec/gcc/sparc-unknown-linux-gnu/ld: warning: creating a DT_TEXTREL in object $ echo 'int main(){}' | sparc-unknown-linux-gnu-gcc -x c - -o a -no-pie $ echo 'int main(){}' | sparc-unknown-linux-gnu-gcc -x c - -o a -pie gcc is built as: """ Using built-in specs. COLLECT_GCC=/usr/bin/sparc-unknown-linux-gnu-gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/sparc-unknown-linux-gnu/10.1.0/lto-wrapper Target: sparc-unknown-linux-gnu Configured with: /tmp/portage-tmpdir/portage/cross-sparc-unknown-linux-gnu/gcc-10.1.0-r2/work/gcc-10.1.0/configure --host=x86_64-pc-linux-gnu --target=sparc-unknown-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/sparc-unknown-linux-gnu/gcc-bin/10.1.0 --includedir=/usr/lib/gcc/sparc-unknown-linux-gnu/10.1.0/include --datadir=/usr/share/gcc-data/sparc-unknown-linux-gnu/10.1.0 --mandir=/usr/share/gcc-data/sparc-unknown-linux-gnu/10.1.0/man --infodir=/usr/share/gcc-data/sparc-unknown-linux-gnu/10.1.0/info --with-gxx-include-dir=/usr/lib/gcc/sparc-unknown-linux-gnu/10.1.0/include/g++-v10 --with-python-dir=/share/gcc-data/sparc-unknown-linux-gnu/10.1.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 10.1.0-r2 p3' --disable-esp --enable-libstdcxx-time --enable-poison-system-directories --with-sysroot=/usr/sparc-unknown-linux-gnu --disable-bootstrap --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libmudflap --disable-libssp --disable-libada --disable-systemtap --enable-vtable-verify --without-zstd --enable-lto --without-isl --enable-default-pie --enable-default-ssp Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.1.0 (Gentoo 10.1.0-r2 p3) """ I think the bug here is in SPEC files where crtendS.o is only pulled by explicit options: gcc/config/sparc/linux.h: "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\ gcc/config/sparc/linux64.h: "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\ AFAIu it should be something similar to generic case: gcc/config/gnu-user.h: shared|static-pie|" PIE_SPEC ":crtendS.o%s; \ Does it sound about right? Should other targets follow as well? Specifically: gcc/config/alpha/linux.h: crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/alpha/linux.h: crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/alpha/linux.h: %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" gcc/config/bfin/linux.h: crti.o%s %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/c6x/uclinux-elf.h: "%{!shared:crt1%O%s} crti%O%s %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/csky/csky-linux-elf.h: crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/csky/csky-linux-elf.h: "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" gcc/config/frv/linux.h: crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/frv/linux.h: "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" gcc/config/ia64/linux.h: crti.o%s %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/ia64/linux.h: crti.o%s %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/ia64/linux.h: %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" gcc/config/m32r/linux.h: crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" gcc/config/m32r/linux.h: "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" gcc/config/sparc/linux.h: "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\ gcc/config/sparc/linux64.h: "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\