* * *

Author Topic: Crosscompiling x86_64 > i386 does not uses /usr/lib32  (Read 11292 times)

Ocye

  • Sr. Member
  • ****
  • Posts: 421
    • Scrabble3D
Crosscompiling x86_64 > i386 does not uses /usr/lib32
« on: December 18, 2011, 01:38:35 pm »
I switched recently from Ubunto to Arch Linux. All works fine except crosscompiling for 32bit. E.g. Lazarus tells me
Quote
/usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread
Quote from: ls /usr/lib32/libpthread*
/usr/lib32/libpthread.a  /usr/lib32/libpthread_nonshared.a  /usr/lib32/libpthread.so

When I run "fpc -Pi386 -vt bogus" it seems to be okay
Quote
   
Configfile search: /home/<name>/.fpc.cfg
Reading options from file /home/<name>/.fpc.cfg
Free Pascal Compiler version 2.7.1 [2011/10/02] for i386
Copyright (c) 1993-2011 by Florian Klaempfl and others
Searching file /lib/ld-linux.so.2... found
Compiler: /usr/local/lib/fpc/2.7.1/ppc386
Target OS: Linux for i386
Using executable path: /usr/local/lib/fpc/2.7.1/
...
Using unit path: /usr/local/lib/fpc/2.7.1/
Using library path: /usr/lib32/
Using library path: /lib32/

My ~/.fpc.cfg contains
Quote
    #ifdef cpux86_64
    -Fl/lib
    -Fl/usr/lib
    #endif
    #ifdef cpui386
    -Xd
    -Fl/lib32
    -Fl/usr/lib32
    #endif
    #ifdef cpuarm
    -Xd
    -Fl/usr/local/arm/libc/usr/lib
    -CaEABI
    -Parm
    -CfSOFT
    -CpARMV5
    #endif

Project settings are:
Quote
-MObjFPC -Scghi -CX -Cirot -O2 -Pi386 -Xs -XX -vewnhib -l -FuSynapse -Fu/usr/local/bin/Lazarus/lcl/units/i386-linux/qt -Fu/usr/local/bin/Lazarus/lcl/units/i386-linux -Fu/usr/local/bin/Lazarus/components/lazutils/lib/i386-linux -Fu/usr/local/bin/Lazarus/packager/units/i386-linux -Fu. -vm5024,5057 -dLCL -dLCLqt
(gtk2 does not work for i386 too)

Multiarch libs are installed, even compiling for arm works. Which setting did I miss?


Lazarus 0.9.31 r33990M FPC 2.7.1 x86_64-linux-qt
Linux version 3.1.5-1-ARCH (tobias@T-POWA-LX) (gcc version 4.6.2 20111125 (prerelease) (GCC) ) #1 SMP PREEMPT Sat Dec 10 14:43:09 CET 2011
Lazarus 1.3 r44896M FPC 2.6.4 x86_64-linux-qt

Andru

  • Full Member
  • ***
  • Posts: 112
    • Homepage
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #1 on: December 18, 2011, 03:56:24 pm »
Quote
/usr/bin/ld: skipping incompatible /usr/lib/libpthread.so when searching for -lpthread
That is fine. What real error do you have? My fpc.cfg contains this:
Code: [Select]
#ifdef cpui386
-Xd
-Fl/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/32
-Fl/usr/lib32
#endif

Ocye

  • Sr. Member
  • ****
  • Posts: 421
    • Scrabble3D
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #2 on: December 18, 2011, 04:17:10 pm »
It's not okay since I want to create a 32bit application. The linker should use /usr/lib32/libpthread instead of /usr/lib/. Of course, I switched to non standard path by -Xd as quoted.
Lazarus 1.3 r44896M FPC 2.6.4 x86_64-linux-qt

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3049
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #3 on: December 18, 2011, 05:43:46 pm »
If you still have problems, bisect the problem by looking at the ppas.sh and link.res files. (generated by using -s)

This allows you to pinpoint if your problem is in FPC (or its configuration), when it contains searchpaths for /usr/lib32,

OR

if it doesn't, it's the linker itself.

Andru

  • Full Member
  • ***
  • Posts: 112
    • Homepage
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #4 on: December 18, 2011, 06:58:15 pm »
Quote
It's not okay since I want to create a 32bit application.
It's ok, because I have the same messages with ZenGL and everything compiles fine with these skipping messages... :)

