solaris - compile 64bit gcc - elf class error

北城以北 提交于 2019-12-04 20:15:22

With the default configure line, GCC will not be built as a 64-bit binary, but as 32-bit. So, you need to rebuild GMP, MPFR and MPC in 32-bit mode, by forcing configure ABI=32.

Alternatively, you can configure GCC with a sparc64-sun-solarisX build triplet. In that case, there are additional instructions on the GCC website.

You don't need 64-bit gcc binaries in order to build 64-bit application. The OpenCSW Solaris packages provide 32-bit compiler with 32-bit and 64-bit targets.

I assume you care more about being able to generate 64-bit binaries from your gcc, and less about gcc itself being 64-bit.

The way to build both 32-bit and 64-bit targets, you need to build gmp two times, once 32-bit and once 64-bit. Then you have the following layout (the example is taken from package's pkgmap):

1 f none /opt/csw/include/gmp-32.h 0644 root bin 86213 38841 1316878625
1 f none /opt/csw/include/gmp-64.h 0644 root bin 86218 39139 1316879685
1 f none /opt/csw/include/gmp.h 0755 root bin 159 12880 1316879688
1 f none /opt/csw/include/gmpxx-32.h 0644 root bin 114646 51865 1316878625
1 f none /opt/csw/include/gmpxx-64.h 0644 root bin 114646 51865 1316879685
1 f none /opt/csw/include/gmpxx.h 0755 root bin 163 13360 1316879688
1 s none /opt/csw/lib/libgmp.so=libgmp.so.10.0.2
1 s none /opt/csw/lib/libgmpxx.so=libgmpxx.so.4.2.2
1 s none /opt/csw/lib/libgmp.so.10=libgmp.so.10.0.2
1 f none /opt/csw/lib/libgmp.so.10.0.2 0755 root bin 462552 51359 1316878625
1 s none /opt/csw/lib/sparcv9/libgmp.so.10=libgmp.so.10.0.2
1 f none /opt/csw/lib/sparcv9/libgmp.so.10.0.2 0755 root bin 503424 11223 1316879684

The GCC build system is smart enough to know to look into /opt/csw/lib/sparcv9 for the 64-bit libraries and into /opt/csw/lib for the 32-bit libraries.

The gmp.h header file is a wrapper, which contains an #ifdef statement, including gmp-32.h or gmp-64.h depending on the compilation mode requested.

/* Allow 32 and 64 bit headers to coexist */
#if defined __amd64 || defined __x86_64 || defined __sparcv9
#include "gmp-64.h"
#else
#include "gmp-32.h"
#endif

The gmp library is the only one which requires this kind of header file wrapper; the mpc, mpfr, ppl and cloog libraries don't vary the header files depending on the architecture / word length.

When you compile gcc with 64-bit targets, you get a layout with two crt1.o files:

/opt/csw/lib/gcc/sparc-sun-solaris2.9/4.6.2/crt1.o
/opt/csw/lib/gcc/sparc-sun-solaris2.9/4.6.2/sparcv9/crt1.o

This way, when you pass -m64, gcc will produce a 64-bit binary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!