llvm / llvm-project

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

-m32 fails to work on openSUSE #12480

Closed ismail closed 2 years ago

ismail commented 12 years ago
Bugzilla Link 12108
Version trunk
OS Linux
CC @arichardson,@chandlerc,@zmodem

Extended Description

[/havana/down]> cat foo.c int main() { }

[/havana/down]> clang -m32 foo.c /usr/bin/ld: skipping incompatible /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../libc.so when searching for -lc /usr/bin/ld: i386:x86-64 architecture of input file /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crt1.o' is incompatible with i386 output /usr/bin/ld: i386:x86-64 architecture of input file/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crti.o' is incompatible with i386 output /usr/bin/ld: i386:x86-64 architecture of input file `/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crtn.o' is incompatible with i386 output /usr/bin/ld: /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crti.o: file class ELFCLASS64 incompatible with ELFCLASS32 /usr/bin/ld: final link failed: File in wrong format clang: error: linker command failed with exit code 1 (use -v to see invocation)

[/havana/down]> clang -v -m32 foo.c SUSE Linux clang version 3.1 (trunk 151521) (based on LLVM 3.1svn) Target: i386-unknown-linux-gnu Thread model: posix "/usr/bin/clang" -cc1 -triple i386-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name foo.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib64/clang/3.1 -fmodule-cache-path /tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/clang/3.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /havana/down -ferror-limit 19 -fmessage-length 239 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/foo-kWpaX7.o -x c foo.c clang -cc1 version 3.1 based upon LLVM 3.1svn default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include"

include "..." search starts here:

include <...> search starts here:

/usr/local/include /usr/bin/../lib64/clang/3.1/include /usr/include End of search list. "/usr/bin/ld" -z relro --hash-style=gnu --hash-style=both --build-id --enable-new-dtags --eh-frame-hdr -m elf_i386 -dynamic-linker /lib64/ld-linux.so.2 -o a.out /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crt1.o /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crti.o /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/32/crtbegin.o -L/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/32 -L/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6 -L/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib -L/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../.. -L/lib -L/usr/lib /tmp/foo-kWpaX7.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/32/crtend.o /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crtn.o /usr/bin/ld: skipping incompatible /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../libc.so when searching for -lc /usr/bin/ld: i386:x86-64 architecture of input file /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crt1.o' is incompatible with i386 output /usr/bin/ld: i386:x86-64 architecture of input file/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crti.o' is incompatible with i386 output /usr/bin/ld: i386:x86-64 architecture of input file `/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crtn.o' is incompatible with i386 output /usr/bin/ld: /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crti.o: file class ELFCLASS64 incompatible with ELFCLASS32 /usr/bin/ld: final link failed: File in wrong format clang: error: linker command failed with exit code 1 (use -v to see invocation)

Location for various files:

[/havana/]> find /usr -name crt1.o /usr/lib64/crt1.o /usr/lib/crt1.o

[/havana/]> find /usr -name crtbegin.o /usr/lib64/gcc/x86_64-suse-linux/4.6/32/crtbegin.o /usr/lib64/gcc/x86_64-suse-linux/4.6/crtbegin.o

gcc run:

[/havana/down]> gcc -v -m32 foo.c Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.6/lto-wrapper Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.6 --enable-ssp --disable-libssp --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --enable-linker-build-id --program-suffix=-4.6 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux Thread model: posix gcc version 4.6.2 20111212 [gcc-4_6-branch revision 182222] (SUSE Linux) COLLECT_GCC_OPTIONS='-v' '-m32' '-mtune=generic' '-march=i586' /usr/lib64/gcc/x86_64-suse-linux/4.6/cc1 -quiet -v -imultilib 32 foo.c -quiet -dumpbase foo.c -m32 -mtune=generic -march=i586 -auxbase foo -version -o /tmp/ccwiVw38.s GNU C (SUSE Linux) version 4.6.2 20111212 [gcc-4_6-branch revision 182222] (x86_64-suse-linux) compiled by GNU C version 4.6.2 20111212 [gcc-4_6-branch revision 182222], GMP version 5.0.3, MPFR version 3.1.0-p1, MPC version 0.8.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

include "..." search starts here:

include <...> search starts here:

