cross-linker behaviour differs from native linked
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
armel-cross-toolchain-base (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
armhf-cross-toolchain-base (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
binutils (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
binutils-armel-cross (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
binutils-armhf-cross (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
This requires a bit of background to understand. From the man page of ld(1).
-snip-
When using ELF or SunOS, one shared library may require another.
This happens when an "ld -shared" link includes a shared library as
one of the input files.
When the linker encounters such a dependency when doing a non-
shared, non-relocatable link, it will automatically try to locate
the required shared library and include it in the link, if it is
not included explicitly. In such a case, the -rpath-link option
option may specify a sequence of directory names either by
multiple times.
This option should be used with caution as it overrides the search
path that may have been hard compiled into a shared library. In
such a case it is possible to use unintentionally a different
search path than the runtime linker would do.
The linker uses the following search paths to locate required
shared libraries:
1. Any directories specified by -rpath-link options.
2. Any directories specified by -rpath options. The difference
link time. Searching -rpath in this way is only supported by
with the --with-sysroot option.
3. On an ELF system, for native linkers, if the -rpath and
4. On SunOS, if the -rpath option was not used, search any
5. For a native linker, the search the contents of the environment
6. For a native ELF linker, the directories in "DT_RUNPATH" or
7. The default directories, normally /lib and /usr/lib.
8. For a native linker on an ELF system, if the file
If the required shared library is not found, the linker will issue
a warning and continue with the link.
-snip-
Our concern are the sections 3, 5, 6, 8 and indirectly 7 (/usr/lib/
The problem is, that while we search for libraries in /usr/lib/
The attached testcase, which succeeds on native ld, will fail with the cross-toolchain with:
-snip-
/usr/lib/
/usr/lib/
collect2: ld returned 1 exit status
-snip-
Changing the last line to either:
arm-linux-
arm-linux-
Will make the build succeed.
We have a bunch of options here:
1) patch ld to make cross-ld behave identically to ld. This can be done by setting "NATIVE=yes" in genscripts.sh of binutils
2) add /usr/lib/
3) tell people to change their buildscripts to add all libraries to the linking command line. This is tricky, as most people don't select the -lflags them self, they come from pkg-config et all. Further more, people have been actively endorsing doing the complete opposite, eg. removing all unnecessary -lflags to cut down package dependencies.
4) copy the ld wrapper from scratchbox that adds the default directories and LD_LIBRARY_PATH with -rpath-link to the real linkier... I don't think we want that, but just for sake of completeness lets mention it ;)
Discuss.
Changed in armel-cross-toolchain-base (Ubuntu): | |
assignee: | nobody → Linaro Developer Platform (linaro-foundations) |
Changed in armel-cross-toolchain-base (Ubuntu): | |
assignee: | Linaro Developer Platform (linaro-foundations) → Marcin Juszkiewicz (hrw) |
status: | Confirmed → In Progress |
tags: | added: patch |
Changed in binutils (Ubuntu): | |
status: | New → Confirmed |
Status changed to 'Confirmed' because the bug affects multiple users.