Gentoo enables --warn-shared-textrel by default for and extends warning to all dynamic executables (PIE or not): https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/binutils/2.17/66_all_binutils-2.17.50.0.2-warn-textrel.patch?revision=1.1&view=markup What do you think of extending this option (or adding new one) to cover executables in upstream binutils? Something like --warn-textrel. Lack of TEXTREL warning came up recently in gcc where gcc was built with TEXTRELs due to a platform-specific gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84553 The warning would be complementary to '-Wl,-z,-text' which converts problems of this kind to errors. Related bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20824 : "enable warn-shared-textrel by default".
Do you have a testcase which shows the problem on x86 targets?
I was not able to force x86 targets to generate TEXTREL executables. Best I could do is to emit pseudo textrel but it does not cause TEXTREL section creation: // a.c #include <stdio.h> int _start() { __asm__ volatile ( ".Ltext_reloc:" ".reloc .Ltext_reloc - _start, R_386_32, printf\n" ".long 0x90909090\n" ); } $ gcc -m32 a.c -O2 -o a -rdynamic -no-pie -nostdlib -lc -Wl,-q Is there a way to force printf symbol ot be resolved to absolute address instead of .plt?
Gentoo still has that check enabled. A few days ago it found the problem in riscv64 as bug #25694 (a case of bug #22263).
Duplicate of PR ld/20824 I think we've had enough text relocation related options. With the proposed --enable-textrel-check=error, this might be simple and easy: * -z notext/-z textoff -> enable text relocations * -z text -> disallow text relocations (error if unavoidable)
*** Bug 26035 has been marked as a duplicate of this bug. ***
A patch is posted at https://sourceware.org/pipermail/binutils/2020-May/111250.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=a6dbf402de65fe66f4ec99b56527dfd00d077cb6 commit a6dbf402de65fe66f4ec99b56527dfd00d077cb6 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed May 27 04:53:54 2020 -0700 ld: Add --warn-textrel and obsolete --warn-shared-textrel --warn-shared-textrel and -z text apply to both shared object and PIE. Add --warn-textrel and obsolete --warn-shared-textrel. Consolidate --warn-textrel and -z text/notext/textoff implementation. bfd/ PR ld/22909 * elflink.c (bfd_elf_final_link): Use bfd_link_textrel_check. Check bfd_link_dll when issue a DT_TEXTREL warning. * elfxx-x86.c (maybe_set_textrel): Likewise. (_bfd_x86_elf_size_dynamic_sections): Likewise. include/ PR ld/22909 * bfdlink.h (textrel_check_method): New enum. (bfd_link_textrel_check): New. (bfd_link_info): Replace warn_shared_textrel and error_textrel with textrel_check. ld/ PR ld/22909 * NEWS: Mention --warn-textrel. * ld.texi: Update -z text/notext/textoff. Add --warn-textrel. Remove --warn-shared-textrel. * ldlex.h (option_values): Rename OPTION_WARN_SHARED_TEXTREL to OPTION_WARN_TEXTREL. * lexsup.c (ld_options): Add --warn-textrel. Obsolete --warn-shared-textrel. (parse_args): Updated. (elf_shlib_list_options): Check link_info.textrel_check. * emultempl/elf.em: Updated. * testsuite/ld-elf/pr19539.d: Replace -z notext with --warn-textrel. Expect a warning. * testsuite/ld-i386/warn1.d: Update expected warning.
Fixed for 2.35.
The master branch has been updated by Hans-Peter Nilsson <hp@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2a37823bfe57d43f6c43a48a00237ba169599c3c commit 2a37823bfe57d43f6c43a48a00237ba169599c3c Author: Hans-Peter Nilsson <hp@axis.com> Date: Wed May 27 23:14:45 2020 +0200 PR ld/22909 amendment; don't xfail ld-elf/pr19539.d for cris*-*-*. Noticed by my autotester covering cris-axis-linux-gnu: ... Running <x>/src/ld/testsuite/ld-elf/elf.exp ... XPASS: ld-elf/pr19539 ... This was apparently as intended, so I'm just adjusting the xfail. PR ld/22909 * testsuite/ld-elf/pr19539.d: Don't xfail for cris*-*-*.