/usr/lib64/gcc/x86_64-suse-linux/4.6/include /usr/local/include /usr/lib64/gcc/x86_64-suse-linux/4.6/include-fixed /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/include /usr/include End of search list. GNU C (SUSE Linux) version 4.6.2 20111212 [gcc-4_6-branch revision 182222] (x86_64-suse-linux) compiled by GNU C version 4.6.2 20111212 [gcc-4_6-branch revision 182222], GMP version 5.0.3, MPFR version 3.1.0-p1, MPC version 0.8.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 57555659ed6d758aaf0edb2be09471b2 COLLECT_GCC_OPTIONS='-v' '-m32' '-mtune=generic' '-march=i586' /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/as --32 -o /tmp/ccataEWT.o /tmp/ccwiVw38.s COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/ LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/4.6/32/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib/../lib/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib64/gcc/x86_64-suse-linux/4.6/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-m32' '-mtune=generic' '-march=i586' /usr/lib64/gcc/x86_64-suse-linux/4.6/collect2 --build-id --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.6/32/crtbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/4.6/32 -L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib/../lib -L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib64/gcc/x86_64-suse-linux/4.6 -L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../.. /tmp/ccataEWT.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.6/32/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib/crtn.o

[/havana/down]> gcc -### Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.6/lto-wrapper Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.6 --enable-ssp --disable-libssp --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --enable-linker-build-id --program-suffix=-4.6 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux Thread model: posix gcc version 4.6.2 20111212 [gcc-4_6-branch revision 182222] (SUSE Linux)

chandlerc commented 10 years ago

FWIW, I don't have time to fully dig into this, but here is the beginnings of how I suspect this should be fixed:

% git diff diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 9ea21b4..16991de 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -3088,7 +3088,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) // // Note that this matches the GCC behavior. See the below comment for where // Clang diverges from GCC's behavior.

@@ -3103,7 +3103,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) // a bug. if (StringRef(LibPath).startswith(SysRoot)) { addPathIfExists(LibPath + "/" + MultiarchTriple, Paths);

If you apply this, you'll find a couple of 32-bit generic multilib driver tests fail and some mips tests fail.

The generic multilib test failures all seem to stem from the GCC installation detector's multilib suffix missing a '32' in cases where a 32-bit targeting GCC is installed into usr/lib/ rather than usr/lib32... at least I think. Maybe some other reason. Once the GCC installation detector creates a Multilib object with th ecorrect '32' suffix, those tests will pass again.

The MIPS test I don't understand at all. IT might be the same as above, but the mips multilib stuff is about 10x more complex than the rest and is tho cause of a lot of the confusing stuff so I can't make heads or tails of it.

Maybe this will help someone figure out enoguh to propose a complete fix.

ismail commented 10 years ago

On a recent clang:

clang version 3.6.0 (trunk 216444) Target: i386-suse-linux Thread model: posix Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/4.8 Selected GCC installation: /usr/lib64/gcc/x86_64-suse-linux/4.8 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: 32;@m32 "/opt/clang/bin/clang-3.6" -cc1 -triple i386-suse-linux -emit-obj -mrelax-all -disable-free -main-file-name active.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu pentium4 -v -dwarf-column-info -resource-dir /opt/clang/bin/../lib64/clang/3.6.0 -internal-isystem /usr/local/include -internal-isystem /opt/clang/bin/../lib64/clang/3.6.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/ismail -ferror-limit 19 -fmessage-length 120 -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/active-49f249.o -x c active.c clang -cc1 version 3.6.0 based upon LLVM 3.6.0svn default target x86_64-suse-linux ignoring nonexistent directory "/include"

include "..." search starts here:

include <...> search starts here:

