llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.14k stars 12.02k forks source link

linux ppc: clang linking invokes ld for x86_64 rather than ppc #9915

Closed 0e6f8740-1d2a-4afc-85fd-df25c3a603fd closed 13 years ago

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago
Bugzilla Link 9543
Resolution FIXED
Resolved on Apr 06, 2011 19:45
Version trunk
OS Linux

Extended Description

$ /opt/llvm/bin/clang -c test.c

$ file test.o test.o: ELF 32-bit MSB relocatable, PowerPC or cisco 4500, version 1 (SYSV), not stripped

$ /opt/llvm/bin/clang test.o -o test /usr/bin/ld: unrecognised emulation mode: elf_x86_64 Supported emulations: elf32ppclinux elf32ppc elf32ppcsim elf64ppc elf32_spu clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ /opt/llvm/bin/clang --version clang version 3.0 (trunk 128223) Target: powerpc-unknown-linux-gnu Thread model: posix

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

r128944

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

[Support linking for Ubuntu Natty/ppc Gentoo/ppc and Gentoohttps://user-images.githubusercontent.com/92601458/143742909-11cfd3c8-5f33-48c6-99de-7afb4c480bbc.gz) Updated tuple detection for Gentoo/ppc based on current stage3 tarball

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

That patch finds tuples from Ubuntu/ppc and Gentoo/ppc64 (the only two I have access to at the moment). I can update it for Fedora/ppc and Gentoo/ppc in a week or so, but I'd rather get this in first and provide a smaller patch for those distros later.

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

[Linking support for Ubuntu Nattyhttps://user-images.githubusercontent.com/92601458/143742910-6225fdf3-7754-4c44-86c8-18b1252ea013.gz)

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

[Linking support for Ubuntu Nattyhttps://user-images.githubusercontent.com/92601458/143742911-4f943bc2-cfd4-4ded-bef3-5ac669469130.gz)

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

The patch above fixes the reported problem, but I'm still unable to link due to missing data from ToolChain.getFilePaths();

$ clang -v -o test test.o clang version 3.0 (trunk 128223) Target: powerpc-unknown-linux-gnu Thread model: posix "/usr/bin/ld" --eh-frame-hdr -m elf32ppclinux -dynamic-linker /lib/ld.so -o test crt1.o crti.o crtbegin.o -L -L/../../.. test.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o /usr/bin/ld: cannot find crt1.o: No such file or directory /usr/bin/ld: cannot find crti.o: No such file or directory /usr/bin/ld: cannot find crtbegin.o: No such file or directory /usr/bin/ld: cannot find -lgcc /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find -lc /usr/bin/ld: cannot find -lgcc /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find crtend.o: No such file or directory /usr/bin/ld: cannot find crtn.o: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation)


Here are invocations of gcc for -m32 and -m64 on linux/ppc64, so you can see the paths used

$ gcc -v -m64 -o test.64 test.64.o Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/lto-wrapper Target: powerpc-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-6ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=powerpc-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/powerpc-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/powerpc-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --enable-secureplt --disable-softfloat --enable-targets=powerpc-linux,powerpc64-linux --with-cpu=default32 --disable-werror --with-long-double-128 --enable-checking=release --build=powerpc-linux-gnu --host=powerpc-linux-gnu --target=powerpc-linux-gnu Thread model: posix gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-6ubuntu5) COMPILER_PATH=/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/ LIBRARY_PATH=/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/64/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../../../lib64/:/lib/../../lib64/:/usr/lib/../../lib64/:/usr/lib/powerpc-linux-gnu/../../lib64/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../:/lib/:/usr/lib/:/usr/lib/powerpc-linux-gnu/ COLLECT_GCC_OPTIONS='-v' '-m64' '-o' 'test.64' /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/collect2 --build-id --no-add-needed --eh-frame-hdr -V -Qy -m elf64ppc --hash-style=gnu -dynamic-linker /lib64/ld64.so.1 -z relro -o test.64 /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../../../lib64/crt1.o /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../../../lib64/crti.o /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/64/crtbegin.o -L/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/64 -L/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../../../lib64 -L/lib/../../lib64 -L/usr/lib/../../lib64 -L/usr/lib/powerpc-linux-gnu/../../lib64 -L/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2 -L/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../.. -L/usr/lib/powerpc-linux-gnu test.64.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/64/crtend.o /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../../../lib64/crtn.o GNU ld (GNU Binutils for Ubuntu) 2.21.0.20110302 Supported emulations: elf32ppclinux elf32ppc elf32ppcsim elf64ppc elf32_spu

$ gcc -v -o test test.o Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/lto-wrapper Target: powerpc-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-6ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=powerpc-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/powerpc-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/powerpc-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --enable-secureplt --disable-softfloat --enable-targets=powerpc-linux,powerpc64-linux --with-cpu=default32 --disable-werror --with-long-double-128 --enable-checking=release --build=powerpc-linux-gnu --host=powerpc-linux-gnu --target=powerpc-linux-gnu Thread model: posix gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-6ubuntu5) COMPILER_PATH=/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/ LIBRARY_PATH=/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/:/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../:/lib/:/usr/lib/:/usr/lib/powerpc-linux-gnu/ COLLECT_GCC_OPTIONS='-v' '-o' 'test' /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/collect2 --build-id --no-add-needed --eh-frame-hdr -V -Qy -m elf32ppclinux --hash-style=gnu -dynamic-linker /lib/ld.so.1 -z relro -o test /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../crt1.o /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../crti.o /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/crtbegin.o -L/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2 -L/usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../.. -L/usr/lib/powerpc-linux-gnu test.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/crtend.o /usr/lib/powerpc-linux-gnu/gcc/powerpc-linux-gnu/4.5.2/../../../crtn.o GNU ld (GNU Binutils for Ubuntu) 2.21.0.20110302 Supported emulations: elf32ppclinux elf32ppc elf32ppcsim elf64ppc elf32_spu

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

Here's at least a partial fix:

Index: lib/Driver/Tools.cpp

--- lib/Driver/Tools.cpp (revision 128223) +++ lib/Driver/Tools.cpp (working copy) @@ -3631,6 +3631,10 @@ else if (ToolChain.getArch() == llvm::Triple::arm || ToolChain.getArch() == llvm::Triple::thumb) CmdArgs.push_back("armelf_linux_eabi");

@@ -3654,6 +3658,10 @@ else if (ToolChain.getArch() == llvm::Triple::arm || ToolChain.getArch() == llvm::Triple::thumb) CmdArgs.push_back("/lib/ld-linux.so.3");

0e6f8740-1d2a-4afc-85fd-df25c3a603fd commented 13 years ago

$ /opt/llvm/bin/clang test.c -v clang version 3.0 (trunk 128223) Target: powerpc-unknown-linux-gnu Thread model: posix "/opt/llvm/bin/clang" -cc1 -triple powerpc-unknown-linux-gnu -S -disable-free -main-file-name test.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-linker-version 2.21.0.20110302 -momit-leaf-frame-pointer -v -resource-dir /opt/llvm/bin/../lib/clang/3.0 -ferror-limit 19 -fmessage-length 124 -fno-signed-char -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-RLFAdb.s -x c test.c clang -cc1 version 3.0 based upon llvm 3.0svn hosted on powerpc-unknown-linux-gnu

include "..." search starts here:

include <...> search starts here:

/usr/local/include /opt/llvm/bin/../lib/clang/3.0/include /usr/include End of search list. "/usr/bin/as" -o /tmp/cc-IAvLgc.o /tmp/cc-RLFAdb.s "/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out crt1.o crti.o crtbegin.o -L -L/../../.. /tmp/cc-IAvLgc.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o /usr/bin/ld: unrecognised emulation mode: elf_x86_64 Supported emulations: elf32ppclinux elf32ppc elf32ppcsim elf64ppc elf32_spu clang: error: linker command failed with exit code 1 (use -v to see invocation)