[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2023-07-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |WORKSFORME

--- Comment #12 from Andrew Pinski  ---
Because pc as the vendor for x86_64-* is the default.

>From config.sub:
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
i*86 | x86_64)
cpu=$basic_machine
vendor=pc
;;

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2019-03-21 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #11 from Mateusz Zych  ---
Oh, I forgot to mention that I've also tested this configuration:

HOST=x86_64-abc-linux-gnu
TARGET=x86_64-xyz-linux-gnu

and it worked without any issues.

I don't understand why would these configurations fail:

   HOST   = x86_64-linux-gnu
   TARGET = x86_64-pc-linux-gnu

   HOST   = x86_64-pc-linux-gnu
   TARGET = x86_64-pc-linux-gnu

yet such a fabricated configuration works.
This is really confusing. @.@

Best regards, Mateusz

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2019-03-21 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #10 from Mateusz Zych  ---
Created attachment 46005
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46005&action=edit
Build log of first GCC, ending on compilation failure of libstdc++-v3.

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2019-03-21 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #9 from Mateusz Zych  ---
Hi ;)

I've analysed this issue further and
tested all combinations of different vendors in host and target triplets.

Here are the results:
 +---+
 |   host|
 |---|
 |    |  glibc |unknown |   pc   |
++---+
|   |    |  FAIL  |  PASS  |  PASS  |  FAIL  |
| t ||||||
| a |  glibc |  PASS  |  FAIL  |  PASS  |  PASS  |
| r ||||||
| g |unknown |  PASS  |  PASS  |  FAIL  |  PASS  |
| e ||||||
| t |   pc   |  FAIL  |  PASS  |  PASS  |  FAIL  |
++---+

Looks like building isolated compiler (target == host) doesn't work at all
and for some reason cross-compiling by combining no vendor with pc vendor fails
as well.

Note that, all failing configurations are encountering the same issue
with compilation of libstdc++-v3 during first GCC build:

  checking whether the 
  /home/mzych/Downloads/build-many-glibcs/gcc-first-build/./gcc/xgcc 
  -B/home/mzych/Downloads/build-many-glibcs/gcc-first-build/./gcc/ 
  -B/home/mzych/Downloads/build-many-glibcs/gcc/x86_64-pc-linux-gnu/bin/ 
  -B/home/mzych/Downloads/build-many-glibcs/gcc/x86_64-pc-linux-gnu/lib/ 
  -isystem
/home/mzych/Downloads/build-many-glibcs/gcc/x86_64-pc-linux-gnu/include 
  -isystem
/home/mzych/Downloads/build-many-glibcs/gcc/x86_64-pc-linux-gnu/sys-include
  linker
(/home/mzych/Downloads/build-many-glibcs/gcc-first-build/./gcc/collect-ld -m
elf_x86_64) 
  supports shared libraries... yes
  checking dynamic linker characteristics... 
  configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
  Makefile:18985: recipe for target 'configure-stage1-target-libstdc++-v3'
failed

Initially I was thinking that there might be something wrong with the script,
which I've used to build GCC (CreateToolchain.sh),
but it seems unlikely, since other configurations work without any issues.

To me this looks very surprising that changing vendor in a triplet causes GCC
to fail to compile.
Can somebody help with figuring out what's going on here?

I think that the script CreateToolchain.sh could benefit the whole GCC
community,
because developers could use it to compile GCC by simply choosing desired
configuration.

Thank you, Mateusz

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2019-03-05 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #8 from Mateusz Zych  ---
Created attachment 45901
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45901&action=edit
Script creating standalone GNU toolchain for C++.

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2019-03-05 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #7 from Mateusz Zych  ---
Hi Joseph, ;)


Thank you very much for your advice - it was really helpful!
I've managed to implement a script creating standalone GNU toolchain for C++:

 - https://github.com/mtezych/cpp/blob/master/CreateToolchain.sh