/usr/local/include /opt/clang/bin/../lib64/clang/3.6.0/include /usr/include End of search list. "/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld" -z relro --hash-style=gnu --hash-style=both --build-id --enable-new-dtags --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../crti.o /usr/lib64/gcc/x86_64-suse-linux/4.8/32/crtbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/4.8/32 -L/usr/lib64/gcc/x86_64-suse-linux/4.8 -L/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.8/../../.. -L/lib -L/usr/lib /tmp/active-49f249.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.8/32/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../crtn.o /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../libc.so when searching for -lc /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: i386:x86-64 architecture of input file /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../crt1.o' is incompatible with i386 output /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: i386:x86-64 architecture of input file/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../crti.o' is incompatible with i386 output /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: i386:x86-64 architecture of input file `/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../crtn.o' is incompatible with i386 output /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../crt1.o: file class ELFCLASS64 incompatible with ELFCLASS32 /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: final link failed: File in wrong format clang-3.6: error: linker command failed with exit code 1 (use -v to see invocation)

The correct location for the files is

/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib/crti.o

(added one ../lib/ at the end)

which actually simplifies to

/usr/lib/crti.o

and actually

[~]> file /usr/lib/crt*.o /usr/lib/crt1.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), for GNU/Linux 3.0.0, not stripped /usr/lib/crti.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped /usr/lib/crtn.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped

on 64bit openSUSE.

ismail commented 10 years ago

Sorry, you are right. I haven't tested to run the binary... it calls the linker with /lib64/ld-linux.so.2 and that is wrong.

This was a bug in our build scripts. This should be fixed in openSUSE 13.2

llvmbot commented 11 years ago

Sorry, you are right. I haven't tested to run the binary... it calls the linker with /lib64/ld-linux.so.2 and that is wrong.

it solved my problem, because I just want to see compiler warnings using clang (normal build process uses g++).

One could write a wrapper around ld that replaces /lib64/ld-linux.so.2 with /lib/ld-linux.so.2 if the arguments contains -m elf_i386.

llvmbot commented 11 years ago

I tried the workaround with gcc 4.7 (shipped with OpenSuSE 12.3) and while linking worked, I cannot execute the resulting binaries. I get the error "No such file or directory", the same when I do ldd . strings shows /lib64/ld-linux.so.2 as first string, this should be /lib/ld-linux.so.2. Does the workaround produce working binaries for you?

llvmbot commented 11 years ago

I don't think so.

And I still get warnings for other libs, but only warnings, no errors:

/usr/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../libdl.so when searching for -ldl /usr/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../librt.so when searching for -lrt /usr/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../libm.so when searching for -lm /usr/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../libpthread.so when searching for -lpthread /usr/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../libc.so when searching for -lc

llvmbot commented 11 years ago

Workaround (openSuSE 12.3, clang 3.3 branches/release_33 183898, gcc 4.8):

cd /usr/lib64/gcc/x86_64-suse-linux/4.8/32 ln -s /usr/lib/crt1.o ln -s /usr/lib/crti.o ln -s /usr/lib/crtn.o

Are there any downsides to this workaround?

llvmbot commented 11 years ago

Workaround (openSuSE 12.3, clang 3.3 branches/release_33 183898, gcc 4.8):

cd /usr/lib64/gcc/x86_64-suse-linux/4.8/32 ln -s /usr/lib/crt1.o ln -s /usr/lib/crti.o ln -s /usr/lib/crtn.o

llvmbot commented 11 years ago

I can confirm with OpenSuSE 12.3 and their shipped clang (clang version 3.2 (branches/release_32 170558))

llvmbot commented 11 years ago

I'm seeing the same issue with openSUSE 12.3, using clang 3.3 (183898).

llvmbot commented 11 years ago

please ignore my last comment, does not work, sorry.

llvmbot commented 11 years ago

please ignore my last comment, does not work, sorry.

llvmbot commented 11 years ago

Workaround: create a symbolic link to /usr/lib64 as /usr/lib/amd64:

cd /usr/lib ; ln -s ../lib64 amd64

llvmbot commented 11 years ago

I can confirm that clang 3.2 and clang HEAD both don't work with -m32 on openSUSE 12.1 while -m32 works just fine on Ubuntu 12.04.

arichardson commented 12 years ago

I can confirm this runnning openSuSE 12.1 The crt* files exist in the right architecture in /usr/lib I also added -L/usr/lib but that doesn't help.

/usr/bin/ld: i386:x86-64 architecture of input file /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crt1.o' is incompatible with i386 output /usr/bin/ld: i386:x86-64 architecture of input file/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crti.o' is incompatible with i386 output /usr/bin/ld: i386:x86-64 architecture of input file `/usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crtn.o' is incompatible with i386 output /usr/bin/ld: /usr/bin/../lib64/gcc/x86_64-suse-linux/4.6/../../../crti.o: file class ELFCLASS64 incompatible with ELFCLASS32 /usr/bin/ld: final link failed: File in wrong format

EugeneZelenko commented 2 years ago

@ismail" Could you please elaborate on reason(s) and also add relevant label(s)?