Created attachment 9636 [details]
enable warn-shared-textrel by default
In gnu-ld, warn-shared-textrel is disabled by default. Why not to enable it by default?
One of our customers found that he did not have enough memory to run his application after a recompilation. The root cause turn out to be a silly mistake that he forgot to add "-fPIC" for his shared libraries. Yes yes, the one who make mistakes got to pay the price, it's very reasonable. But there were no warning at all, a normal user(not a expert) probably did not know what was wrong (and how to fix). This does not seem reasonable...
Although some arches(like x86-64) force all shared libraries to be PIC, there are some that does not. In my opinion, the linker should be a good place to make the warnings. So, warn-shared-textrel should be enable by default.
attached patch enable "warn-shared-textrel" and add a new option to close this warning, is that ok?
patches should be sent to the firstname.lastname@example.org mailing list for discussion. there are problems with this particular patch, but that can be ironed out after we discuss whether we want to do this in the first place.
you'll also need to update gold.
(In reply to Mike Frysinger from comment #1)
> patches should be sent to the email@example.com mailing list for
> discussion. there are problems with this particular patch, but that can be
> ironed out after we discuss whether we want to do this in the first place.
> you'll also need to update gold.
Thanks for the reply. I have send a mail to firstname.lastname@example.org.
for the things about gold: we did not use the gold linker,so I am not familiar with it. if this behavior change were accepted by the binutils community, I will pay some time for the gold.
Instead of enabled-by-default --warn-shared-textrel, we can
* make bfd_link_info::error_textrel default to 1
* delete warn_shared_textrel
* make --warn-shared-textrel a no-op
The bi-state approach is used by LLD: either -z notext or -z text. There is no state where DT_TEXTREL/DF_TEXTREL is added on demand. The diagnostic should remind the user that -z notext may be needed.
ld.lld: error: can't create dynamic relocation R_386_32 against symbol: gdt in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
>>> defined in a.o
>>> referenced by a.o:(.text+0x2)
Created attachment 12567 [details]
A patch is posted at
The master branch has been updated by H.J. Lu <email@example.com>:
Author: H.J. Lu <firstname.lastname@example.org>
Date: Thu May 28 04:21:04 2020 -0700
ld: Add --enable-textrel-check=[no|yes|warning|error]
Add a configure option, --enable-textrel-check=[no|yes|warning|error],
to decide what ELF linker should do by default with DT_TEXTREL in an
executable or shared library.
* NEWS: Mention --enable-textrel-check=[no|yes|warning|error].
* configure.ac: Add --enable-textrel-check=[no|yes|warning|error].
(DEFAULT_LD_TEXTREL_CHECK): New AC_DEFINE_UNQUOTED.
* ldmain.c (main): Initialize link_info.textrel_check to
* lexsup.c (ld_options): Check DEFAULT_LD_TEXTREL_CHECK_WARNING.
* config.in: Regenerated.
* configure: Likewise.
Fixed for 2.35.