public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Building gcc11 with sysroot
@ 2021-09-24  1:42 Oleg Smolsky
  2021-09-24 21:13 ` Oleg Smolsky
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Smolsky @ 2021-09-24  1:42 UTC (permalink / raw)
  To: gcc-help

Hello there! I'm trying to setup a GCC 11.2 using --with-sysroot=$sysroot
(into which glibc is already installed). I get far enough to have `xgcc`
executable (which works). The executable itself is configured to get glibc
from sysroot (I did that via LDFLAGS):

```
$ ldd ./gcc/xgcc
        linux-vdso.so.1 (0x00007ffec27d7000)
        libm.so.6 => /opt/sysroot/usr/lib/libm.so.6 (0x00007fc12463c000)
        libc.so.6 => /opt/sysroot/usr/lib/libc.so.6 (0x00007fc124440000)
        /opt/sysroot/usr/lib/ld-linux-x86-64.so.2 =>
/lib64/ld-linux-x86-64.so.2 (0x00007fc124718000)
```

where
LDFLAGS="-Wl,--dynamic-linker,$sysroot/usr/lib/ld-linux-x86-64.so.2,--rpath,$sysroot/usr/lib"

Things break a little further down the road when building libgomp:

checking whether we are cross compiling... configure: error: in
`.../gcc11sr/_obj/x86_64-pc-linux-gnu/libgomp':
configure: error: cannot run C compiled programs.

The issue here, it seems, is the absence of LDFLAGS that I had passed to
the top-level `configure` script. We can see the compiler invocation in the
log:

configure:3996: .../gcc11sr/_obj/./gcc/xgcc -B.../gcc11sr/_obj/./gcc/
-B/opt/gcc-11sr/x86_64-pc-linux-gnu/bin/
-B/opt/gcc-11sr/x86_64-pc-linux-gnu/lib/ -isystem
/opt/gcc-11sr/x86_64-pc-linux-gnu/include -isystem
/opt/gcc-11sr/x86_64-pc-linux-gnu/sys-include    -o conftest -g -O2
conftest.c  >&5

The compiler yields a correctly-formed executable when I take that very
command line and add LDFLAGS.

So, finally my question: is this the right way to build a "sysrooted" GCC?
IIRC this recipe worked in the GCC7 days...

Thanks in advance,
Oleg.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Building gcc11 with sysroot
  2021-09-24  1:42 Building gcc11 with sysroot Oleg Smolsky
@ 2021-09-24 21:13 ` Oleg Smolsky
  2021-09-25 10:11   ` Xi Ruoyao
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Smolsky @ 2021-09-24 21:13 UTC (permalink / raw)
  To: gcc-help

...and the workaround for that issue was to add `--target=x86_64-linux-gnu`
which, as I understand it, switches the build into the cross-compiler mode.
I think there was some variance in the treatment of that flag in GCC
versions 7/10/11...

Curiously, `--target=x86_64-pc-linux-gnu` does not help... I am guessing
that matches the host... And also, the generated executable bundle only has
full names like `x86_64-linux-gnu-c++`, there are no `c++`, `cpp` etc.

Can anyone shed some light on this aspect of the build process please?



On Thu, Sep 23, 2021 at 6:42 PM Oleg Smolsky <osmolsky@netskope.com> wrote:

