This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: x86-64 with lib and lib64


Dan Kegel wrote:
Roman Duka wrote:

Dan Kegel wrote:

Roman Duka wrote:

a silly question, for x86-64 targets we get 2 lib dirs, lib and lib64, does that mean that the SAME toolchain could produce 64 bit and 32 bit binaries?? and if yes how, by using compiler switches or something else?


Yes, with a compiler switch, though I haven't tried it myself.
Note however that you need to compile the C library once for
each architecture.


i'm trying to do it now, i think we need to pass --enable-multilib when configuring cross gcc for x86-64, however it fails with error on gcc-3.3.2, it says something about ld skipping incompatible libraries when linking with -lc etc ??? i've managed to built full x86-64 toolchain, but only with --disable-multilib options. well i'll try a snapshot of gcc-3.4.0, maybe that's different.


for x86_64, I highly recommend gcc-3.3.3 snapshots rather than gcc-3.3.2,
since I had no success until I turned on --with-sysroot, which is new to
gcc-3.3.3 and gcc-3.4.

I don't use --disable-multilib when building my final gcc with gcc-3.3.3, by
the way, so maybe I already have both versions of the startup files; I
haven't checked.
- Dan



i don't think gcc needs --with-sysroot if you have all you cross libraries in your target install directory under lib, lib64 and NOT split into lib and us/lib, lib64 and usr/lib64, only binutils needs --with-sysroot for correct operation (i think). i abandoned my idea of having cross glibc libraris installed unger lib, usr/lib etc, it seems to cause problems, having all glibc libraris under a single lib or lib64 is probably expected by cross gcc, this is what i came to by browsing through gcc.c source file, it creates a different list of default search paths (the ones you get with gcc -print-search-dirs) based on whether it's a corss compiler or not, i.e. if it's a corss compiler, it omits the default /lib, /usr/lib search paths, which i think would work for a cross compiler, provided binutils was compiled with "--with-sysroot=your_target_sysroot", because i think with this setup whenever cross ld is passed "/lib" or "/usr/lib" it would search for those directories relative to "your_target_sysroot".
i was trying to build x86_64 toolchain on my x86 machine, which was capable of producing 32 AND 64 bit binaries, in order to do this you need to enable --enable-multilib for gcc (which is usually enable by default) this will create and extra "32" directory in the gcc libdir, which will contain 32 bin startup files etc. The only trick to achieving this is to copy your 32 bit glibc libraries (which you could find under your systems /lib, /usr/lib) to the 32 bit library directory under your target install directory, i.e. prefix/x86_64-unknown-linux-gnu/lib. You need to copy the 32 bit libraries BEFORE you attempt to compile the final cross gcc, or you'll error message about missing crti.o files and incompatible glibc.so.6 libraries, this is because the final cross gcc needs 32 bit libraries under prefix/x86_64-unknown-linux-gnu/lib (or whatever you prefix/target name is) to compile its 32 bit startup files.


Here is the proof that it works:

roman@athlon1000:~/crosstool/x86_64-unknown/bin> cat size.c
#include <stdio.h>

int main(void) {
        int *int_ptr;
        void *void_ptr;
        int (*funct_ptr)(void);

        printf("sizeof(char):         %d bytes\n", sizeof(char));
        printf("sizeof(short):        %d bytes\n", sizeof(short));
        printf("sizeof(int):          %d bytes\n", sizeof(int));
        printf("sizeof(long):         %d bytes\n", sizeof(long));
        printf("sizeof(long long):    %d bytes\n", sizeof(long long));
        printf("------------------------------\n");
        printf("sizeof(float):        %d bytes\n", sizeof(float));
        printf("sizeof(double):       %d bytes\n", sizeof(double));
        printf("sizeof(long double):  %d bytes\n", sizeof(long double));
        printf("------------------------------\n");
        printf("sizeof(*int_ptr):     %d bytes\n", sizeof(int_ptr));
        printf("sizeof(*void_ptr):    %d bytes\n", sizeof(void_ptr));
        printf("sizeof(*funct_ptr):   %d bytes\n", sizeof(funct_ptr));

        return 0;
}


roman@athlon1000:~/crosstool/x86_64-unknown/bin> ls ./*gcc ./x86_64-unknown-linux-gnu-gcc

roman@athlon1000:~/crosstool/x86_64-unknown/bin> ./*gcc -m64 -o size64 size.c
roman@athlon1000:~/crosstool/x86_64-unknown/bin> ./*gcc -m32 -o size32 size.c


roman@athlon1000:~/crosstool/x86_64-unknown/bin> file ./size64
./size64: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped


roman@athlon1000:~/crosstool/x86_64-unknown/bin> file ./size32
./size32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), not stripped


roman@athlon1000:~/crosstool/x86_64-unknown/bin> ./size32
sizeof(char):         1 bytes
sizeof(short):        2 bytes
sizeof(int):          4 bytes
sizeof(long):         4 bytes
sizeof(long long):    8 bytes
------------------------------
sizeof(float):        4 bytes
sizeof(double):       8 bytes
sizeof(long double):  12 bytes
------------------------------
sizeof(*int_ptr):     4 bytes
sizeof(*void_ptr):    4 bytes
sizeof(*funct_ptr):   4 bytes
roman@athlon1000:~/crosstool/x86_64-unknown/bin>


------ Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]