我正在使用Debian/MIPS+QEMU构建MIPS端口的PortFusion(一种TCP隧道解决方案)。生成的二进制文件链接到GNU libc。因此,它们不能仅仅复制并在原始OpenWrt上使用,因为原始OpenWrt使用的是uclibc而不是eglibc(后者似乎与GNU libc二进制兼容)。
- GHC 7.4是否可以在ARM和MIPS处理器的Linux二进制文件中不静态链接libc(+ libgmp等)?
- 我如何查看GHC是否使用完全静态编译构建?
-static
在 MIPS 上被忽略:
root@debian:~# cat hello.hs
main = print 2
root@debian:~# ghc --make hello.hs
[1 of 1] Compiling Main ( hello.hs, hello.o )
Linking hello ...
root@debian:~# ldd ./hello
libgmp.so.10 => /usr/lib/mips-linux-gnu/libgmp.so.10 (0x77908000)
libffi.so.5 => /usr/lib/mips-linux-gnu/libffi.so.5 (0x778ea000)
libm.so.6 => /lib/mips-linux-gnu/libm.so.6 (0x77855000)
librt.so.1 => /lib/mips-linux-gnu/librt.so.1 (0x7783c000)
libdl.so.2 => /lib/mips-linux-gnu/libdl.so.2 (0x77827000)
libc.so.6 => /lib/mips-linux-gnu/libc.so.6 (0x776a0000)
libpthread.so.0 => /lib/mips-linux-gnu/libpthread.so.0 (0x77675000)
/lib/ld.so.1 (0x55550000)
root@debian:~# rm hello
root@debian:~# ghc --make -static hello.hs
Linking hello ...
root@debian:~# ldd ./hello
libgmp.so.10 => /usr/lib/mips-linux-gnu/libgmp.so.10 (0x76f98000)
libffi.so.5 => /usr/lib/mips-linux-gnu/libffi.so.5 (0x76f7a000)
libm.so.6 => /lib/mips-linux-gnu/libm.so.6 (0x76ee5000)
librt.so.1 => /lib/mips-linux-gnu/librt.so.1 (0x76ecc000)
libdl.so.2 => /lib/mips-linux-gnu/libdl.so.2 (0x76eb7000)
libc.so.6 => /lib/mips-linux-gnu/libc.so.6 (0x76d30000)
libpthread.so.0 => /lib/mips-linux-gnu/libpthread.so.0 (0x76d05000)
/lib/ld.so.1 (0x55550000)
GHC的信息:
root@debian:~# ghc --info
[("Project name","The Glorious Glasgow Haskell Compilation System")
,("GCC extra via C opts"," -fwrapv")
,("C compiler command","/usr/bin/gcc")
,("C compiler flags"," -fno-stack-protector -Wl,--hash-size=31 -Wl,--reduce-memory-overheads")
,("ar command","/usr/bin/ar")
,("ar flags","q")
,("ar supports at file","YES")
,("touch command","touch")
,("dllwrap command","/bin/false")
,("windres command","/bin/false")
,("perl command","/usr/bin/perl")
,("target os","OSLinux")
,("target arch","ArchUnknown")
,("target word size","4")
,("target has GNU nonexec stack","True")
,("target has subsections via symbols","False")
,("Project version","7.4.1")
,("Booter version","7.4.1")
,("Stage","2")
,("Build platform","mips-unknown-linux")
,("Host platform","mips-unknown-linux")
,("Target platform","mips-unknown-linux")
,("Have interpreter","NO")
,("Object splitting supported","NO")
,("Have native code generator","NO")
,("Support SMP","NO")
,("Unregisterised","YES")
,("Tables next to code","YES")
,("RTS ways","l debug ")
,("Leading underscore","NO")
,("Debug on","False")
,("LibDir","/usr/lib/ghc")
,("Global Package DB","/usr/lib/ghc/package.conf.d")
,("Gcc Linker flags","[\"-Wl,--hash-size=31\",\"-Wl,--reduce-memory-overheads\"]")
,("Ld Linker flags","[\"--hash-size=31\",\"--reduce-memory-overheads\"]")
]
-static -optl-pthread -optl-static
有帮助吗? - gspr-optl-static
确保告诉 C 库的链接器进行静态链接。据我所知,由于库的排序被搞乱了,它还需要被告知包含 pthreads。我认为这些标志在 x86 上也需要用于完全静态二进制文件。 - gsprPortFusion.cabal
。 - Cetin Sert