> Hello there! I'm trying to setup a GCC 11.2 using --with-sysroot=$sysroot
> (into which glibc is already installed). I get far enough to have `xgcc`
> executable (which works). The executable itself is configured to get glibc
> from sysroot (I did that via LDFLAGS):
>
> ```
> $ ldd ./gcc/xgcc
>         linux-vdso.so.1 (0x00007ffec27d7000)
>         libm.so.6 => /opt/sysroot/usr/lib/libm.so.6 (0x00007fc12463c000)
>         libc.so.6 => /opt/sysroot/usr/lib/libc.so.6 (0x00007fc124440000)
>         /opt/sysroot/usr/lib/ld-linux-x86-64.so.2 =>
> /lib64/ld-linux-x86-64.so.2 (0x00007fc124718000)
> ```
>
> where
> LDFLAGS="-Wl,--dynamic-linker,$sysroot/usr/lib/ld-linux-x86-64.so.2,--rpath,$sysroot/usr/lib"
>
> Things break a little further down the road when building libgomp:
>
> checking whether we are cross compiling... configure: error: in
> `.../gcc11sr/_obj/x86_64-pc-linux-gnu/libgomp':
> configure: error: cannot run C compiled programs.
>
> The issue here, it seems, is the absence of LDFLAGS that I had passed to
> the top-level `configure` script. We can see the compiler invocation in the
> log:
>
> configure:3996: .../gcc11sr/_obj/./gcc/xgcc -B.../gcc11sr/_obj/./gcc/
> -B/opt/gcc-11sr/x86_64-pc-linux-gnu/bin/
> -B/opt/gcc-11sr/x86_64-pc-linux-gnu/lib/ -isystem
> /opt/gcc-11sr/x86_64-pc-linux-gnu/include -isystem
> /opt/gcc-11sr/x86_64-pc-linux-gnu/sys-include    -o conftest -g -O2
> conftest.c  >&5
>
> The compiler yields a correctly-formed executable when I take that very
> command line and add LDFLAGS.
>
> So, finally my question: is this the right way to build a "sysrooted" GCC?
> IIRC this recipe worked in the GCC7 days...
>
> Thanks in advance,
> Oleg.
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Building gcc11 with sysroot
  2021-09-24 21:13 ` Oleg Smolsky
@ 2021-09-25 10:11   ` Xi Ruoyao
  2021-09-28 16:09     ` [EXTERNAL] " Oleg Smolsky
  0 siblings, 1 reply; 6+ messages in thread
From: Xi Ruoyao @ 2021-09-25 10:11 UTC (permalink / raw)
  To: Oleg Smolsky, gcc-help

On Fri, 2021-09-24 at 14:13 -0700, Oleg Smolsky via Gcc-help wrote:
> ...and the workaround for that issue was to add `--target=x86_64-
> linux-gnu`
> which, as I understand it, switches the build into the cross-compiler
> mode.
> I think there was some variance in the treatment of that flag in GCC
> versions 7/10/11...
> 
> Curiously, `--target=x86_64-pc-linux-gnu` does not help... I am
> guessing
> that matches the host... And also, the generated executable bundle
> only has
> full names like `x86_64-linux-gnu-c++`, there are no `c++`, `cpp` etc.
> 
> Can anyone shed some light on this aspect of the build process please?

I'm not sure how do you mean by "sysroot GCC".

If you want a compiler running on the existing host system but produce
executables running in the sysroot (after reboot/chroot into it), yes
you need to build GCC as a cross compiler because the output of the
compiler normally can't run on the host.  It's better to use
"--target=x86_64-sysroot-linux-gnu" to make it clear that you're
building a cross compiler.  If you don't like the prefix in the
executable name, I think it's able to override it with --program-
prefix="" (not tried).

If you want a compiler running in sysroot (after reboot/chroot into it),
cross-compile it with a cross compiler (using --host=x86_64-sysroot-
linux-gnu).

You may find some way to pretend the executables for sysroot "runnable
on the host", but it's not the expected usage of GCC building system and
likely to be broken if something in the building system changes.

