building multilib libgcc?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

building multilib libgcc?

Post by mariuszp »

I have a cross-compiler targetting my OS on x86_64. I want the entire OS to be buildable using that single toolchain, but some 32-bit code is required (some bootloader stuff mainly). My toolchain successfully produces 32-bit object files using the -m32 option, but I cannot link an ELF32 executable because there is no 32-bit version of libgcc.

How do I configure GCC to target x86_64-glidix, and build the i386 libgcc too? Will it automatically know to put the 32-bit version of libgcc in a separate folder in the sysroot, or does it require more options? Has anyone done this?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: building multilib libgcc?

Post by iansjack »

I use a 32-bit cross compiler and toolchain for the 32-bit code. There's probably a better way of doing it, but that works for me.
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: building multilib libgcc?

Post by mariuszp »

I'd very much prefer not to build 2 different cross-compilers just to build the OS, especially since i want it to become self-hosting so it's a bit silly to build a second compiler under the OS just for the purpose of compiling the OS itself.

I'm trying the following configure command:

Code: Select all

../glidix-gcc/configure --target=x86_64-glidix --prefix=/glidix/usr --with-sysroot=/glidix --enable-languages=c,c++ --disable-nls --enable-multilib --enable-multiarch --with-multilib-list=m32,m64 --with-arch-32=i686
It does not complain, builds fully (using just "make"; no "make all-gcc" and other trickery) and installs in the sysroot. However, it only builds a 64-bit version of libgcc, and furthermore, with the "-m32" flag passed, it still searches the same library directories and complains about the 64-bit libgcc being incompatible.

The configure command with which my native Linux toolchain was compiled (the binary distribution that comes with Ubuntu) is:

Code: Select all

../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
I'm not sure exactly what they set there to make it build a 32-bit libgcc and to look for libraries in /lib32 instead of /usr/lib
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: building multilib libgcc?

Post by gerryg400 »

Hi. You need a t-myos file something like the following.

Code: Select all

MULTILIB_OPTIONS = m64/m32
MULTILIB_DIRNAMES = 64 32 
MULTILIB_OSDIRNAMES = ../lib ../lib32

LIBGCC = stmp-multilib
INSTALL_LIBGCC = install-multilib

EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o crtprec32.o crtprec64.o crtprec80.o 

# Compile crtbeginS.o and crtendS.o with pic.
CRTSTUFF_T_CFLAGS += -fPIC
CRTSTUFF_T_CFLAGS_S = $(CRTSTUFF_T_CFLAGS) -fPIC

# Compile libgcc2.a with pic.
TARGET_LIBGCC2_CFLAGS = -fPIC
You may also need to handle the -m option as below from myos64.h

Code: Select all

...
#define SPEC_32 "m32"
#define SPEC_64 "!m32"

#undef ASM_SPEC
#define ASM_SPEC "%{" SPEC_32 ":--32} %{" SPEC_64 ":--64}"

#undef  STARTFILE_SPEC
#define STARTFILE_SPEC "%{!shared:crt1.o%s} \
   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"

#undef  ENDFILE_SPEC
#define ENDFILE_SPEC "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"

#undef  LINK_SPEC
#define LINK_SPEC "%{" SPEC_64 ":-m elf_x86_64} %{" SPEC_32 ":-m elf_i386} \
  %{shared:-shared} \
  %{!shared: \
    %{!static: \
      %{rdynamic:-export-dynamic} \
      %{" SPEC_32 ":-dynamic-linker " "/lib32/ld-myos32.so" "} \
      %{" SPEC_64 ":-dynamic-linker " "/lib/ld-myos.so" "}} \
    %{static:-static}}"

#define MULTILIB_DEFAULTS { "m64" }
...
The result of this is that I end up with 2 sets of libs. When I build libc I put the 32 bit version in /lib32/libc.a and it and the associated startup code is all found automatically when I type -m32. Unfortunately I did most of this by trial and error so the 'science' is lacking a little.
If a trainstation is where trains stop, what is a workstation ?
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: building multilib libgcc?

Post by mariuszp »

Do I need to list the t-glidix file somewhere?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: building multilib libgcc?

Post by gerryg400 »

Yes. You have something like this in config.gcc

Code: Select all

+x86_64-*-glidix*)
+	extra_parts="$extra_parts crtbegin.o crtend.o"
+	tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+	;;
I have this. I guess your tm_file is a default. I added an extra file to it for myos.
Then I have my own i386/myos64-t

Code: Select all

+x86_64-*-myos*)
+    tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h i386/myos_64.h"
+    tmake_file="${tmake_file} i386/t-myos64 t-svr4 i386/t-crtstuff i386/t-crtpc i386/t-crtfm t-dfprules"
+    use_fixproto=yes
+    ;;
If a trainstation is where trains stop, what is a workstation ?
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: building multilib libgcc?

Post by mariuszp »

And what configure/build commands did you use? With the example you provided I did:

Code: Select all

../glidix-gcc/configure --target=x86_64-glidix --prefix=/glidix/usr --with-sysroot=/glidix --enable-languages=c,c++ --disable-nls --enable-multiarch --enable-multilib
make
make install
And then:

Code: Select all

x86_64-glidix-gcc -m32 test.o -o test -lgcc -nostdlib -ffreestanding
Still searches for the 64-bit libgcc, and there is no "lib32" folder anywhere to be seen. (And so it doesn't link).
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: building multilib libgcc?

Post by mariuszp »

Whoops, done a few mistakes. Now it builds the 32-bit libgcc, but fails for the C++ library, because it "cannot performs link tests after GCC_NO_EXECUTABLES", which is apparently due to the lack of a 32-bit libc for my OS.

Can I disable multilib for just the C++ library? That is, I want to build the 32-bit compiler as well as libgcc, but not the 32-bit C++ standard library (only the 64-bit one).
Post Reply