Ocye

  • Sr. Member
  • ****
  • Posts: 421
    • Scrabble3D
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #5 on: December 18, 2011, 07:25:05 pm »
If you still have problems, bisect the problem by looking at the ppas.sh and link.res files. (generated by using -s)
Quote from: link.res
SEARCH_DIR(/usr/lib32/)
SEARCH_DIR(/lib32/)
SEARCH_DIR(./Synapse/)
SEARCH_DIR(/usr/local/bin/Lazarus/components/opengl/lib/i386-linux/gtk2/)
...
Quote from: ppas.sh
/usr/bin/ld -b elf32-i386 -m elf_i386  -s --dynamic-linker=/lib/ld-linux.so.2    -L. -o Scrabble3D link.res
Quote from: ls -l /lib/ld-linux*
lrwxrwxrwx 1 root root 22  3. Dez 04:06 /lib/ld-linux.so.2 -> ../lib32/ld-linux.so.2
lrwxrwxrwx 1 root root 12  2. Dez 19:29 /lib/ld-linux-x86-64.so.2 -> ld-2.14.1.so
ld -v says GNU ld (GNU Binutils) 2.22.0.20111201

Objects seems to be 32bit.
Quote from: file umessages.o
umessages.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
Quote from: file /lib32/libpthread-2.14.1.so
/lib32/libpthread-2.14.1.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), BuildID[sha1]=0xdaae775adca86bf1f87c0f36a90316624e657417, for GNU/Linux 2.6.27, not stripped

Strange.
« Last Edit: December 18, 2011, 07:28:59 pm by Ocye »
Lazarus 1.3 r44896M FPC 2.6.4 x86_64-linux-qt

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3049
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #6 on: December 18, 2011, 07:35:42 pm »
SEARCH_DIR(/lib32/)

So the problem is clear: LD doesn't properly adapt the default paths if 32-bit mode is chosen.

I already suspected this. I would file a bug with the Linux distribution. Preferably see if you can reproduce it with gcc based code.

Andru

  • Full Member
  • ***
  • Posts: 112
    • Homepage
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #7 on: December 18, 2011, 08:01:14 pm »
Quote
I would file a bug with the Linux distribution.
This is not a bug of ArchLinux. I also use this distro with installed binutils-multilib, gcc-libs-multilib, gcc-multilib and lib32* libraries - everything just works for FreePascal 2.4.4 and fixes_2_6 branch.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3049
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #8 on: December 18, 2011, 08:59:34 pm »
Quote
I would file a bug with the Linux distribution.
This is not a bug of ArchLinux. I also use this distro with installed binutils-multilib, gcc-libs-multilib, gcc-multilib and lib32* libraries - everything just works for FreePascal 2.4.4 and fixes_2_6 branch.

So how do you explain the above then? Not using multilib versions but the stock ones?

Andru

  • Full Member
  • ***
  • Posts: 112
    • Homepage
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #9 on: December 18, 2011, 11:24:07 pm »
Quote
Not using multilib versions but the stock ones?
Multilib one is designed for using in such cases, and available in standard repository. You won't be able to compile anything 32-bit under 64-bit without it, because ArchLinux x86_64 by default is pure x86_64 system.

Ocye

  • Sr. Member
  • ****
  • Posts: 421
    • Scrabble3D
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #10 on: December 19, 2011, 02:31:37 pm »
Code: [Select]
#include <stdio.h>
  int main(void)
  {
    printf("Hello, World\n");
    return 0;
  }

gcc -m32 -o hello hello.c (no error, works)
Quote from: file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, BuildID[sha1]=0x35f957192f312df883c0bd943ce96992e9d286cf, not stripped
Quote from: ldd hello
        linux-gate.so.1 =>  (0xf77c8000)
        libc.so.6 => /lib32/libc.so.6 (0xf7624000)
        /lib32/ld-linux.so.2 (0xf77c9000)

cc -m32 hello.c (no error)
Quote from: file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, BuildID[sha1]=0x35f957192f312df883c0bd943ce96992e9d286cf, not stripped
Quote from: /usr/bin/ld -b elf32-i386 -m elf_i386 -o Hello ./a.out
/usr/bin/ld: error in ./a.out(.eh_frame); no .eh_frame_hdr table will be created.
./Hello: error while loading shared libraries: : cannot open shared object file: No such file or directory
Quote from: file ./Hello
./Hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, BuildID[sha1]=0x35f957192f312df883c0bd943ce96992e9d286cf, not stripped
Quote from: ldd ./Hello
./Hello: error while loading shared libraries: ./Hello: unsupported version 33619 of Verneed record