> 
> 
> On Thu, Sep 23, 2021 at 6:42 PM Oleg Smolsky <osmolsky@netskope.com>
> wrote:
> 
> > Hello there! I'm trying to setup a GCC 11.2 using --with-
> > sysroot=$sysroot
> > (into which glibc is already installed). I get far enough to have
> > `xgcc`
> > executable (which works). The executable itself is configured to get
> > glibc
> > from sysroot (I did that via LDFLAGS):
> > 
> > ```
> > $ ldd ./gcc/xgcc
> >         linux-vdso.so.1 (0x00007ffec27d7000)
> >         libm.so.6 => /opt/sysroot/usr/lib/libm.so.6
> > (0x00007fc12463c000)
> >         libc.so.6 => /opt/sysroot/usr/lib/libc.so.6
> > (0x00007fc124440000)
> >         /opt/sysroot/usr/lib/ld-linux-x86-64.so.2 =>
> > /lib64/ld-linux-x86-64.so.2 (0x00007fc124718000)
> > ```
> > 
> > where
> > LDFLAGS="-Wl,--dynamic-linker,$sysroot/usr/lib/ld-linux-x86-
> > 64.so.2,--rpath,$sysroot/usr/lib"
> > 
> > Things break a little further down the road when building libgomp:
> > 
> > checking whether we are cross compiling... configure: error: in
> > `.../gcc11sr/_obj/x86_64-pc-linux-gnu/libgomp':
> > configure: error: cannot run C compiled programs.
> > 
> > The issue here, it seems, is the absence of LDFLAGS that I had
> > passed to
> > the top-level `configure` script. We can see the compiler invocation
> > in the
> > log:
> > 
> > configure:3996: .../gcc11sr/_obj/./gcc/xgcc -
> > B.../gcc11sr/_obj/./gcc/
> > -B/opt/gcc-11sr/x86_64-pc-linux-gnu/bin/
> > -B/opt/gcc-11sr/x86_64-pc-linux-gnu/lib/ -isystem
> > /opt/gcc-11sr/x86_64-pc-linux-gnu/include -isystem
> > /opt/gcc-11sr/x86_64-pc-linux-gnu/sys-include    -o conftest -g -O2
> > conftest.c  >&5
> > 
> > The compiler yields a correctly-formed executable when I take that
> > very
> > command line and add LDFLAGS.
> > 
> > So, finally my question: is this the right way to build a
> > "sysrooted" GCC?
> > IIRC this recipe worked in the GCC7 days...
> > 
> > Thanks in advance,
> > Oleg.
> > 

-- 
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [EXTERNAL] Re: Building gcc11 with sysroot
  2021-09-25 10:11   ` Xi Ruoyao
@ 2021-09-28 16:09     ` Oleg Smolsky
  2021-09-28 18:42       ` Segher Boessenkool
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Smolsky @ 2021-09-28 16:09 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-help

On Sat, Sep 25, 2021 at 3:18 AM Xi Ruoyao <xry111@mengyan1223.wang> wrote:

> If you want a compiler running in sysroot (after reboot/chroot into it),
> cross-compile it with a cross compiler (using --host=x86_64-sysroot-
> linux-gnu).
>
> You may find some way to pretend the executables for sysroot "runnable
> on the host", but it's not the expected usage of GCC building system and
> likely to be broken if something in the building system changes.
>

I am trying to get both: such executables run on the host system, yet all
run-time dependencies are located within the "sysroot". I vaguely remember
someone calling such a x86-to-x86 cross-compiler a "Canadian cross"... The
idea here is to enforce a tight, fully-encapsulated build environment for
the host and then ship it all into the production. This combo runs on any
Linux distro...

