choosing the gcc toolchain

I built a Mips llvm for one of our target machines.
When I run it there it unfortunately chooses the wrong gcc toolchain.
4.7.2 is what I want it to choose.

Can this be overriden?

Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6.3
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7.2
Selected GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6

Tia.

Reed

Weird, the code is supposed to select 4.7 there… lemme check why it would do this.

At the same command line:

rkotler@mipsswbrd006-le:~/caviumllvmwclang/build$ gcc --version
gcc (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My best guess is that the multilib stuff wasn’t setup correctly. Note that MIPS has custom logic for this (findMIPSMultilibs). If that fails, then we’ll not use the newer GCC installation. You could add logging there to try and figure out why.

Okay.

The clang is working ok. I can compile, link and run a program in a simple fashion.

I will take a look.

Thanks.

Reed

It looks like a regression after r201205. The problem is in the end of
the findMIPSMultilibs routine in the following line:

[[
else if (DebianMipsMultilibs.size() == 3) {
]]

The clang driver does not select a regular Debian MIPS toolchain if
the toolchain includes 32-bit libraries only and does not include 64
and n32 variants.

If temporarily delete FSF and CS toolchain selection it solves the
problem at least on my x86-64 Debian machines with a regular MIPS 4.7
toolchain.

[[
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -1802,13 +1802,10 @@ bool
Generic_GCC::GCCInstallationDetector::findMIPSMultilibs(
   // a bit of overlap in the directories that each specifies)
   if (TargetTriple.getEnvironment() == llvm::Triple::Android)
     Multilibs.combineWith(AndroidMipsMultilibs);
- else if (DebianMipsMultilibs.size() == 3) {
+ else {
     Multilibs.combineWith(DebianMipsMultilibs);
     BiarchSibling = Multilib();
- } else if (FSFMipsMultilibs.size() > CSMipsMultilibs.size())
- Multilibs.combineWith(FSFMipsMultilibs);
- else
- Multilibs.combineWith(CSMipsMultilibs);
+ }

   llvm::Triple::ArchType TargetArch = TargetTriple.getArch();

]]

Reed, could you check this hack on the cavium board?

I will try to fix this bug.

The clang is working ok. I can compile, link and run a program in a simple
fashion.

I will take a look.

[...]

Seems to almost work.
It should have picked up 4.7.2 I would think.

rkotler@mipsswbrd006-le:~/caviumllvmwclang/install/bin$ ./clang -v
clang version 3.5 (gitosis@dmz-portal.mips.com:clang.git 42303467cd4adb0dbcbead5517482265ea111bfa) (gitosis@dmz-portal.mips.com:llvm.git 0ff25b31d895c82d3fea67b76531c9580ce00d0a)
Target: mipsel-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6.3
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7.2
Selected GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7
Candidate multilib: .;@m32
Selected multilib: .;@m32

I do a diff in my area and pick up some other changes that look like formatting changes from my clang. Not sure why.

I only made the change you suggested.

(Attachment 1536.txt is missing)

Reed,

Which multilib folders do your 4.7.2, 4.7, and 4.6 gcc installations each have respectively?

Jon

The problem seems to be clear. By default Debian MIPS toolchain 4.7
has libraries for o32 ABI only. In that case sizes of
DebianMipsMultilibs, CSMipsMultilibs and FSFMipsMultilibs are equal to
1. So in the following code we always incorrectly select CS Toolchain:

[[
  if (TargetTriple.getEnvironment() == llvm::Triple::Android)
    Multilibs.combineWith(AndroidMipsMultilibs);
  else if (DebianMipsMultilibs.size() == 3) {
    Multilibs.combineWith(DebianMipsMultilibs);
    BiarchSibling = Multilib();
  } else if (FSFMipsMultilibs.size() > CSMipsMultilibs.size())
    Multilibs.combineWith(FSFMipsMultilibs);
  else
    Multilibs.combineWith(CSMipsMultilibs);
]]

Seems to almost work.

[...]

So what do you propose?

Here is the fix:
http://llvm-reviews.chandlerc.com/D2911

I will try this patch tonight.

I will try the new patch tonight.

The one the night before had some new errors but it was still not chosing the right toolchain as we know.

The good news is that with clang/llvm we eliminated the errors:
     LLVM-Unit :: ADT/Release+Asserts/ADTTests/HashingTest.HashCombineBasicTest
     LLVM-Unit :: ADT/Release+Asserts/ADTTests/HashingTest.HashValueStdPair

In particular, check mips-cs.cpp and mips-fs.cpp.

When built with gcc 4.7:

Failing Tests (11):
     Clang :: Analysis/crash-trace.c
     Clang :: Driver/mips-cs.cpp
     Clang :: Driver/mips-fsf.cpp
     Clang :: Parser/crash-report.c
     LLVM :: CodeGen/Generic/2009-03-17-LSR-APInt.ll
     LLVM :: CodeGen/Generic/2011-07-07-ScheduleDAGCrash.ll
     LLVM :: CodeGen/Generic/add-with-overflow-128.ll
     LLVM :: CodeGen/Generic/i128-addsub.ll
     LLVM :: DebugInfo/2010-10-01-crash.ll
     LLVM-Unit :: ADT/Release+Asserts/ADTTests/HashingTest.HashCombineBasicTest
     LLVM-Unit :: ADT/Release+Asserts/ADTTests/HashingTest.HashValueStdPair

   Expected Passes : 16716
   Expected Failures : 90
   Unsupported Tests : 41
   Unexpected Failures: 11
make[1]: *** [check-local-all] Error 1
make[1]: Leaving directory `/home/rkotler/caviumnativellvm/build/test'
make: *** [check-all] Error 2
rkotler@mipsswbrd006-le:~/caviumnativellvm/build$

When built with recent clang/llvm:

Failing Tests (9):
     Clang :: Analysis/crash-trace.c
     Clang :: Driver/mips-cs.cpp
     Clang :: Driver/mips-fsf.cpp
     Clang :: Parser/crash-report.c
     LLVM :: CodeGen/Generic/2009-03-17-LSR-APInt.ll
     LLVM :: CodeGen/Generic/2011-07-07-ScheduleDAGCrash.ll
     LLVM :: CodeGen/Generic/add-with-overflow-128.ll
     LLVM :: CodeGen/Generic/i128-addsub.ll
     LLVM :: DebugInfo/2010-10-01-crash.ll

I've been testing this part on little endian and there are currently some additional "make check" issues on little endian no present on big endian.

The little endian native compiler without your patch gets:

With this latest patch I'm seeing:

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$ ./Release+Asserts/bin/clang++ -v
clang version 3.5 (gitosis@dmz-portal.mips.com:clang.git f4481e0e412e3f817e65d5ce1c835381dc7a7773) (gitosis@dmz-portal.mips.com:llvm.git 18fe44cb057e4b11533bd3f814b96fdca724baf0)
Target: mips64el-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6.3
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7.2
Selected GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6
Candidate multilib: .;@m32
Candidate multilib: 64;@m64
Candidate multilib: n32;@mabi=n32
Selected multilib: 64;@m64
rkotler@mipsswbrd006-le:~/caviumnativellvm/build$

The day before I was getting 4.7

Hi Reed,

Could you:
1. Send the command line options used to run the clang
2. Run the following command and send its output:
$ find /usr/lib -name crtbegin.o

Thanks.

And one a couple of questions more. When you check the first patch the
target triple was mipsel-unknown-linux-gnu. When you check the last
patch the target triple is mips64el-unknown-linux-gnu. Do you use the
same clang command line options both time? Does the 4.7.2 toolchain
contain 64-bit support?

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$ ./Release+Asserts/bin/clang++ -v
clang version 3.5 (gitosis@dmz-portal.mips.com:clang.git f4481e0e412e3f817e65d5ce1c835381dc7a7773) (gitosis@dmz-portal.mips.com:llvm.git 18fe44cb057e4b11533bd3f814b96fdca724baf0)
Target: mips64el-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6.3
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7.2
Selected GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6
Candidate multilib: .;@m32
Candidate multilib: 64;@m64
Candidate multilib: n32;@mabi=n32
Selected multilib: 64;@m64
rkotler@mipsswbrd006-le:~/caviumnativellvm/build$

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$ find /usr/lib -name crtbegin.o
/usr/lib/gcc/mipsel-linux-gnu/4.7/crtbegin.o
/usr/lib/gcc/mipsel-linux-gnu/4.6/64/crtbegin.o
/usr/lib/gcc/mipsel-linux-gnu/4.6/n32/crtbegin.o
/usr/lib/gcc/mipsel-linux-gnu/4.6/crtbegin.o
/usr/lib/gcc/mipsel-linux-gnu/4.4/crtbegin.o
rkotler@mipsswbrd006-le:~/caviumnativellvm/build$

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$ which gcc
/usr/bin/gcc

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$ gcc --version -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/mipsel-linux-gnu/4.7/lto-wrapper
gcc (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Target: mipsel-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --enable-plugin --with-mips-plt --with-arch-32=mips2 --with-tune-32=mips32 --enable-targets=all --with-arch-64=mips3 --with-tune-64=mips64 --enable-checking=release --build=mipsel-linux-gnu --host=mipsel-linux-gnu --target=mipsel-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
COLLECT_GCC_OPTIONS='--version' '-v' '-march=mips2' '-mtune=mips32' '-mllsc' '-mplt' '-mno-synci' '-mno-shared' '-EL' '-mabi=32'
  /usr/lib/gcc/mipsel-linux-gnu/4.7/cc1 -quiet -v -imultiarch mipsel-linux-gnu help-dummy -mel -quiet -dumpbase help-dummy -march=mips2 -mtune=mips32 -mllsc -mplt -mno-synci -mno-shared -mabi=32 -auxbase help-dummy -version --version -o /tmp/ccMqrJTq.s
GNU C (Debian 4.7.2-5) version 4.7.2 (mipsel-linux-gnu)
     compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='--version' '-v' '-march=mips2' '-mtune=mips32' '-mllsc' '-mplt' '-mno-synci' '-mno-shared' '-EL' '-mabi=32'
  as -v -EL -O1 -no-mdebug -mabi=32 -march=mips2 -mno-shared -mtune=mips32 -mfix-loongson2f-nop -call_nonpic --version -o /tmp/cc4RqYZu.o /tmp/ccMqrJTq.s
GNU assembler version 2.22 (mipsel-linux-gnu) using BFD version (GNU Binutils for Debian) 2.22
GNU assembler (GNU Binutils for Debian) 2.22
Copyright 2011 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `mipsel-linux-gnu'.
COMPILER_PATH=/usr/lib/gcc/mipsel-linux-gnu/4.7/:/usr/lib/gcc/mipsel-linux-gnu/4.7/:/usr/lib/gcc/mipsel-linux-gnu/:/usr/lib/gcc/mipsel-linux-gnu/4.7/:/usr/lib/gcc/mipsel-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/mipsel-linux-gnu/4.7/:/usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu/:/usr/lib/gcc/mipsel-linux-gnu/4.7/../../../../lib/:/lib/mipsel-linux-gnu/:/lib/../lib/:/usr/lib/mipsel-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/mipsel-linux-gnu/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='--version' '-v' '-march=mips2' '-mtune=mips32' '-mllsc' '-mplt' '-mno-synci' '-mno-shared' '-EL' '-mabi=32'
  /usr/lib/gcc/mipsel-linux-gnu/4.7/collect2 --sysroot=/ --build-id --no-add-needed --eh-frame-hdr -EL -EL -dynamic-linker /lib/ld.so.1 -melf32ltsmip --version /usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu/crt1.o /usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu/crti.o /usr/lib/gcc/mipsel-linux-gnu/4.7/crtbegin.o -L/usr/lib/gcc/mipsel-linux-gnu/4.7 -L/usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu -L/usr/lib/gcc/mipsel-linux-gnu/4.7/../../../../lib -L/lib/mipsel-linux-gnu -L/lib/../lib -L/usr/lib/mipsel-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/mipsel-linux-gnu/4.7/../../.. /tmp/cc4RqYZu.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/mipsel-linux-gnu/4.7/crtend.o /usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu/crtn.o
collect2 version 4.7.2
/usr/bin/ld --sysroot=/ --build-id --no-add-needed --eh-frame-hdr -EL -EL -dynamic-linker /lib/ld.so.1 -melf32ltsmip --version /usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu/crt1.o /usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu/crti.o /usr/lib/gcc/mipsel-linux-gnu/4.7/crtbegin.o -L/usr/lib/gcc/mipsel-linux-gnu/4.7 -L/usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu -L/usr/lib/gcc/mipsel-linux-gnu/4.7/../../../../lib -L/lib/mipsel-linux-gnu -L/lib/../lib -L/usr/lib/mipsel-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/mipsel-linux-gnu/4.7/../../.. /tmp/cc4RqYZu.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/mipsel-linux-gnu/4.7/crtend.o /usr/lib/gcc/mipsel-linux-gnu/4.7/../../../mipsel-linux-gnu/crtn.o
GNU ld (GNU Binutils for Debian) 2.22
Copyright 2011 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
rkotler@mipsswbrd006-le:~/caviumnativellvm/build$

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$
./Release+Asserts/bin/clang++ -v
clang version 3.5 (gitosis@dmz-portal.mips.com:clang.git
f4481e0e412e3f817e65d5ce1c835381dc7a7773)
(gitosis@dmz-portal.mips.com:llvm.git
18fe44cb057e4b11533bd3f814b96fdca724baf0)
Target: mips64el-unknown-linux-gnu

[...]

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$ find /usr/lib -name
crtbegin.o
/usr/lib/gcc/mipsel-linux-gnu/4.7/crtbegin.o
/usr/lib/gcc/mipsel-linux-gnu/4.6/64/crtbegin.o

That is why the clang selects toolchain version 4.6. You provide
"mips64el-unknown-linux-gnu" triple but toolchain version 4.7 does not
support 64 ABI. So the clang fall back to the 4.6.

The first time you provide "mipsel-unknown-linux-gnu" triple and the
fixed clang successfully selects toolchain version 4.7.

Is this because of the recent change to make mips64 be the default?

rkotler@mipsswbrd006-le:~/caviumnativellvm/build$ ./Release+Asserts/bin/clang++ -v -target mipsel-unknown-linux-gnu
clang version 3.5 (gitosis@dmz-portal.mips.com:clang.git f4481e0e412e3f817e65d5ce1c835381dc7a7773) (gitosis@dmz-portal.mips.com:llvm.git 18fe44cb057e4b11533bd3f814b96fdca724baf0)
Target: mipsel-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.6.3
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7.2
Selected GCC installation: /usr/lib/gcc/mipsel-linux-gnu/4.7
Candidate multilib: .;@m32
Selected multilib: .;@m32
rkotler@mipsswbrd006-le:~/caviumnativellvm/build$

But it still does not find 4.7.2

Even with the patch from Friday it found 4.7.