2

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")

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
  • 2
    [How do you suppress GCC linker warnings?](https://stackoverflow.com/questions/3409448/how-do-you-suppress-gcc-linker-warnings)? – cremno Aug 24 '15 at 20:25
  • Does this answer your question? [How do you suppress GCC linker warnings?](https://stackoverflow.com/questions/3409448/how-do-you-suppress-gcc-linker-warnings) – Victor Sergienko Aug 15 '20 at 01:38

2 Answers2

1

is there any command-line switch that can be passed to ld or gcc in order to suppress it

No.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
0

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.

Jeremy
  • 5,055
  • 1
  • 28
  • 44