Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc link option to see why some object file is linked into binary

I have some link problem.

To investigate the problem I add -t linker flag (gcc -Wl,-t) to print what libraries are used and what objects from static libraries are used.

There's one static library that in some configuration one set of object files are used and in other other set.

Is there any way (probably ld flag) to see why specific object (what previously undefined symbol is defined in the object file) is linked into binary and other from the same static library is not?

like image 672
dimba Avatar asked Oct 25 '12 09:10

dimba


People also ask

Which GCC option is used to link the library?

The -l option tells GCC to link in the specified library.

Does GCC automatically link?

Most Windows compilers support auto-linking, as does Clang, while GCC does not support auto-linking.

What is a linker flag?

The flag tells the linker to link in the produced binary only the libraries containing symbols actually used by the binary itself. This binary can be either a final executable or another library. In theory, when linking something, only the needed libraries are passed to the command line used to invoke the linker.


1 Answers

The flag I was looking for is -M, which prints a link map to the standard output.

From ld(1):

  -M
  --print-map
      Print a link map to the standard output.  A link map provides information about the link, including the following:
           ·   Where object files are mapped into memory.
           ·   How common symbols are allocated.
           ·   All archive members included in the link, with a mention of the symbol which caused the archive member to be brought in.
           ·   The values assigned to symbols.

Second item in the list is what I was looking.

like image 144
dimba Avatar answered Oct 07 '22 07:10

dimba