Discussion:
sysroot and lib-path
Christer Solskogen
2018-11-08 07:23:25 UTC
Permalink
Hi!

I'm a bit confused on how binutils (or really ld.bfd / gold) works when
building a cross compiler.
For instance, if I build binutils like this:
--target=arm-linux-gnueabihf
--with-sysroot=/opt/cross/sysroot.arm-linux-gnueabihf

/opt/cross/bin/arm-linux-gnueabihf-ld --verbose | grep SEAR
SEARCH_DIR("=/opt/cross/arm-linux-gnueabihf/lib");
SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");

Why is directories on the host in SEARCH_DIR? And not
$sysroot/lib:$sysroot:usr/lib ?

/opt/cross/bin/arm-linux-gnueabihf-ld --print-sysroot
/opt/cross/sysroot.arm-linux-gnueabihf

I see that LFS (Linux from scratch) adds --with-lib-path to configure
their temporary cross compiler, but their way confuses me even more as
they point their lib-path to somewhere on the host system that will
contain libraries for the host and not for the target.
Alan Modra
2018-11-09 00:15:53 UTC
Permalink
Post by Christer Solskogen
Hi!
I'm a bit confused on how binutils (or really ld.bfd / gold) works when
building a cross compiler.
--target=arm-linux-gnueabihf
--with-sysroot=/opt/cross/sysroot.arm-linux-gnueabihf
/opt/cross/bin/arm-linux-gnueabihf-ld --verbose | grep SEAR
SEARCH_DIR("=/opt/cross/arm-linux-gnueabihf/lib");
SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");
You don't get the first SEARCH_DIR line you show if you are using the
FSF binutils sources with the configure options you state. I suspect
you also configured with --prefix=/opt/cross.
Post by Christer Solskogen
Why is directories on the host in SEARCH_DIR? And not
$sysroot/lib:$sysroot:usr/lib ?
But these are all in the sysroot. The sysroot is substituted for the
'=' in the search paths by ld. This allows ld's configure time
sysroot to be overridden on the ld command line with --sysroot=.
--
Alan Modra
Australia Development Lab, IBM
Christer Solskogen
2018-11-09 08:55:28 UTC
Permalink
Post by Alan Modra
You don't get the first SEARCH_DIR line you show if you are using the
FSF binutils sources with the configure options you state. I suspect
you also configured with --prefix=/opt/cross.
Yes, I only pasted what I thought was the relevant configure options. Sorry.
Post by Alan Modra
Post by Christer Solskogen
Why is directories on the host in SEARCH_DIR? And not
$sysroot/lib:$sysroot:usr/lib ?
But these are all in the sysroot. The sysroot is substituted for the
'=' in the search paths by ld. This allows ld's configure time
sysroot to be overridden on the ld command line with --sysroot=.
Okay, but why does it also have
SEARCH_DIR("=/opt/cross/arm-linux-gnueabihf/lib") then? That doesn't
make sense, does it?

Last, but not least. Thanks for your reply, I didn't know that the = is
substituted.
--
chs
Alan Modra
2018-11-09 13:10:21 UTC
Permalink
Post by Christer Solskogen
Okay, but why does it also have
SEARCH_DIR("=/opt/cross/arm-linux-gnueabihf/lib") then? That doesn't make
sense, does it?
That's $prefix/$target/lib. Note that it's inside the sysroot too.
So in your case the host directory searched would be
/opt/cross/sysroot.arm-linux-gnueabihf/opt/cross/arm-linux-gnueabihf/lib

$prefix/$target was an idea that predated sysroot for a place to put
target and tool specific info. You might see that directory
referred to as tooldir.
--
Alan Modra
Australia Development Lab, IBM
Christer Solskogen
2018-11-09 14:11:25 UTC
Permalink
Post by Alan Modra
Post by Christer Solskogen
Okay, but why does it also have
SEARCH_DIR("=/opt/cross/arm-linux-gnueabihf/lib") then? That doesn't make
sense, does it?
That's $prefix/$target/lib. Note that it's inside the sysroot too.
So in your case the host directory searched would be
/opt/cross/sysroot.arm-linux-gnueabihf/opt/cross/arm-linux-gnueabihf/lib
Which is why I said that I don't think that makes sense :-) I would
understand it if no sysroot was set.
Post by Alan Modra
$prefix/$target was an idea that predated sysroot for a place to put
target and tool specific info. You might see that directory
referred to as tooldir.
Yeah, I see that binutils places hardlinks in bin and ldscripts in the
lib directory. IMHO I think $prefix/$target should be what the sysroot
would or could be set at, but if I do that now host and target stuff
would be mixed. Which, right now, makes (only?) sense with a target that
newlib supports.

But ok, for now on tooldir and sysroot needs to be two different
directories if you want to use sysroot.

Loading...