Michael Dalpee via llvm-dev
2018-Apr-11 19:41 UTC
[llvm-dev] Building an LLVM/CLANG cross compiler for legacy GCC toolchain
Hello, I need to build a CLANG cross compiler for mips-linux-uclibc. To be completely compatible with the target system, I would like it to use linux 2.6.32.54 headers, binutils 2.25, gcc 4.1.2, and uClibc 0.9.30.1 for the gcc toolchain. I have been able to build the GCC toolchain a variety of different ways, but none of these builds can be "dropped in" via clang as a replacement for just using the gcc toolchain directly. I am building the toolchain on ubuntu 14.04 using gcc 4.8.4. I believe this is because I do not understand how to build the toolchain such that when clang invokes toolchain programs (particularly the linker), those programs can find the things they need (include files, libraries, etc) to operate properly. This manifests itself in a variety of way depending on what technique I used to build the toolchain, but here is a representative problem from a toolchain I built using the buildroot system: clang -v -target mips-linux-uclibc --gcc-toolchain=/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr --sysroot=/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr -o build-mips-product/test-png -fPIC -I/home/mdalpee/checkouts/clang/source/src/program/include test_png.c png.c ../lib/build-mips-product/libutils.a clang version 7.0.0 (trunk 328723) Target: mips--linux-uclibc Thread model: posix InstalledDir: /home/milkweed/build-clang/bin "/home/mdalpee/build-clang/bin/clang-7.0" -cc1 -triple mips--linux-uclibc -emit-obj -mrelax-all -disable-free -main-file-name png.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu mips32r2 -target-feature -noabicalls -target-abi o32 -mfloat-abi hard -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /home/mdalpee/build-clang/lib/clang/7.0.0 -I /home/mdalpee/checkouts/clang/source/src/program/include -isysroot /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr -internal-isystem /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/usr/local/include -internal-isystem /home/mdalpee/build-clang/lib/clang/7.0.0/include -internal-externc-isystem /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/include -internal-externc-isystem /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/usr/include -fdebug-compilation-dir /home/mdalpee/checkouts/clang/source/src/program/png -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fdiagnostics-show-option -o /tmp/png-b34eab.o -x c png.c clang -cc1 version 7.0.0 based upon LLVM 7.0.0svn default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/usr/local/include" ignoring nonexistent directory "/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/usr/include" #include "..." search starts here: #include <...> search starts here: /home/mdalpee/checkouts/clang/source/src/program/include /home/mdalpee/build-clang/lib/clang/7.0.0/include /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/include End of search list. "/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/bin/mips-linux-uclibc-ld" --sysroot=/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr -z relro --sysroot=/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr --eh-frame-hdr -m elf32btsmip -dynamic-linker /lib/ld.so.1 -o build-mips-product/test-png /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/lib/../lib/crt1.o /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/lib/../lib/crti.o crtbegin.o -L/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/lib/../lib -L/home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/lib /tmp/test_png-2da555.o /tmp/png-b34eab.o ../lib/build-mips-product/libutils.a -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/lib/../lib/crtn.o /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/bin/mips-linux-uclibc-ld: cannot find crtbegin.o: No such file or directory /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/bin/mips-linux-uclibc-ld: cannot find -lgcc /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/bin/mips-linux-uclibc-ld: cannot find -lgcc_s /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/bin/mips-linux-uclibc-ld: cannot find /lib/libc.so.0 inside /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/bin/mips-linux-uclibc-ld: cannot find /usr/lib/uclibc_nonshared.a inside /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr/bin/mips-linux-uclibc-ld: cannot find /lib/ld-uClibc.so.0 inside /home/mdalpee/buildroot-2009.05/build_mips/staging_dir/usr clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation) make[4]: *** [build-mips-product/test-png] Error 1 make[3]: *** [png] Error 2 Any guidance about how to best create the gcc toolchain (particularly how to properly build gcc to use uclibc instead of glibc) would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180411/94f0e862/attachment.html>
Simon Atanasyan via llvm-dev
2018-Apr-12 11:27 UTC
[llvm-dev] Building an LLVM/CLANG cross compiler for legacy GCC toolchain
Hello, On Wed, Apr 11, 2018 at 10:41 PM, Michael Dalpee via llvm-dev <llvm-dev at lists.llvm.org> wrote:> I need to build a CLANG cross compiler for mips-linux-uclibc. To be > completely compatible with the target system, I would like it to use linux > 2.6.32.54 headers, binutils 2.25, gcc 4.1.2, and uClibc 0.9.30.1 for the gcc > toolchain. I have been able to build the GCC toolchain a variety of > different ways, but none of these builds can be "dropped in" via clang as a > replacement for just using the gcc toolchain directly. I am building the > toolchain on ubuntu 14.04 using gcc 4.8.4.The "MTI GNU/Linux Toolchain" [1] includes uclibc library support and its directories hierarchy recognized by the Clang compiler. For example, the following command produces an executable file linked with uclibc: clang -target mips-linux-mti-gnu -gcc-toolchain ~/2017.10-05 -muclibc main.c You might use this toolchain as a reference. [1] https://codescape.mips.com/components/toolchain/2017.10-05/downloads.html -- Simon Atanasyan