From Fedora Project Wiki

Revision as of 16:37, 21 December 2009 by Valce (talk | contribs) (Example deltarpm)

Understanding the (Proposed) Change to DSO Linking

A quick list of packages that were found to have DSO link issues in mock builds is at DSOLinkBugs


The default behaviour for ld allows users to 'indirectly' link to required objects/libraries through intermediate objects/libraries. While this is convenient, it can also be dangerous because it makes your program's dependencies tied to the dependencies of other objects. If those objects ever change their linkages, they can break your program without any changes to your own code!

For example : has:

 NEEDED            Shared library: []
 NEEDED            Shared library: []

Under the old system, a program that links with libxml2 and uses dlopen may not link with libdl, and a program that links with libxml2 and uses gzopen may not link with libz. While these programs will work, they will break if libxml2 is ever changed to omit the dependency on libdl/libz.

What's the difference?

For example (courtesy Roland McGrath):

 ==> foo1.c <==
 #include <stdio.h>
 extern int foo ();
 main ()
   printf ("%d\n", foo ());
 ==> foo2.c <==
 extern int foo ();
 int bar () { return foo (); }
 ==> foo3.c <==
 int foo () { return 0; }

Prepare position-independent code:

gcc -g -fPIC -c foo1.c foo2.c foo3.c


gcc -shared -o foo3.o

Generate, linking

gcc -shared -o foo2.o

The proposed change will affect the next step: Creating foo1.


A call to gcc will succeed quietly, even though the link to is only implicit.

 gcc -o foo1 foo1.o -Wl,--rpath-link=.


The call to gcc will fail, prompting the user to explicitly link the required shared object.

 gcc -o foo1 foo1.o -Wl,--rpath-link=.
/usr/bin/ld: foo1.o: undefined reference to symbol 'foo'
/usr/bin/ld: note: 'foo' is defined in DSO ./ so try adding it to the linker command line

So, the difference is whether you can refer to a symbol that's in a DSO that you didn't list explicitly in your link line, but that is a DT_NEEDED dependency of one of those (or recursively of those, I think).

The big difference is that with the proposed change in place, ld will no longer skip linking needed libraries by default. The current default behaviour will lead ld to skip linking with a library if it is listed as a needed by another library that the program uses. In abstract terms, if libA is needed by libB and your program requires both libA and libB, your program may only link to libB. Then if another version of libB comes out that does not list libA as a needed library, then a recompilation will mysteriously break.

What do I do?

If you encounter this error, the error message will prompt you to explicitly link to the DSO that you need. From the foo example, adding will get rid of the error:

gcc -o foo1 foo1.o -Wl,--rpath-link=.

Example deltarpm

Run fedora-cvs deltarpm or check out a 'devel' version of deltarpm from :

Go to the devel folder and run 'make srpm' to produce a source rpm.

In /etc/mock, copy the desired fedora-rawhide-*.cfg file to test.cfg. In the test.cfg file, change the root to 'test'.

Add the following to test.cfg:


This will enable the mock build to pull the latest test version of ld. Next, run the build by executing mock -r /path/to/deltarpm/srpm

The following error should appear in /var/lib/mock/test/result/build.log :

RPM build errors:
/usr/bin/ld.bfd: rpmdumpheader.o: undefined reference to symbol 'Fopen'
/usr/bin/ld.bfd: note: 'Fopen' is defined in DSO /usr/lib/ so try adding it to the linker command line
/usr/lib/ could not read symbols: Invalid operation
*** /usr/bin/ld: ld behavior mismatch! ***
*** /usr/bin/ld.bfd succeeeded ***
*** /usr/bin/ld.bfd --no-add-needed exits 1 ***
*** arguments: --eh-frame-hdr --build-id -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ -o rpmdumpheader
/usr/lib/gcc/i686-redhat-linux/4.4.2/../../../crt1.o /usr/lib/gcc/i686-redhat-linux/4.4.2/../../../crti.o /usr/lib/gcc/i686-redhat-linux/4.4.2/crtbegin.o
-L/usr/lib/gcc/i686-redhat-linux/4.4.2 -L/usr/lib/gcc/i686-redhat-linux/4.4.2 -L/usr/lib/gcc/i686-redhat-linux/4.4.2/../../.. rpmdumpheader.o -lrpm -lgcc 
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i686-redhat-linux/4.4.2/crtend.o
collect2: ld returned 1 exit status
make: *** [rpmdumpheader] Error 1

This indicates that deltarpm used /usr/lib/ without explicitly linking to it. To fix, add -lrpmio to the gcc command for any binaries that use librpmio. In deltarpm, this can be done quickly by changing the Makefile:

rpmdumpheader: rpmdumpheader.o
-       $(CC) $(LDFLAGS) $^ -lrpm -o $@
+       $(CC) $(LDFLAGS) $^ -lrpm -lrpmio -o $@

Holiday Contact

Have questions? During the holiday season, feel free to e-mail Charley at fakey dot mcfakename at if you have any issues (Yes, that is his real e-mail address)