[cfe-commits] [PATCH] [Driver] Make default GCC install prefix and sysroot relocatable
Kito Cheng
kito at 0xlab.org
Wed Dec 12 05:13:49 PST 2012
Let's a brief summary the current discuss and what's this patch want to do.
URL : http://llvm-reviews.chandlerc.com/D203
* The Goal of this patch
Make the default sysroot and gcc install prefix relocatable.
For example you have an
$HOME/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-clang and
it's have configure with --with-default-sysroot to
$HOME/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc.
you can compile program to arm with
$HOME/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-clang hello.c
now, for some reason you change the path of toolchain such as
re-name the folder
mv $HOME/arm-none-linux-gnueabi $HOME/arm-none-linux-gnueabi-test
and you use the toolchain again
$HOME/arm-none-linux-gnueabi-test/bin/arm-none-linux-gnueabi-clang hello.c
/home/kito/hello.c:1:10: fatal error: 'stdio.h' file not found
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
but clang will complain can't find the header! (and the libraries
also not found!).
because the clang use the absolute path to find sysroot and search
header and libraries.
(You can observe by -v flag)
$HOME/arm-none-linux-gnueabi-test/bin/arm-none-linux-gnueabi-clang hello.c -v
clang version 3.3 (http://llvm.org/git/clang.git
007c44ccbd048472469514284697f23a58475f35)
(http://llvm.org/git/llvm.git
d181342eee9eed65e5428a33646288345cdbdd7a)
Target: arm-none-linux-gnueabi
Thread model: posix
"/home/kito/arm-none-linux-gnueabi-test/bin/arm-none-linux-gnueabi-clang"
-cc1 -triple armv4t-none-linux-gnueabi -S -disable-free
-main-file-name hello.c -mrelocation-model static -mdisable-fp-elim
-fmath-errno -mconstructor-aliases -target-abi aapcs-linux -target-cpu
arm7tdmi -mfloat-abi soft -target-feature +soft-float-abi
-target-linker-version 2.21.53.0.1 -momit-leaf-frame-pointer -v
-resource-dir /home/kito/arm-none-linux-gnueabi-test/bin/../lib/clang/3.3
-isysroot /home/kito/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/
-fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
/home/kito/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc//usr/local/include
-internal-isystem
/home/kito/arm-none-linux-gnueabi-test/bin/../lib/clang/3.3/include
-internal-externc-isystem
/home/kito/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc//include
-internal-externc-isystem
/home/kito/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc//usr/include
-fno-dwarf-directory-asm -fdebug-compilation-dir /home/kito
-ferror-limit 19 -fmessage-length 96 -mstackrealign -fno-signed-char
-fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/hello-BzqVDG.s -x c hello.c
clang -cc1 version 3.3 based upon LLVM 3.3svn default target
arm-none-linux-gnueabi
ignoring nonexistent directory
"/home/kito/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc//usr/local/include"
ignoring nonexistent directory
"/home/kito/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc//include"
ignoring nonexistent directory
"/home/kito/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc//usr/include"
#include "..." search starts here:
#include <...> search starts here:
/home/kito/arm-none-linux-gnueabi-test/bin/../lib/clang/3.3/include
End of search list.
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
However, the gcc has the capability to relocate the sysroot to right
path according
the path of gcc executable.
So the goal is the
$HOME/arm-none-linux-gnueabi-test/bin/arm-none-linux-gnueabi-clang
in this example also can find the right sysroot.
* An instruction for the above experiment setup.
For example we are build a cross-compler for clang
../llvm/configure --prefix=$HOME/arm-none-linux-gnueabi
--target=arm-none-linux-gnueabi \
--with-default-sysroot=$HOME/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/
\
--enable-targets=arm
The prefix folder is hold the prebuild toolchain,
you can try this with this experiment:
https://sourcery.mentor.com/sgpp/lite/arm/portal/package9728/public/arm-none-linux-gnueabi/arm-2011.09-70-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
* GCC_INSTALL_PREFIX
The gcc install prefix also has simular issue like sysroot, however
threre is no such relocate issue
if the gcc is install with the same prefix.
However it's not work if you configure clang with the --with-gcc-toolchain!
for example
../llvm/configure --prefix=$HOME/arm-none-linux-gnueabi
--target=arm-none-linux-gnueabi \
--with-default-sysroot=$HOME/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/
\
--enable-targets=arm
and prefix folder hold the prebuild toolchain again, it's can find
the correct toolchain
such as arm-none-linux-gnueabi-as and arm-none-linux-gnueabi-ld.
../llvm/configure --prefix=$HOME/arm-none-linux-gnueabi
--target=arm-none-linux-gnueabi \
--with-default-sysroot=$HOME/arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/
\
--enable-targets=arm --with-gcc-toolchain=$HOME/arm-none-linux-gnueabi
And it's NOT WORK if you specify the defautl gcc toolchain path!
* Proposed Solution:
1. Relocate the sysroot by path of clang executable.(This patch, and
this approach is what the gcc do)
2. Make sysroot support setting to relative path, for example
--with-default-sysroot="$prefix/sysroot"
and the $prefix will substitute with the path of clang
executable. (Propose by Rafael EspĂndola)
(eg. clang in /path/to/bin/clang, and sysroot is /path/to/sysroot)
More information about the cfe-commits
mailing list