However, I still have an issue with some configurations of triples.
For example,
the following cross-compiling configurations are building successfully:

   HOST   = x86_64-pc-linux-gnu
   TARGET = x86_64-glibc-linux-gnu

   HOST   = x86_64-linux-gnu
   TARGET = x86_64-glibc-linux-gnu

   HOST   = x86_64-pc-linux-gnu
   TARGET = x86_64-unknown-linux-gnu

   HOST   = x86_64-unknown-linux-gnu
   TARGET = x86_64-pc-linux-gnu

Even cross-compiling for x86 works:

   HOST   = x86_64-unknown-linux-gnu
   TARGET = i686-pc-linux-gnu

However, for some reason these configurations do not work:

   HOST   = x86_64-linux-gnu
   TARGET = x86_64-pc-linux-gnu

   HOST   = x86_64-pc-linux-gnu
   TARGET = x86_64-linux-gnu

Also, I cannot build an isolated compiler:

   HOST   = x86_64-linux-gnu
   TARGET = x86_64-linux-gnu

   HOST   = x86_64-pc-linux-gnu
   TARGET = x86_64-pc-linux-gnu

   HOST   = x86_64-unknown-linux-gnu
   TARGET = x86_64-unknown-linux-gnu

   HOST   = x86_64-glibc-linux-gnu
   TARGET = x86_64-glibc-linux-gnu


Can you explain to me what's the significance of a vendor in a triplet?
That is, what's the difference between these triplets?

 - x86_64-linux-gnu
 - x86_64-pc-linux-gnu
 - x86_64-none-linux-gnu
 - x86_64-glibc-linux-gnu
 - x86_64-unknown-linux-gnu

Maybe there is a piece of documentation, blog post or an article,
that you can point me to, which explains this?


Which triplet configuration I should use for a host and a target,
when I am using regular GNU/Linux distro (Ubuntu MATE 18.04 LTS)
and want to target wide range or GNU/Linux distros?

Are triples returned by these commands good values for triples?
 $ gcc -dumpmachine -> x86_64-linux-gnu
 $ make -v  -> x86_64-pc-linux-gnu


Thank you, Mateusz

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2018-11-12 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #6 from joseph at codesourcery dot com  ---
If you want the modern process for building a cross toolchain for a 
GNU/Linux (or GNU/Hurd) target, look at how glibc's build-many-glibcs.py 
does it.  (This is not saying you need to use build-many-glibcs.py - 
rather, that studying the script will show you the modern process, which 
you can then integrate into your own toolchain build, whereas many scripts 
and instructions out there for building cross toolchains have a lot of 
obsolete code in them handling things that may have been issues ten years 
ago but haven't been needed for a long time now and are not now the 
recommended way to do things.)

As building a cross toolchain is something that involves builds of several 
different components in the right sequence, and each component has its own 
maintainers and documentation concerned specifically with that one 
component, the overall process doesn't fit easily in the documentation for 
any one toolchain component.  The GCC documentation only naturally 
describes how to build GCC, leaving it to the reader to deduce how to 
compose multiple builds of GCC and other components if they wish to build 
a whole toolchain.

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2018-11-12 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

Mateusz Zych  changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |---

--- Comment #5 from Mateusz Zych  ---
I read numerous articles describing how to build standalone GCC for source:

 -
https://solarianprogrammer.com/2018/05/06/building-gcc-cross-compiler-raspberry-pi/
 - https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
 - https://wiki.osdev.org/GCC_Cross-Compiler
 - https://wiki.osdev.org/Building_GCC
 - https://gist.github.com/maoueh/14ef25a03d5722bc1e03

