Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overrule default gcc options to the linker?

On my system when I compile something (with bfin-linux-uclibc-g++ but that is irrelevant), I get hundreds of warnings (not in my own code base) with respect to one of the compiler flags. I want to disable it.

fde encoding in src/SpiMessageUtil.o(.eh_frame) prevents .eh_frame_hdr table being created.

This orginates from a default gcc flag which is handed over to the linker, which is easy to check by adding '-v' to the compilation step:

COLLECT_GCC_OPTIONS=... --eh-frame-hdr ...

I would like to get rid of this option, which is indeed by default defined:

bfin-linux-uclibc-g++ -dumpspecs | grep frame-hdr
%{!static:--eh-frame-hdr}\
%{mfdpic: -m elf32bfinfd -z text} %{shared} %{pie}   \
%{static:-dn -Bstatic}   %{shared:-G -Bdynamic}   \
%{!shared: %{!static:    %{rdynamic:-export-dynamic}    \
  %{!dynamic-linker:-dynamic-linker \
     %{mglibc:%{muclibc:%e-mglibc and -muclibc used together;:%e-mglibc not supported for this target};:/lib/ld-uClibc.so.0 \
}}}\
%{static}} -init __init -fini __fini

How can I override this option? I cannot use -Wl,--no-eh-frame-hdr, because there is nothing like that defined.

like image 300
Anne van Rossum Avatar asked Nov 03 '22 21:11

Anne van Rossum


1 Answers

You can dynamically dump GCC's specs, remove this switch from there and use it when linking, i.e.:

g++ -dumpspecs | sed -e 's,--eh-frame-hdr,,g' > better_specs
g++ -specs=better_specs -o target file1.o file2.o -llib1...

This would replace the specs inline, while keeping original compiler intact.

If you keep your own Makefiles, this could also be handled with something like:

$(TARGET): $(OBJS) | better_specs
    $(LINK.o) $(OUTPUT_OPTION) -specs=$| $^

better_specs:
    $(CXX) -dumpspecs | sed -e 's,--eh-frame-hdr,,g' > $@

This approach could be also used with configure scripts, provided that you generate better_specs before, you could just use ./configure CXX='g++ -specs=/path/to/better_specs'.

like image 193
raspy Avatar answered Jan 04 '23 13:01

raspy