sysroot and lib-path

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

sysroot and lib-path

Christer Solskogen-3
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.

Reply | Threaded
Open this post in threaded view
|

Re: sysroot and lib-path

Alan Modra-3
On Thu, Nov 08, 2018 at 08:23:25AM +0100, Christer Solskogen wrote:

> 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");

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.

> 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
Reply | Threaded
Open this post in threaded view
|

Re: sysroot and lib-path

Christer Solskogen-3
On 09.11.2018 01:15, Alan Modra wrote:

> 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.

>
>> 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

Reply | Threaded
Open this post in threaded view
|

Re: sysroot and lib-path

Alan Modra-3
On Fri, Nov 09, 2018 at 09:55:28AM +0100, Christer Solskogen wrote:
> 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
Reply | Threaded
Open this post in threaded view
|

Re: sysroot and lib-path

Christer Solskogen-3
On 09.11.2018 14:10, Alan Modra wrote:
> On Fri, Nov 09, 2018 at 09:55:28AM +0100, Christer Solskogen wrote:
>> 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.

> $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.