Bug 7061 - cross ld configured with --with-sysroot doesn't search all relevant library directories
Summary: cross ld configured with --with-sysroot doesn't search all relevant library d...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.19
: P2 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-02 05:42 UTC by f.knauf
Modified: 2022-08-25 01:32 UTC (History)
1 user (show)

See Also:
Host: i686-linux-gnu
Target: sparc-sun-solaris2.8
Build: i686-linux-gnu
Last reconfirmed:


Attachments
Make 32-bit sparc library searching behave in the same way as the 64-bit version (257 bytes, patch)
2009-01-03 12:38 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description f.knauf 2008-12-02 05:42:38 UTC
I was building a cross-compiler from i686 linux to sparc solaris 2.8. Binutils
were configured as

../binutils-2.19/configure --target=sparc-sun-solaris2.8 \
  --with-sysroot=/usr/local/sysroots/sparc-sun-solaris2.8

Where /usr/local/sysroots/sparc-sun-solaris2.8 contains the /usr/include and
/usr/lib directories from a solaris2.8/sparc machine. 

It worked for the most part, but when I was done building gcc, I noticed that
the linker does not search /usr/local/sparc-sun-solaris2.8/lib (called $tool_lib
from now on) when linking 32 bit applications. These would thus not link unless
I passed -rpath-link=$tool_lib to the linker, complaining libgcc_s.so.1 and
libstdc++.so.6 could not be found. 64 bit applications link fine, however.

The problem lies in the builtin linker scripts. Where the
${builddir}/ld/ldscripts/elf64_sparc.x* linker scripts (and consequently
ld/eelf64_sparc.c) are generated including $tool_lib/sparcv9 (but not $tool_lib)
in the SEARCH_DIRs, the elf32_sparc.x* scripts don't have $tool_lib; their
relevant line is

SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/usr/ccs/lib"); SEARCH_DIR("=/lib");
SEARCH_DIR("=/usr/lib");

Manually patching eelf32_sparc.c, then compiling ld solves the problem.

I believe the relevant piece of code is in ${sourcedir}/ld/genscripts.sh, lines
155 to 164, where $tool_lib is added to $libs _unless_ binutils are configured
with --with-sysroot - in which case they are, however, also needed there.
Comment 1 Nick Clifton 2009-01-03 12:38:09 UTC
Created attachment 3633 [details]
Make 32-bit sparc library searching behave in the same way as the 64-bit version
Comment 2 Nick Clifton 2009-01-03 12:41:19 UTC
Hi,

  I do not think that genscripts.sh is misbehaving here.  In general if you are
providing a sysroot then you should not expect the linker to search elsewhere
for libraries.  The fact that the 64-bit sparc linker does do this is an
anomaly. (At least in my opinion).  It does make sense however that the 32-bit
and 64-bit sparc linkers should behave in same way, so please could you try out
the uploaded patch which will make the 32-bit sparc linker look in the normal
system library directories as well as the sysroot directories.

Cheers
  Nick
Comment 3 f.knauf 2009-01-09 13:24:19 UTC
That works, at least for my use case.

About the searchworthyness of those directories with a sysroot linker...I don't
know much about the bowels of binutils or gcc, so I can't make any calls on
design questions. From a user's perspective, though - unless I (and, indeed,
most people who bothered with cross compilers on the 'net) was grossly
misinformed, --with-sysroot is the preferred means to build cross compilers, and
it would make a lot of sense if the linker the compiler uses found the
compiler's components.

How that is best achieved is open for debate, I suppose, but one way or another,
the linker has to know where to find them.
Comment 4 Alan Modra 2022-08-25 01:32:48 UTC
Fixed a long time ago