Is it really a question of ld if gcc works?
Lazarus 1.3 r44896M FPC 2.6.4 x86_64-linux-qt

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3049
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #11 on: December 19, 2011, 04:32:17 pm »

Is it really a question of ld if gcc works?

You see that FPC doesn't pass /usr/lib to LD. Then LD must do it itself. There is no other option.

It might be that gcc passes other parameters (e.g. uses --rpath-link to specify a different prefix, FPC option -Xr passes that to the compiler, but that requires an alternate dir that can be used as root). Parsing the gcc high verbosity output might help you find what it passes.

Anyway, it is all in the dual architecture setup from the distribution, so for more information I would ask on their development list/forum.

Ocye

  • Sr. Member
  • ****
  • Posts: 421
    • Scrabble3D
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #12 on: December 19, 2011, 05:13:48 pm »
"gcc -v ..." prints a lot of information but nothing helpful (for me). For those who are interested: I posted the question in the Arch forum: https://bbs.archlinux.org/viewtopic.php?pid=1030127#p1030127

Thanks, marcov and Andru.
Lazarus 1.3 r44896M FPC 2.6.4 x86_64-linux-qt

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3049
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #13 on: December 21, 2011, 03:12:09 pm »
Please post the -v output somewhere. (output when compiling a 32-bit app of course)

Ocye

  • Sr. Member
  • ****
  • Posts: 421
    • Scrabble3D
Re: Crosscompiling x86_64 > i386 does not uses /usr/lib32
« Reply #14 on: December 21, 2011, 03:25:39 pm »
gcc -m32 -v test.c
Quote
gcc -m32 -v test.c
Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/lto-wrapper
Ziel: x86_64-unknown-linux-gnu
Konfiguriert mit: /build/src/gcc-4.6-20111125/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --enable-multilib --disable-libssp --disable-libstdcxx-pch --enable-checking=release --with-fpmath=sse
Thread-Modell: posix
gcc-Version 4.6.2 20111125 (prerelease) (GCC)
COLLECT_GCC_OPTIONS='-m32' '-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/cc1 -quiet -v -imultilib 32 test.c -quiet -dumpbase test.c -m32 -mtune=generic -march=x86-64 -auxbase test -version -o /tmp/ccdwHAIO.s
GNU C (GCC) Version 4.6.2 20111125 (prerelease) (x86_64-unknown-linux-gnu)
        kompiliert von GNU-C-Version 4.6.2 20111125 (prerelease), GMP-Version 5.0.2, MPFR-Version 3.1.0-p3, MPC-Version 0.9.
GGC-Heuristik: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
nicht vorhandenes Verzeichnis »/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../x86_64-unknown-linux-gnu/include« wird ignoriert
#include "..." - Suche beginnt hier:
#include <...> - Suche beginnt hier:
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/include
 /usr/local/include
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/include-fixed
 /usr/include
Ende der Suchliste.
GNU C (GCC) Version 4.6.2 20111125 (prerelease) (x86_64-unknown-linux-gnu)
        kompiliert von GNU-C-Version 4.6.2 20111125 (prerelease), GMP-Version 5.0.2, MPFR-Version 3.1.0-p3, MPC-Version 0.9.
GGC-Heuristik: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: a255f0a427d446be89ce347a664e79ea
COLLECT_GCC_OPTIONS='-m32' '-v' '-mtune=generic' '-march=x86-64'
 as --32 -o /tmp/ccbSZcJm.o /tmp/ccdwHAIO.s
COMPILER_PATH=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/32/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../lib32/:/lib/../lib32/:/usr/lib/../lib32/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-m32' '-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/collect2 --build-id --eh-frame-hdr -m elf_i386 --hash-style=both -dynamic-linker /lib32/ld-linux.so.2 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../lib32/crt1.o /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../lib32/crti.o /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/32/crtbegin.o -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/32 -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../lib32 -L/lib/../lib32 -L/usr/lib/../lib32 -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2 -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../.. /tmp/ccbSZcJm.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/32/crtend.o /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../lib32/crtn.o
Lazarus 1.3 r44896M FPC 2.6.4 x86_64-linux-qt

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus