LEAP ILP 32

From CDOT Wiki
Jump to: navigation, search

This page describes the process of creating ILP32 support for LEAP.

Current state:

At the current state, gcc-ilp32 (gcc-4.9.2) is created to be correctly installed in the separate tree (/opt/ilp32/). Latest version of gcc can be found here: http://blue/koji/buildinfo?buildID=30942 It correctly produces Aarch64ELF32 files, using the technique, describe below in "Testing ILP32" section. Binutils 2.24 were created to provide scripts that are needed by the linker to work with ILP32 files. There will not be two different versions of Binutils, only one, with the scripts already there. Latest version can be found here: http://blue/koji/buildinfo?buildID=30943

To do:

Currently, we are missing some 32-bit C/C++ libraries. While compiling a file in ilp32 mode is generally successful, some generic C/C++ libraries are present only in 64-bit. To successfully produce 32-bit versions, we need to compile GCC in MultiLib mode, which supposedly will generate those libraries. We found this information after checking the build logs for Fedora gcc, to see at what point and what command 32-bit libraries were generated. https://kojipkgs.fedoraproject.org//packages/gcc/5.2.1/1.fc22/data/logs/x86_64/build.log build log shows that 32-bit folder was created in libgcc/Makefile.in. There we found that the directory uses default gcc macro to name MULTIOSDIR, which on our builders is different from what it needs to be. We created a patch to hardcode that value to what it needs to be ("32"). Next step was to enable multilib support in gcc-ilp32.spec. For that we added aarch64 architecture to the list of architectures with multilib support. Unfortunately, to compile a compiler with MultiLib support, one would need to use another existing on the system compiler with MultiLib. Since out gcc was build without such support, it doesn't come with the required libraries. We have two options here. Wither use Fedora gcc, or see if we can use APM drop gcc. First, we tried to use Fedora gcc as that MultiLib compiler. Unfortunately, building gcc using that Fedora compiler crashes with a message "C compiler cannot create executables". This problem is believed to occur if there are missing or corrupted libgcc, gcc-c++ and/or libstdc++ packages on the system. Reinstalling those packages on LEAP system didn't help. We tried to use APM drop gcc, but it would crash pretty quickly as well, with the message "error: gmp.h header not found". Unfortunately, reinstalling gmp and gmp-devel packages did not solve this problem. With the freshly installed Fedora 21, and fully installed gcc package from Fedora repos, we tried to build gcc again. This time it broke while trying to build "libgomp". Checking the build logs showed that the problem is: "/usr/bin/ld: cannot find -lgcc_s". The file "libgcc_s" is present in /usr/lib64/, which is the default. Somehow, the linker still doesn't find it. On the following screenshot, you can see the building error (left), the build log with the exact error (middle), and the corresponding code within the configure file (located at "rpmbuild/BUILD/gcc-4.9.2-20150212/libgomp/").

Screenshot-from-2015-08-19-161047.png

The line that is failing the build is "3691: test $ac_status = 0; }; then :". The ac_status comes from "3688: (eval "$ac_link_default") 2>&5" and "3689: ac_status=$?". As you can see, $ac_link_default is giving 1 instead of 0. It gets its value from "3666: ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`". $ac_link is defined as "3323: ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'". It is believed that the value of $LDFLAGS is the problem. Possibly, it is overwriting the search path for the linker, resulting in the library not being found.

Next steps:

We need to put some echo statements in the mentioned above configure file to see if the guesses were correct. and LDFLAGS was the problem. If it was, we need to create a patch that would change the value of LDFLAGS to what we need, or, possibly, simply create a link in the correct place to the existing file. Then we will try to build our MultiLib capable gcc on that system. When succeeded, we will install our gcc on a LEAP builder, change the spec file for gcc to point towards that MultiLib capable gcc, and produce the final version of our gcc.

Testing ILP32:

  • Create "hello.c" file.
  • Add info to it at your discretion.
  • Run "/opt/ilp32/usr/bin/gcc -c -mabi=ilp32 hello.c".
  • Run "ld -m aarch64elf32 hello.o".
  • If you want to run it in one commands, use "/opt/ilp32/usr/bin/gcc -mabi=ilp32 -Xlinker -maarch64elf32 hello.c".
  • Run "file a.out".
  • Check that it says "ELF32", "executable binary" and "statically linked".



Old information (outdated, kept here for reference/info):

GCC:

%define _prefix /opt/ilp32/usr
  • I run "export RPM_PACKAGER="Artem Luzyanin <artem.luzyanin@senecacollege.ca>""
  • I run "rpmdev-bumpspec -c "Changed spec file to create ilp32-capable gcc in a separate tree."" command to add the changes with comments to the spec file.
  • I run "rpmbuild -ba --nocheck gcc.spec" command to get the rpms.
  • I run "rpm -qlp gcc-4.9.2-6.bb1.1.aarch64.rpm gcc.spec" command to check that all gcc files will be installed in the correct place (under /opt/ilp32/).

GLIBC:

  • I downloaded glibc-2.17 source rpm. I got mine from http://blue/kojifiles/packages/glibc/2.17/78.bb4/src/glibc-2.17-78.bb4.src.rpm.
  • I downloaded and installed required dependencies from the same place.
  • I run "rpm -i glibc-2.17-78.bb4.src.rpm" to install it on AArch64 builder.
  • I went in the "~/rpmbuild/SPEC" directory, and run command "rpmbuild -bp glibc.spec" to get the prep stage on the rpm.
  • I created a git repository, and pushed the content of "~/rpmbuild/BUILD/glibc{some random numbers}" directory to it to get the original information in it.
  • I went in the "~/rpmbuild/BUILD/glibc{some random numbers}" directory.

I changed "configure" file in the next ways: I run "./configure" command. I changed "Makefile" file in the next ways:

  • I run "make" command, then waited for the make for a long period of time for it to be complete (around 7 hours).
  • I committed the changes and run "git diff --patience master glibc21-leap-ilp-32 | filterdiff --format=context > ../glibc21-leap-ilp-32.patch" command to get the patch for my changes.
  • I run "export RPM_PACKAGER="Artem Luzyanin <artem.luzyanin@senecacollege.ca>""
  • I run "rpmdev-bumpspec -c "This patch is to create ilp32-compiler libraries of glibc in a separate tree."" command to add the changes with comments to the spec file.

I changed "~/rpmbuild/SPEC/glibc.spec" file in the next way: I run "rpmbuild -bs glibc.spec" command to get the source rpm.