linkwhole test case fails on OpenBSD
Summary
TEST="linkwhole" gmake test
currently fails on OpenBSD
Steps to reproduce
=====> 1 of 1 [0, 0, 0]
$ TEST="linkwhole" gmake test
...
linkwhole(normal) 1 of 1 [0, 0, 0]Wrong exit code for linkwhole()(expected 0 , actual 2 )
Stderr ( linkwhole ):
host: lib.so: unknown symbol `base_GHCziNum_zdfNumInt_closure'
host: Could not load Object Code lib.so.
host: Unable to resolve objects for lib.so
gmake[1]: *** [Makefile:20: linkwhole] Error 1
*** unexpected failure for linkwhole(normal)
Expected behavior
The test should pass.
Environment
- GHC version used: 9.3 (commit 6cea7311)
Optional:
- Operating System: OpenBSD 7.0-current with clang 13
- System Architecture: amd64
More details
This test checks -fwhole-archive-hs-libs
related behavior which is documented as
This is for specialist applications that may require symbols defined in these Haskell libraries at runtime even though they aren’t referenced by any other code linked into the executable. If you’re using -fwhole-archive-hs-libs, you probably also want -rdynamic.
and -rdynamic in turn is documented as:
This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table. Currently Linux and Windows/MinGW32 only. This is equivalent to using -optl -rdynamic on Linux, and -optl -export-all-symbols on Windows.
Based on these I wouldn't expect the test to actually work on OpenBSD, but the failure mode is somewhat strange. Note that the test goes all the way until ./host lib.so
runs. At this point, with LD_DEBUG I get more information:
-rwxr-xr-x 1 greg wsrc 29671392 Dec 19 17:27 host
-rw-r--r-- 1 greg wsrc 8240 Dec 19 17:27 lib.so
Stderr ( linkwhole ):
ld.so loading: 'host'
exe load offset: 0x0
flags ./host = 0x0
head ./host
obj ./host has ./host as head
examining: './host'
loading: libiconv.so.7.0 required by ./host
flags /usr/local/lib/libiconv.so.7.0 = 0x0
obj /usr/local/lib/libiconv.so.7.0 has ./host as head
loading: libc.so.96.1 required by ./host
flags /usr/lib/libc.so.96.1 = 0x21
obj /usr/lib/libc.so.96.1 has ./host as head
loading: libffi.so.1.2 required by ./host
flags /usr/local/lib/libffi.so.1.2 = 0x0
obj /usr/local/lib/libffi.so.1.2 has ./host as head
loading: libgmp.so.11.0 required by ./host
flags /usr/local/lib/libgmp.so.11.0 = 0x0
obj /usr/local/lib/libgmp.so.11.0 has ./host as head
loading: libutil.so.16.0 required by ./host
flags /usr/lib/libutil.so.16.0 = 0x0
obj /usr/lib/libutil.so.16.0 has ./host as head
loading: libcharset.so.1.1 required by ./host
flags /usr/local/lib/libcharset.so.1.1 = 0x0
obj /usr/local/lib/libcharset.so.1.1 has ./host as head
loading: libpthread.so.26.1 required by ./host
flags /usr/lib/libpthread.so.26.1 = 0x8
obj /usr/lib/libpthread.so.26.1 has ./host as head
loading: libm.so.10.1 required by ./host
flags /usr/lib/libm.so.10.1 = 0x0
obj /usr/lib/libm.so.10.1 has ./host as head
linking dep /usr/lib/libm.so.10.1 as child of ./host
linking dep /usr/lib/libutil.so.16.0 as child of ./host
objname /usr/lib/libpthread.so.26.1 is nodelete
linking dep /usr/lib/libpthread.so.26.1 as child of ./host
linking dep /usr/local/lib/libiconv.so.7.0 as child of ./host
linking dep /usr/local/lib/libcharset.so.1.1 as child of ./host
linking dep /usr/local/lib/libgmp.so.11.0 as child of ./host
linking dep /usr/local/lib/libffi.so.1.2 as child of ./host
linking dep /usr/lib/libc.so.96.1 as child of ./host
examining: '/usr/lib/libm.so.10.1'
examining: '/usr/lib/libutil.so.16.0'
examining: '/usr/lib/libpthread.so.26.1'
examining: '/usr/local/lib/libiconv.so.7.0'
examining: '/usr/local/lib/libcharset.so.1.1'
examining: '/usr/local/lib/libgmp.so.11.0'
examining: '/usr/local/lib/libffi.so.1.2'
examining: '/usr/lib/libc.so.96.1'
flags /usr/libexec/ld.so = 0x0
obj /usr/libexec/ld.so has ./host as head
static tls size=0 align=8 offset=0
Start End Type Open Ref GrpRef Name
0000000000200000 00000000013f4000 exe 2 0 0 ./host
000000020652f000 0000000206560000 rlib 0 1 0 /usr/lib/libm.so.10.1
00000002854f4000 0000000285509000 rlib 0 1 0 /usr/lib/libutil.so.16.0
00000002e330d000 00000002e3319000 rlib 0 1 0 /usr/lib/libpthread.so.26.1
000000024a62f000 000000024a731000 rlib 0 1 0 /usr/local/lib/libiconv.so.7.0
00000002f01c4000 00000002f01c8000 rlib 0 1 0 /usr/local/lib/libcharset.so.1.1
0000000225373000 0000000225401000 rlib 0 1 0 /usr/local/lib/libgmp.so.11.0
00000002d3b44000 00000002d3b50000 rlib 0 1 0 /usr/local/lib/libffi.so.1.2
000000023074e000 0000000230842000 rlib 0 1 0 /usr/lib/libc.so.96.1
00000002d667a000 00000002d667a000 ld.so 0 1 0 /usr/libexec/ld.so
dynamic loading done, success.
tib new=0x2cc0bdb00
doing initarray obj 0x29d137000 @0x23082f9b0: [/usr/lib/libc.so.96.1]
version 0 callbacks requested
protect RELRO [0x23082ad90,0x230830000) in /usr/lib/libc.so.96.1
protect RELRO [0x20655ccd0,0x20655e000) in /usr/lib/libm.so.10.1
doing ctors obj 0x29d137400 @0x20655b9e0: [/usr/lib/libm.so.10.1]
protect RELRO [0x285506e70,0x285508000) in /usr/lib/libutil.so.16.0
doing ctors obj 0x29d137c00 @0x285504b00: [/usr/lib/libutil.so.16.0]
protect RELRO [0x2e33175c0,0x2e3318000) in /usr/lib/libpthread.so.26.1
doing ctors obj 0x2c5bac800 @0x2e3315db0: [/usr/lib/libpthread.so.26.1]
protect RELRO [0x24a72d940,0x24a730000) in /usr/local/lib/libiconv.so.7.0
doing ctors obj 0x226894c00 @0x24a72c690: [/usr/local/lib/libiconv.so.7.0]
protect RELRO [0x2f01c6bd0,0x2f01c7000) in /usr/local/lib/libcharset.so.1.1
doing ctors obj 0x2c5bac000 @0x2f01c5ac0: [/usr/local/lib/libcharset.so.1.1]
protect RELRO [0x2253fd380,0x2253fead8) in /usr/local/lib/libgmp.so.11.0
doing ctors obj 0x2c5bac400 @0x2253f96f0: [/usr/local/lib/libgmp.so.11.0]
protect RELRO [0x2d3b4d7e0,0x2d3b4dc60) in /usr/local/lib/libffi.so.1.2
doing ctors obj 0x226894000 @0x2d3b4c470: [/usr/local/lib/libffi.so.1.2]
protect RELRO [0x116edc0,0x1188000) in ./host
doing initarray obj 0x226894800 @0x11711d8: [./host]
entry point: 0x25e440
dlsym: failed to find symbol base_GHCziNum_zdfNumInt_closure
host: lib.so: unknown symbol `base_GHCziNum_zdfNumInt_closure'
host: Could not load Object Code lib.so.
host: Unable to resolve objects for lib.so
doing dtors
We can see that lib.so
is this kind of file:
$ ls -l lib.so
-rw-r--r-- 1 greg wsrc 8232 Dec 19 17:29 lib.so
$ file lib.so
lib.so: ELF 64-bit LSB relocatable, x86-64, version 1
$ nm lib.so
00000000 d .L.str
00000110 D Handles_hsNewSOHandle_closure
00000298 T Handles_hsNewSOHandle_info
00000110 D Handles_zdfstableZZC0ZZCmainZZCHandlesZZChsNewSOHandle_closure
00000150 D Handles_zdtrModule_closure
00000088 D MyCode_myFunction_closure
000001c8 T MyCode_myFunction_info
00000020 D MyCode_zdtrModule_closure
U Types_SOHandles_con_info
00000000 W __llvm_retpoline_r11
00000000 W __retguard_2041
00000000 W __retguard_834
U base_GHCziBase_zd_closure
U base_GHCziBase_zpzp_closure
U base_GHCziNum_zdfNumInt_closure
U base_GHCziNum_zp_info
U base_GHCziShow_show_info
U base_GHCziShow_zdfShowInt_closure
U base_GHCziStable_newStablePtr_closure
U base_GHCziTopHandler_runIO_closure
U base_SystemziIO_putStrLn_closure
00000023 c cC5_str
0000000f c cSK_str
00000000 F ghc_1.s
00000000 F ghc_1.s
00000000 F ghc_2.c
00000000 F ghc_3.s
U ghczmprim_GHCziCString_unpackCStringzh_closure
U ghczmprim_GHCziTypes_Module_con_info
U ghczmprim_GHCziTypes_TrNameS_con_info
000002f0 T hs_soHandles
U newCAF
U registerForeignExports
U rts_apply
U rts_checkSchedStatus
U rts_getStablePtr
U rts_inCall
U rts_lock
U rts_unlock
U stg_INTLIKE_closure
U stg_SRT_2_info
U stg_SRT_3_info
U stg_ap_n_fast
U stg_ap_p_fast
U stg_ap_p_info
U stg_ap_pp_fast
U stg_ap_pp_info
U stg_bh_upd_frame_info
00000170 d stg_exports_Handles
U stg_upd_frame_info
00000380 t stginit_export_Handles