static linking on Linux
Fergus Henderson
fjh at cs.mu.oz.au
Sun Feb 9 23:26:35 AEDT 1997
Hi,
Hans Boehm can review this one.
Estimated hours taken: 1
Fix a problem where the new support for Linux ELF shared libraries
in gc 4.11 meant that `ml -static' didn't work on Linux, because
you got unresolved references to _DYNAMIC in dyn_load.o.
boehm_gc/dyn_load.c:
In GC_FirstDLOpenedLinkMap(), check if the address of _DYNAMIC is 0.
If so, we've been linked statically, so just return 0.
scripts/ml.in:
If we're passed `-static' or `--static', then pass
`-static -Wl,-defsym,_DYNAMIC=0' to gcc, so that gcc
will pass `-defsym _DYNAMIC=0' to the linker.
Index: mercury/boehm_gc/dyn_load.c
diff -u mercury/boehm_gc/dyn_load.c:1.6 mercury/boehm_gc/dyn_load.c:1.7
--- mercury/boehm_gc/dyn_load.c:1.6 Sun Dec 8 21:34:34 1996
+++ mercury/boehm_gc/dyn_load.c Sun Feb 9 23:23:28 1997
@@ -279,6 +279,9 @@
struct r_debug *r;
static struct link_map *cachedResult = 0;
+ if( _DYNAMIC == 0) {
+ return(0);
+ }
if( cachedResult == 0 ) {
int tag;
for( dp = _DYNAMIC; (tag = dp->d_tag) != 0; dp++ ) {
Index: mercury/scripts/ml.in
diff -u mercury/scripts/ml.in:1.24 mercury/scripts/ml.in:1.25
--- mercury/scripts/ml.in:1.24 Sun Feb 9 22:20:02 1997
+++ mercury/scripts/ml.in Sun Feb 9 23:26:57 1997
@@ -139,7 +139,20 @@
shift
;;
-static|--static)
- STATIC_OR_SHARED_OPT=-static
+ case $FULLARCH in
+ *-linux*)
+ # On Linux, if we're linking statically, we need to
+ # pass `-defsym _DYNAMIC=0' to the linker, to avoid
+ # undefined references to _DYNAMIC in
+ # boehm_gc/dyn_load.c.
+ # (We might eventually need similar treatment
+ # for other OSs too)
+ STATIC_OR_SHARED_OPT="-static -Wl,-defsym,_DYNAMIC=0"
+ ;;
+ *)
+ STATIC_OR_SHARED_OPT=-static
+ ;;
+ esac
case $mercury_libs in shared)
mercury_libs=static ;;
esac
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list