Opened 7 years ago

Last modified 7 years ago

#1350 new defect

Static linking is broken on Solaris

Reported by: evhan Owned by:
Priority: major Milestone: someday
Component: unknown Version: 4.12.0
Keywords: static solaric ld linker Cc:
Estimated difficulty: medium

Description

While testing Peter's fix for #1347, I found that static linking is totally broken on Solaris.

In particular, our linking tests fail on both Solaris 10 and 11 (gcc, i386 -- I haven't tried with any other compiler or architecture), albeit with slightly different error messages. The underlying issue might be the same, however, since they both fail in the same situations.

Note that this problem isn't caused by the fix for #1347; both c4c60ce5 and 4.12.0 fail in the same way, so this was a preexisting bug.

Try running the following command to see the problem:

$ echo '(print 1)' | csc -static -o /tmp/a.out -

Test output on Solaris 10:

==> solaris-solaris-10-i386: ======================================== linking tests ...
==> solaris-solaris-10-i386: [... snip ...]
==> solaris-solaris-10-i386: /export/home/vagrant/chicken-core/tests/../chicken 'linking-tests.scm' -output-file 'linking-tests.c' -feature chicken-compile-static -verbose -include-path /export/home/vagrant/chicken-core/tests/.. -uses reverser
==> solaris-solaris-10-i386: 'gcc' 'linking-tests.c' -o 'linking-tests.o' -c  -fno-strict-aliasing -fwrapv -DHAVE_CHICKEN_CONFIG_H -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -I/export/home/vagrant/chicken-core/tests/.. -I/export/home/vagrant/chicken-core/tests/../include/chicken/
==> solaris-solaris-10-i386: rm linking-tests.c
==> solaris-solaris-10-i386: 'gcc' 'linking-tests.o' 'reverser.o' -o 'linking-tests' -L/export/home/vagrant/chicken-core/tests/.. -L/export/home/vagrant/chicken-core/tests/../lib/  -Wl,-R'/export/home/vagrant/chicken-core/lib/' -static -lchicken -lsocket -lnsl -lm -ldl -lrt
==> solaris-solaris-10-i386: ld: fatal: library -lsocket: not found
==> solaris-solaris-10-i386: ld: fatal: library -lnsl: not found
==> solaris-solaris-10-i386: ld: fatal: library -lm: not found
==> solaris-solaris-10-i386: ld: fatal: library -ldl: not found
==> solaris-solaris-10-i386: ld: fatal: library -lrt: not found
==> solaris-solaris-10-i386: ld: fatal: library -lc: not found
==> solaris-solaris-10-i386: ld: fatal: file processing errors. No output written to linking-tests
==> solaris-solaris-10-i386: Error: shell command terminated with non-zero exit status 256: 'gcc' 'linking-tests.o' 'reverser.o' -o 'linking-tests' -L/export/home/vagrant/chicken-core/tests/.. -L/export/home/vagrant/chicken-core/tests/../lib/  -Wl,-R'/export/home/vagrant/chicken-core/lib/' -static -lchicken -lsocket -lnsl -lm -ldl -lrt

Test output on Solaris 11:

==> solaris-solaris-11-i386: ======================================== linking tests ...
==> solaris-solaris-11-i386: [... snip ...]
==> solaris-solaris-11-i386: /export/home/vagrant/chicken-core/tests/../chicken 'linking-tests.scm' -output-file 'linking-tests.c' -feature chicken-compile-static -verbose -include-path /export/home/vagrant/chicken-core/tests/.. -uses reverser
==> solaris-solaris-11-i386: 'gcc' 'linking-tests.c' -o 'linking-tests.o' -c  -fno-strict-aliasing -fwrapv -DHAVE_CHICKEN_CONFIG_H -DC_ENABLE_PTABLES -Os -fomit-frame-pointer -I/export/home/vagrant/chicken-core/tests/.. -I/export/home/vagrant/chicken-core/tests/../include/chicken/
==> solaris-solaris-11-i386: rm linking-tests.c
==> solaris-solaris-11-i386: 'gcc' 'linking-tests.o' 'reverser.o' -o 'linking-tests' -L/export/home/vagrant/chicken-core/tests/.. -L/export/home/vagrant/chicken-core/tests/../lib/  -Wl,-R'/export/home/vagrant/chicken-core/lib/' -static -lchicken -lsocket -lnsl -lm -ldl -lrt
==> solaris-solaris-11-i386: ld: fatal: option '-R/export/home/vagrant/chicken-core/lib/' is incompatible with building a static executable
==> solaris-solaris-11-i386: 
==> solaris-solaris-11-i386: Error: shell command terminated with non-zero exit status 256: 'gcc' 'linking-tests.o' 'reverser.o' -o 'linking-tests' -L/export/home/vagrant/chicken-core/tests/.. -L/export/home/vagrant/chicken-core/tests/../lib/  -Wl,-R'/export/home/vagrant/chicken-core/lib/' -static -lchicken -lsocket -lnsl -lm -ldl -lrt

Change History (3)

comment:1 Changed 7 years ago by sjamaan

It looks like static linking against system libraries simply isn't supported on Solaris...

Maybe we need to do something with LIBRARIES so that we know which ones need to be put in front of an (optional) -static flag, so that they are linked dynamically? Alternatively, disable static linking altogether on Solaris...

comment:2 Changed 7 years ago by sjamaan

I asked on #openindiana and people there confirmed that indeed, static system libraries are not available.

comment:3 Changed 7 years ago by sjamaan

TODO: Check how Golang deals with this. They support Solaris since version 1.3

Note: See TracTickets for help on using tickets.