Oleg.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [EXTERNAL] Re: Building gcc11 with sysroot
  2021-09-28 16:09     ` [EXTERNAL] " Oleg Smolsky
@ 2021-09-28 18:42       ` Segher Boessenkool
  2021-09-28 21:34         ` Oleg Smolsky
  0 siblings, 1 reply; 6+ messages in thread
From: Segher Boessenkool @ 2021-09-28 18:42 UTC (permalink / raw)
  To: Oleg Smolsky; +Cc: Xi Ruoyao, gcc-help

On Tue, Sep 28, 2021 at 09:09:43AM -0700, Oleg Smolsky via Gcc-help wrote:
> On Sat, Sep 25, 2021 at 3:18 AM Xi Ruoyao <xry111@mengyan1223.wang> wrote:
> > If you want a compiler running in sysroot (after reboot/chroot into it),
> > cross-compile it with a cross compiler (using --host=x86_64-sysroot-
> > linux-gnu).
> >
> > You may find some way to pretend the executables for sysroot "runnable
> > on the host", but it's not the expected usage of GCC building system and
> > likely to be broken if something in the building system changes.
> 
> I am trying to get both: such executables run on the host system, yet all
> run-time dependencies are located within the "sysroot". I vaguely remember
> someone calling such a x86-to-x86 cross-compiler a "Canadian cross"... The
> idea here is to enforce a tight, fully-encapsulated build environment for
> the host and then ship it all into the production. This combo runs on any
> Linux distro...

"Cross compiler" means that the host is not the same as the build.  A
Canadian cross has the build system a different system as well.

build = host = target  is the normal "native" case.

build = host != target  is the normal "cross" case.

build != host = target  is building a native compiler on a different
system.  This is not often done anymore.

build = target != host  is sometimes called "cross-back".  This is the
rarest kind perhaps.  It is sometimes done as part of a new port, and
in that case you have various other of the above types as well, and
hopefully you fully know ewhat you are doing.  It isn't useful for most
users.

If host is linux and target is mingw, then this always is a cross, no
matter if the CPU architecture on both is the same.  The full triple
matters.


Segher

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [EXTERNAL] Re: Building gcc11 with sysroot
  2021-09-28 18:42       ` Segher Boessenkool
@ 2021-09-28 21:34         ` Oleg Smolsky
  0 siblings, 0 replies; 6+ messages in thread
From: Oleg Smolsky @ 2021-09-28 21:34 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Xi Ruoyao, gcc-help

Right, thank you for clarifying the terms here, Segher!

Practically, for my case, build = target = host (it's `x86_64-pc-linux-gnu`
for all environments). Yet, I specify a distinct target (it's
`x86_64-linux-gnu`) to get a cross-compiler. Yes, it's a fake one. The
point here is to bake the default "sysroot" value into the compiler to
control the headers/libs visible to the compilation process (and exclude
the system's ones).

Oleg.


On Tue, Sep 28, 2021 at 12:04 PM Segher Boessenkool <
segher@kernel.crashing.org> wrote:

> On Tue, Sep 28, 2021 at 09:09:43AM -0700, Oleg Smolsky via Gcc-help wrote:
> > On Sat, Sep 25, 2021 at 3:18 AM Xi Ruoyao <xry111@mengyan1223.wang>
> wrote:
> > > If you want a compiler running in sysroot (after reboot/chroot into
> it),
> > > cross-compile it with a cross compiler (using --host=x86_64-sysroot-
> > > linux-gnu).
> > >
> > > You may find some way to pretend the executables for sysroot "runnable
> > > on the host", but it's not the expected usage of GCC building system
> and
> > > likely to be broken if something in the building system changes.
> >
> > I am trying to get both: such executables run on the host system, yet all
> > run-time dependencies are located within the "sysroot". I vaguely
> remember
> > someone calling such a x86-to-x86 cross-compiler a "Canadian cross"...
> The
> > idea here is to enforce a tight, fully-encapsulated build environment for
> > the host and then ship it all into the production. This combo runs on any
> > Linux distro...
>
> "Cross compiler" means that the host is not the same as the build.  A
> Canadian cross has the build system a different system as well.
>
> build = host = target  is the normal "native" case.
>
> build = host != target  is the normal "cross" case.
>
> build != host = target  is building a native compiler on a different
> system.  This is not often done anymore.
>
> build = target != host  is sometimes called "cross-back".  This is the
> rarest kind perhaps.  It is sometimes done as part of a new port, and
> in that case you have various other of the above types as well, and
> hopefully you fully know ewhat you are doing.  It isn't useful for most
> users.
>
> If host is linux and target is mingw, then this always is a cross, no
> matter if the CPU architecture on both is the same.  The full triple
> matters.
>
>
> Segher
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-28 21:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24  1:42 Building gcc11 with sysroot Oleg Smolsky
2021-09-24 21:13 ` Oleg Smolsky
2021-09-25 10:11   ` Xi Ruoyao
2021-09-28 16:09     ` [EXTERNAL] " Oleg Smolsky
2021-09-28 18:42       ` Segher Boessenkool
2021-09-28 21:34         ` Oleg Smolsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).