glibc uses the following "technique" to generate link warnings...
#define link_warning(symbol, msg) \
__make_section_unallocated (".gnu.warning." #symbol) \
static const char __evoke_link_warning_##symbol[] \
__attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
= msg;
For a particular link warning generated by this, is there any command-line switch that can be passed to ld or gcc in order to suppress it?
(For compile-time warnings you can suppress with `#pragma diagnostic foo ignore")
is there any command-line switch that can be passed to ld or gcc in order to suppress it
No.
First of all, it's important to remember that the warnings are (usually) there for a reason. If you can find a way to avoid linking the symbols that the warning refers to, that's a far preferable course of action.
Now... As the question notes, the linker emits the warnings because they're in library sections named '.gnu.warning.*'. And as explained at length in this answer, there's no way to suppress this with a command line switch.
But renaming the relevant sections will suppress the warnings.
(You could try removing the sections, but the __evoke_* symbols are referenced in the relocation tables. Renaming is simpler, and can be reversed in future - although of course you should back up the original of any library you do this to.)
objcopy --rename-section .gnu.warning.<symbol>=.xgnu.warning.<symbol> libX.a libX-nowarnings.a
You can link the modified library, or replace the original in situ. Of course, whether this is possible or advisable depends on your specific circumstances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With