Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selectively suppressing glibc link warnings?

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

like image 294
Andrew Tomazos Avatar asked Jan 21 '26 08:01

Andrew Tomazos


2 Answers

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

No.

like image 94
Employed Russian Avatar answered Jan 24 '26 14:01

Employed Russian


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.

like image 38
Jeremy Avatar answered Jan 24 '26 16:01

Jeremy