MantisBT - CMake
View Issue Details
0013332CMakeCMakepublic2012-06-20 15:482016-06-10 14:31
Daniel Richard G. 
Kitware Robot 
normalminoralways
closedmoved 
PA-RISCHP-UX11.00
CMake 2.8.8 
 
0013332: Can't link a shared library with cc on HP-UX
Bootstrapping 2.8.8 on HP-UX 11.00 with the vendor compiler fails with

[...]
Linking C shared module libcmsysTestDynload.sl
cd /tmp/cmake-2.8.8-test/_build-cc/Source/kwsys && /tmp/cmake-2.8.8-test/_build-cc/Bootstrap.cmk/cmake -E cmake_link_script CMakeFiles/cmsysTestDynload.dir/link.txt --verbose=1
/opt/ansic/bin/cc +Z -Ae +DA2.0 +ESlit +w1 -z -Wp,-H262144 +O2 -Wl,-E,+nodefaultrpath -b -L/usr/lib -Wl,+hlibcmsysTestDynload.sl -o libcmsysTestDynload.sl CMakeFiles/cmsysTestDynload.dir/testDynload.c.o -Wl,+b/usr/lib
cc: warning 488: "cc +help" invokes On-Line C reference manual.
cc: warning 422: Unknown option "b" ignored.
/usr/ccs/bin/ld: Unsatisfied symbols:
   main (Not referenced yet! Probably due to -u option)
gmake[2]: *** [Source/kwsys/libcmsysTestDynload.sl] Error 1
gmake[2]: Leaving directory `/tmp/cmake-2.8.8-test/_build-cc'
gmake[1]: *** [Source/kwsys/CMakeFiles/cmsysTestDynload.dir/all] Error 2
gmake[1]: Leaving directory `/tmp/cmake-2.8.8-test/_build-cc'
gmake: *** [all] Error 2


For one, that -b needs to be a -Wl,-b. If I do the compiler invocation that way, I get

host:/tmp/cmake-2.8.8-test/_build-cc/Source/kwsys$ /opt/ansic/bin/
cc +Z -Ae +DA2.0 +ESlit +w1 -z -Wp,-H262144 +O2 -Wl,-E,+nodefaultrpath -Wl,-b -L
/usr/lib -Wl,+hlibcmsysTestDynload.sl -o libcmsysTestDynload.sl CMakeFiles/cmsys
TestDynload.dir/testDynload.c.o -Wl,+b/usr/lib
/usr/ccs/bin/ld: CODE_ONE_SYM fixup to non-code subspace in file /opt/langtools/lib/crt0.o - shared library must be position independent. Use +z or +Z to recompile.


Adding -v to that gives me

cc: NLSPATH is /opt/ansic/lib/nls/msg/%L/%N.cat:/opt/ansic/lib/nls/msg/C/%N.cat:
cc: CCOPTS is not set.
cc: INCLUDIR is INCLUDIR=/usr/include
cc: LPATH is /usr/lib:/opt/langtools/lib:
/usr/ccs/bin/ld /opt/langtools/lib/crt0.o -u main -z -E +nodefaultrpath -b -L/usr/lib +hlibcmsysTestDynload.sl -o libcmsysTestDynload.sl CMakeFiles/cmsysTestDynload.dir/testDynload.c.o +b/usr/lib -lc
cc: Entering Link editor.
/usr/ccs/bin/ld: CODE_ONE_SYM fixup to non-code subspace in file /opt/langtools/lib/crt0.o - shared library must be position independent. Use +z or +Z to recompile.


I don't know how crt0.o is getting in there, but if I invoke ld directly without that, the link works. There is probably an option that can be given to cc(1) so that it doesn't pass crt0.o to the linker, but I'm not seeing anything along those lines in the man page...
No tags attached.
Issue History
2012-06-20 15:48Daniel Richard G.New Issue
2012-06-20 16:09Brad KingNote Added: 0029782
2012-06-20 16:44Daniel Richard G.Note Added: 0029787
2012-06-21 08:27Brad KingNote Added: 0029794
2012-06-21 08:27Brad KingStatusnew => backlog
2012-06-21 12:31Daniel Richard G.Note Added: 0029799
2012-06-21 13:00Brad KingNote Added: 0029800
2012-06-22 09:30Daniel Richard G.Note Added: 0029815
2016-06-10 14:28Kitware RobotNote Added: 0042071
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0029782)
Brad King   
2012-06-20 16:09   
We used to use "ld" directly, but that changed here:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5720e1f6 [^]
(0029787)
Daniel Richard G.   
2012-06-20 16:44   
That's how libtool does things on this platform, apparently (just glanced at another build we have here). And it looks like excluding the crt0.o object when linking a shared library with cc is actually not an easy problem:

    https://mail.gnome.org/archives/gtk-list/1999-March/msg00704.html [^]
    http://comments.gmane.org/gmane.comp.encryption.openssl.devel/10303 [^]

Looks like that special case is going to be needed...

(By the way, I would consider changing -Wl,+hlibfoo.sl to -Wl,+h,libfoo.sl. The ld man page shows this option as "+h internal_name" rather than "+hinternal_name".)
(0029794)
Brad King   
2012-06-21 08:27   
Moving to backlog awaiting a specific proposal as I have no time to work on non-trivial changes to support ancient platforms, especially without access to them.

The "special case" will need to detect when a compiler too old to create shared libraries is in use and set CMAKE_${lang}_CREATE_SHARED_LIBRARY to use "ld".

We do have version detection when the compiler defines __HP_cc, but obviously not when the compiler doesn't identify itself.

(0029799)
Daniel Richard G.   
2012-06-21 12:31   
FWIW, "gmake -k" allows this error to be skipped, and the build goes on to produce usable cmake/ccmake/etc. binaries. So this issue isn't much of an obstacle to building CMake itself, at least.

(Maybe revert to using ld directly if none of __HP_cc/__HP_aCC/__GNUC__ is defined, without going to the trouble of a test? That won't rule out all corner cases, but it would be better than what we've got now...)
(0029800)
Brad King   
2012-06-21 13:00   
Re 0013332:0029799: If you just want to build CMake and not run the tests try adding "-- -DBUILD_TESTING=0" to the bootstrap options to disable testing. That may prevent the shared lib from being built.

Without worrying about a test yet, try hacking your local sources to set CMAKE_${lang}_CREATE_SHARED_LIBRARY in Modules/Platform/HP-UX-HP.cmake to use ld, using the code removed by commit 5720e1f6 as a reference. If you can get things working and tests passing then we can worry about the proper test after that.
(0029815)
Daniel Richard G.   
2012-06-22 09:30   
I built CMake 2.8.8 + the three patches + reversed linking-with-cc patch on the HP-UX system with cc. libcmsysTestDynload.sl and everything else builds straight through to the end.
(0042071)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.