None of above approaches worked for me. ;(
I'm always ending up with some obscure compilation / linking issue.

Can someone just explain to me,
how to build GCC using configuration option "--with-sysroot="?
I would really appreciate it.

PS. I am treating this as a bug,
because I couldn't find any official documentation explaining
how to build GCC using configuration option "--with-sysroot=".
I just think that the whole process of doing so shouldn't be that hard.

Thanks, Mateusz

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2018-11-05 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #4 from Mateusz Zych  ---
Right, the "--with-sysroot=" configuration parameter is the key.
The sysroot directory defines minimal filesystem of a target machine,
in particular it should contain standard C library and Linux kernel headers,
so it makes sense that I have to provide the sysroot directory
to build standalone GCC, which would be a cross compiler.

However, I don't understand why would
configuration parameters "--host=" and "--target=",
define whether I am building a cross compiler or not.
To me, what differentiates cross compiler form native compiler,
is the location of libraries and headers.

 - Native compilers use libraries and headers from host machine.
 - Cross compilers never touch host machine and always use sysroot.

Of course, all compilers targeting different architecture compared to
architecture of the host machine have be cross compilers.
But the opposite is not true - not all cross compilers have to target
architecture different from architecture of the host machine.
They can match, no problem!
And this is exactly what I'm trying to do - I want build GCC cross compiler
targeting the exact same architecture that my host machine is using.


OK, with that out of the way, I've updated my script:

# Linux
wget https://kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.gz
tar -xvf linux-4.19.tar.gz
mv linux-4.19 linux-source
cd linux-source
make ARCH=x86_64 INSTALL_HDR_PATH=$PWD/../gcc/sysroot/usr headers_install
cd ..

# GNU C Library (glibc)
wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar -xvf glibc-2.28.tar.gz
mv glibc-2.28 glibc-source
mkdir glibc-build
cd glibc-build
../glibc-source/configure --build=x86_64-linux-gnu \
  --host=x86_64-linux-gnu \
  --target=x86_64-linux-gnu \
  --prefix=$PWD/../gcc/sysroot/usr \
  --with-headers=$PWD/../gcc/sysroot/usr/include \
  --disable-multilib \
  --disable-nls \
  --disable-timezone-tools
make all -j 4
make install
cd ..

# GNU Binutils
wget https://ftp.gnu.org/gnu/binutils/binutils-2.31.tar.gz
tar -xvf binutils-2.31.tar.gz
mv binutils-2.31 binutils-source
mkdir binutils-build
cd binutils-build
../binutils-source/configure --build=x86_64-linux-gnu \
 --host=x86_64-linux-gnu \
 --target=x86_64-linux-gnu \
 --prefix=$PWD/../gcc \
 --with-sysroot=$PWD/../gcc/sysroot \
 --disable-multilib \
 --disable-nls
make all -j 4
make install
cd ..

# GCC
wget https://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz
tar -xvf gcc-8.2.0.tar.gz
mv gcc-8.2.0 gcc-source
cd gcc-source
./contrib/download_prerequisites
cd ..
mkdir gcc-build
cd gcc-build
../gcc-source/configure --build=x86_64-linux-gnu \
--host=x86_64-linux-gnu \
--target=x86_64-linux-gnu \
--prefix=$PWD/../gcc \
--with-sysroot=$PWD/../gcc/sysroot \
--enable-languages=c,c++ \
--disable-multilib \
--disable-nls
make all -j 4
make install
cd ..

Essentially I am puting:
 - GCC and Binutils into $ROOT/gcc and
 - glibc with Linux headers into ROOT/gcc/sysroot.


Unfortunately with updated script, GCC is not compiling anymore. :(
I've never managed to compile GCC configured with parameter "--with-sysroot=".

What is actually failing? Well, the libgcc_s.so fails to link with libc.so.6:

attempt to open
/home/mzych/standalone-gcc/gcc-build/../gcc/sysroot/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc.so.6
failed
attempt to open
/home/mzych/standalone-gcc/gcc-build/../gcc/sysroot/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc_nonshared.a
failed
attempt to open
/home/mzych/standalone-gcc/gcc-build/../gcc/sysroot/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/ld-linux-x86-64.so.2
failed

/usr/bin/ld: cannot find
/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc.so.6
   inside /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot
/usr/bin/ld: cannot find
/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc_nonshared.a 
   inside /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot
/usr/bin/ld: cannot find
/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/ld-linux-x86-64.so.2
inside /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot

To me this failure looks like an issue with sysroot path,
bec

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2018-10-30 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #3 from joseph at codesourcery dot com  ---
On Tue, 30 Oct 2018, mte.zych at gmail dot com wrote:

> ../gcc-source/configure --build=x86_64-linux-gnu \
> --host=x86_64-linux-gnu \
> --target=x86_64-linux-gnu \

If host = target that's a native compiler, and searches native system 
library directories.  If you don't want that you need to configure with 
different host and target values (and probably use --with-sysroot= to 
point to an image of the native system library directories).

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2018-10-30 Thread mte.zych at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

--- Comment #2 from Mateusz Zych  ---
Hi Andrew ;)
Thanks for your reply.

You are right that, in order to create standalone GCC,
I need to provide C standard library,
because GCC can work with various C standard library implementations.
The GNU C Library (glibc) is just one implementation,
which is not always used (for example Android is using bionic).

To correct my script,
I changed it to download and compile binutils, glibc and gcc respectively:

# GNU Binutils
wget https://ftp.gnu.org/gnu/binutils/binutils-2.31.tar.gz
tar -xvf binutils-2.31.tar.gz
mv binutils-2.31 binutils-source
mkdir binutils-build
cd binutils-build
../binutils-source/configure --build=x86_64-linux-gnu \
 --host=x86_64-linux-gnu \
 --target=x86_64-linux-gnu \
 --prefix=$PWD/gcc \
 --disable-multilib \
 --disable-nls
make -j 4
make install
cd ..

# GNU C Library (glibc)
wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar -xvf glibc-2.28.tar.gz
mv glibc-2.28 glibc-source
mkdir glibc-build
cd glibc-build
../glibc-source/configure --build=x86_64-linux-gnu \
  --host=x86_64-linux-gnu \
  --target=x86_64-linux-gnu \
  --prefix=$PWD/gcc \
  --disable-multilib \
  --disable-nls \
  --disable-timezone-tools
make -j 4
make install
cd ..

# GCC
wget https://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz
tar -xvf gcc-8.2.0.tar.gz
mv gcc-8.2.0 gcc-source
cd gcc-source
./contrib/download_prerequisites
cd ..
mkdir gcc-build
cd gcc-build
../gcc-source/configure --build=x86_64-linux-gnu \
--host=x86_64-linux-gnu \
--target=x86_64-linux-gnu \
--prefix=$PWD/gcc \
--enable-languages=c,c++ \
--disable-multilib \
--disable-nls
make -j 4
make install
cd ..

This improved things, in a sense that, in my simple C++ application compiled
using GCC build from source it includes only these headers from host machine:

 - /usr/include/asm-generic/errno-base.h
 - /usr/include/asm-generic/errno.h
 - /usr/include/linux/errno.h
 - /usr/include/x86_64-linux-gnu/asm/errno.h

However, header files from host machine are still being included!
This can be seen when listing include directories used by GCC build from
source:

 
/home/mzych/gcc/bin/../lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0
 
/home/mzych/gcc/bin/../lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/x86_64-linux-gnu
 
/home/mzych/gcc/bin/../lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/backward
  /home/mzych/gcc/bin/../lib/gcc/x86_64-linux-gnu/8.2.0/include
  /home/mzych/gcc/bin/../lib/gcc/x86_64-linux-gnu/8.2.0/include-fixed
 ---> /usr/local/include
  /home/mzych/gcc/bin/../lib/gcc/../../include
 ---> /usr/include/x86_64-linux-gnu
 ---> /usr/include

OK, maybe I'm completely wrong here, but I think that
it would be great to introduce to GCC a configuration option,
which would prevent GCC from using any headers and libraries from host machine.

In this configuration, GCC would simply return compilation error in
case where required header or library would not found
in its own directory tree.

BTW, I was searching for such an option, but I couldn't find it.
 - https://gcc.gnu.org/install/configure.html

Thanks, Mateusz

[Bug driver/87769] GCC build from source uses headers and libraries from directories host machine.

2018-10-26 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #1 from Andrew Pinski  ---
GCC is not independent from the libc's headers.  GCC DOES NOT INCLUDE A LIBC. 
Glibc is the libc that is used on many Linux distro (but not the only one out
there).  If you want to build a completely self contained compiler/libraries,
there are many directions on the internet for that.

NOTE the standard C++ headers include the standard C headers in the end.