Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changes introduced in gcc 4.5 with respect to linking?

I have a project that produces a shared library which is linked against another, also shared, library.

When I compile and link it with gcc 4.4, everything works:

  1. no compile-time warning or error,
  2. no linking time warning or error and
  3. ldd libmyproject.so correctly reports the dependency with the other shared library.

When I compile and link it with gcc 4.5, on the other hand (with the exact same flags), I have the following symptoms:

  1. no compile-time warning or error,
  2. no linking time warning or error but
  3. the library is not correctly linked against the other shared lib: this manifest itself when I run ldd and don't see the connection, and also when I try to use it: while it works with gcc 4.4, it crashes at run-time with gcc 4.5 with a "symbol not found" error (of course from the other lib).

I looked at the release notes and my intuition is that it has something to do with the new link-time optimization, but I could not understand them in enough details.

Did anyone encounter a similar situation and/or has any advice to offer?

(Note that results with 4.6 are in appearance identical to 4.5).

like image 243
Philippe Avatar asked Nov 07 '11 20:11

Philippe


People also ask

Does GCC have a linker?

GCC uses a separate linker program (called ld.exe ) to perform the linking.

What's new in gcc11?

GCC 11 adds support for non-rectangular loop nests in OpenMP constructs and the allocator routines of OpenMP 5.0, including initial allocate clause support in C/C++. The OMP_TARGET_OFFLOAD environment variable and the active-levels routines are now supported.

Is GCC a compiler or linker?

The GNU Compiler Collection (gcc) The GNU Compiler Collection, gcc, can compile programs written in C, C++, Java and several other languages. It provides many useful command line options and syntax extensions, and also serves as a powerful frontend for the GNU linker, ld.

Does G ++ 4.8 5 support C++ 11?

Status of Experimental C++11 Support in GCC 4.8GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler options; the former disables GNU extensions.

How to use GCC to compile and link a file?

This tell gcc to compile the file using the compiler options shown (and those generated from the call to pkg-config, then call the linker With linker options ,--export-dynamic. Add -v for verbose output, e.g. gcc -v ..... and you will see all that is put together to compile and link.

What's happening to GCC support?

Support for a number of older systems and recently unmaintained or untested target ports of GCC has been declared obsolete in GCC 4.5. Unless there is activity to revive them, the next release of GCC will have their sources permanently removed. Details for the IRIX, Solaris 7, and Tru64 UNIX obsoletions can be found in the announcement.

What is the next release of GCC?

Unless there is activity to revive them, the next release of GCC will have their sources permanently removed. Solaris 9 (*-*-solaris2.9). Details can be found in the announcement.

What does the function attribute noinline do in GCC?

The function attribute noinline no longer prevents GCC from cloning the function. A new attribute noclone has been introduced for this purpose. Cloning a function means that it is duplicated and the new copy is specialized for certain contexts (for example when a parameter is a known constant).


2 Answers

To summarize Mat's answer from GCC 4.5 vs 4.4 linking with dependencies and the discussion in the comments, you need to link with:

--copy-dt-needed-entries and --no-as-needed
like image 177
cha0site Avatar answered Oct 02 '22 16:10

cha0site


You can debug your dynamically linked application with LD_DEBUG environment variable. This is an option of ld-linux.so.2; ldd is a script to set such option too. All options are described at http://linux.die.net/man/8/ld-linux man page.

How to use LD_DEBUG (in bash; the easiest way):

 $ LD_DEBUG=all ./your_program

This will turn on debugging of ld-linux.so.2 - the run-time dynamic linker. It will print a lot of debugging to stdout or stderr and you will be able to

  • 1) compare output of "LD_DEBUG=all ./your_program_4.4" and "LD_DEBUG=all ./your_program_4.5"
  • 2) see the last symbols trying to be resolved and locate buggy symbol.

Also, you should give us more information:

  • 0) What is your OS and cpu type? (show us output of uname -a) What is the version of libc? (run in bash for a in /lib*/libc.so.*;do echo $a; $a; done)
  • 1) What are compiling flags of your library itself?
  • 2) What is exact error when you try to run the application?
  • 3) Last lines from output of LD_DEBUG can contain valuable information

UPDATE: Good and exact answer is here: GCC 4.5 vs 4.4 linking with dependencies (by Mat)

like image 23
osgx Avatar answered Oct 02 '22 16:10

osgx