building for sparc-sun-solaris2.10

I am trying to do some research that involves instrumenting LLVM IR, that I need to test for performance and scalability on a bunch of systems.

I've started trying by trying to get sparc-sun-solaris2.10 (niagara) working. It appears that neither llvm nor llvm-gcc will build natively on the system, so I think that I need to build an llvm-gcc cross compiler.

The documentation for building gcc (in general) as a cross compiler seems to be somewhat dated... and I'm not a very accomplished gnu hacker. I /think/ that I need to do 5 things.

1) Get the solaris include files. No problem.
2) Build binutils for the target. No Problem.
3) Build a stage1 gcc. Problem.
4) Build a glibc.
5) Build a full gcc.

I configured llvm-gcc with

./../../src/llvm-gcc-svn/configure
--prefix=/Users/luked/opt/sparc
--program-prefix=sparc-llvm-
--enable-languages=c,c++
--build=i686-apple-darwin9
--host=i686-apple-darwin9
--target=sparc-sun-solaris2.10
--disable-nls
--with-gmp=/opt/local
--with-mpfr=/opt/local
--enable-llvm=/Users/luked/install/obj/llvm-svn
--without-headers
--with-newlib

which appears to work fine. While building I get the error at the end of the email, which I'm fairly sure is related to something that I am doing wrong, but I'm not sure what it is.

I've been following the instructions in https://www6.software.ibm.com/developerworks/education/l-cross/l-cross-ltr.pdf

Any advice would be great.

Luke

/Users/luked/install/obj/sparc/llvm-gcc/./gcc/xgcc -B/Users/luked/install/obj/sparc/llvm-gcc/./gcc/ -B/Users/luked/opt/sparc/sparc-sun-solaris2.10/bin/ -B/Users/luked/opt/sparc/sparc-sun-solaris2.10/lib/ -isystem /Users/luked/opt/sparc/sparc-sun-solaris2.10/include -isystem /Users/luked/opt/sparc/sparc-sun-solaris2.10/sys-include -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -I. -I. -I../../../../src/llvm-gcc-svn/gcc -I../../../../src/llvm-gcc-svn/gcc/. -I../../../../src/llvm-gcc-svn/gcc/../include -I../../../../src/llvm-gcc-svn/gcc/../libcpp/include -I/opt/local/include -I/opt/local/include -I../../../../src/llvm-gcc-svn/gcc/../libdecnumber -I../libdecnumber -I/Users/luked/install/obj/llvm-svn/include -I/Users/luked/install/src/llvm-svn/include \
    -c ../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c -o gmon.o
/Users/luked/install/obj/sparc/llvm-gcc/./gcc/xgcc -B/Users/luked/install/obj/sparc/llvm-gcc/./gcc/ -B/Users/luked/opt/sparc/sparc-sun-solaris2.10/bin/ -B/Users/luked/opt/sparc/sparc-sun-solaris2.10/lib/ -isystem /Users/luked/opt/sparc/sparc-sun-solaris2.10/include -isystem /Users/luked/opt/sparc/sparc-sun-solaris2.10/sys-include -O2 -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -I. -I. -I../../../../src/llvm-gcc-svn/gcc -I../../../../src/llvm-gcc-svn/gcc/. -I../../../../src/llvm-gcc-svn/gcc/../include -I../../../../src/llvm-gcc-svn/gcc/../libcpp/include -I/opt/local/include -I/opt/local/include -I../../../../src/llvm-gcc-svn/gcc/../libdecnumber -I../libdecnumber -I/Users/luked/install/obj/llvm-svn/include -I/Users/luked/install/src/llvm-svn/include -g0 -finhibit-size-directive -fno-inline-functions -fno-exceptions -fno-zero-initialized-in-bss -fno-toplevel-reorder -Dinhibit_libc -fPIC \
    -c ../../../../src/llvm-gcc-svn/gcc/crtstuff.c -DCRT_END \
    -o crtend.o
In file included from ../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:36:
../../../../src/llvm-gcc-svn/gcc/tsystem.h:90:19: error: stdio.h: No such file or directory
../../../../src/llvm-gcc-svn/gcc/tsystem.h:93:23: error: sys/types.h: No such file or directory
../../../../src/llvm-gcc-svn/gcc/tsystem.h:96:19: error: errno.h: No such file or directory
../../../../src/llvm-gcc-svn/gcc/tsystem.h:103:20: error: string.h: No such file or directory
../../../../src/llvm-gcc-svn/gcc/tsystem.h:104:20: error: stdlib.h: No such file or directory
../../../../src/llvm-gcc-svn/gcc/tsystem.h:105:20: error: unistd.h: No such file or directory
../../../../src/llvm-gcc-svn/gcc/tsystem.h:111:18: error: time.h: No such file or directory
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:37:37: error: fcntl.h: No such file or directory
In file included from ./tm.h:5,
                  from ../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:39:
./options.h:462: error: 'HOST_BITS_PER_INT' undeclared here (not in a function)
./options.h:462: error: bit-field 'padding' width not an integer constant
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c: In function 'monstartup':
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:113: warning: implicit declaration of function 'sbrk'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:113: warning: assignment makes pointer from integer without a cast
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:115: warning: implicit declaration of function 'write'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:137: warning: assignment makes pointer from integer without a cast
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c: In function '_mcleanup':
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:182: error: 'PATH_MAX' undeclared (first use in this function)
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:182: error: (Each undeclared identifier is reported only once
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:182: error: for each function it appears in.)
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:187: warning: implicit declaration of function 'getenv'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:187: warning: assignment makes pointer from integer without a cast
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:193: warning: implicit declaration of function 'strrchr'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:193: warning: incompatible implicit declaration of built-in function 'strrchr'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:199: warning: implicit declaration of function 'sprintf'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:199: warning: incompatible implicit declaration of built-in function 'sprintf'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:199: warning: implicit declaration of function 'getpid'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:205: warning: implicit declaration of function 'creat'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:207: warning: implicit declaration of function 'perror'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:232: warning: implicit declaration of function 'close'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:182: warning: unused variable 'buf'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c: In function 'internal_mcount':
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:300: warning: implicit declaration of function 'atexit'
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c: In function 'moncontrol':
../../../../src/llvm-gcc-svn/gcc/config/sparc/gmon-sol2.c:413: warning: implicit declaration of function 'profil'
make[2]: *** [gmon.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [all-gcc] Error 2
make: *** [all] Error 2

I've started trying by trying to get sparc-sun-solaris2.10 (niagara)
working. It appears that neither llvm nor llvm-gcc will build natively
on the system, so I think that I need to build an llvm-gcc cross compiler.

Get a gcc binary from someplace, use that to then build it, then install and use that, presto, done, and much easier than anything else.

The documentation for building gcc (in general) as a cross compiler
seems to be somewhat dated...

The scheme has not changed (much) in the past 15 years.

4) Build a glibc.

No, I'd nix this part.

--without-headers

?

--with-newlib

?

These two are wrong. You don't want to use newlib. You want to use headers from solaris, as otherwise, you'll get:

../../../../src/llvm-gcc-svn/gcc/tsystem.h:90:19: error: stdio.h: No such file or directory

:slight_smile:

Mike Stump wrote:

I've started trying by trying to get sparc-sun-solaris2.10 (niagara)
working. It appears that neither llvm nor llvm-gcc will build natively
on the system, so I think that I need to build an llvm-gcc cross compiler.

Get a gcc binary from someplace, use that to then build it, then install and use that, presto, done, and much easier than anything else.

Hmm... I'm not exactly following this. I have gcc installed on all of the systems that I work with.

The documentation for building gcc (in general) as a cross compiler
seems to be somewhat dated...

The scheme has not changed (much) in the past 15 years.

Good.

4) Build a glibc.

No, I'd nix this part.

OK, I didn't understand the dependency on glibc. I was just following that IBM document.

--without-headers

?

--with-newlib

?

These two are wrong. You don't want to use newlib. You want to use headers from solaris, as otherwise, you'll get:

../../../../src/llvm-gcc-svn/gcc/tsystem.h:90:19: error: stdio.h: No such file or directory

:slight_smile:

OK. So I've discovered --with-sysroot which seems to be grabbing and patching the include files correctly. Now it's dieing with

   ./options.h:462: error: 'HOST_BITS_PER_INT' undeclared here (not in a function)
   ./options.h:462: error: bit-field 'padding' width not an integer constant

which appears to be llvm-gcc specific because it doesn't happen in vanilla 4.2.4.

I'm definitely moving forward though. Thanks for the advice.

Luke

Luke Dalessandro wrote:

OK. So I've discovered --with-sysroot which seems to be grabbing and patching the include files correctly. Now it's dieing with

   ./options.h:462: error: 'HOST_BITS_PER_INT' undeclared here (not in a function)
   ./options.h:462: error: bit-field 'padding' width not an integer constant

which appears to be llvm-gcc specific because it doesn't happen in vanilla 4.2.4.

I'm definitely moving forward though. Thanks for the advice.

Anton helped me out on irc. For anyone that needs it, the solution was to add #define IN_LIBGCC2 in the beginning of sol2-gmon.c file before its includes.

Now I get to an ICE

/Users/luked/install/obj/sparc/llvm-gcc/./gcc/xgcc -B/Users/luked/install/obj/sparc/llvm-gcc/./gcc/ -B/Users/luked/opt/sparc/sparc-sun-solaris2.10/bin/ -B/Users/luked/opt/sparc/sparc-sun-solaris2.10/lib/ -isystem /Users/luked/opt/sparc/sparc-sun-solaris2.10/include -isystem /Users/luked/opt/sparc/sparc-sun-solaris2.10/sys-include -O2 -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -I. -I. -I../../../../src/llvm-gcc-svn/gcc -I../../../../src/llvm-gcc-svn/gcc/. -I../../../../src/llvm-gcc-svn/gcc/../include -I../../../../src/llvm-gcc-svn/gcc/../libcpp/include -I/opt/local/include -I/opt/local/include -I../../../../src/llvm-gcc-svn/gcc/../libdecnumber -I../libdecnumber -I/Users/luked/install/obj/llvm-svn/include -I/Users/luked/install/src/llvm-svn/include -DL_powitf2 -fvisibility=hidden -DHIDE_EXPORTS -c ../../../../src/llvm-gcc-svn/gcc/libgcc2.c -o libgcc/./_powitf2.o
../../../../src/llvm-gcc-svn/gcc/libgcc2.c: In function '__powitf2':
../../../../src/llvm-gcc-svn/gcc/libgcc2.c:1765: internal compiler error: in HandleArgument, at llvm-abi.h:520

It seems like the sparc-sun-solaris2.10 triple isn't currently supported correctly. I'm considering trying to fix it myself, but my research is in scalable shared memory programming, not the intricacies of gcc and the sparc-solaris ABI.

Can anyone give me a feeling on how much time getting llvm-gcc to produce sparc-solaris IR is likely to take someone with 0 familiarity? Or pointers to documentation. Is reading the llvm-gcc source really the best way to learn about it?

Thanks,
Luke

I also got this far in compiling llvm-gcc 4.2-2.5 on Solaris 10 on a
Niagara 2 machine. Does anyone have a patch/solution for fixing this?
LLVM itself compiles just fine.

Thanks,
Mojtaba