[MLton-commit] r6904

Wesley Terpstra wesley at mlton.org
Fri Oct 3 16:25:18 PDT 2008


Copying the .drectve section with a custom linker script can have the 
unfortunate side effect of putting that section first, which causes
addresses of symbols to change when it is eventually discarded, resulting
ultimately in a segfault for the library in question.

Telling 'ld' it's unique seems to not cause this, yet still preserves the
export section.


----------------------------------------------------------------------

U   mlton/trunk/bin/static-library

----------------------------------------------------------------------

Modified: mlton/trunk/bin/static-library
===================================================================
--- mlton/trunk/bin/static-library	2008-10-03 23:23:00 UTC (rev 6903)
+++ mlton/trunk/bin/static-library	2008-10-03 23:25:18 UTC (rev 6904)
@@ -40,15 +40,16 @@
     "${target}ld" -r -o "$output.o" "$@"
     # The osx linker already makes hidden symbols local
   elif [ "$os" = "mingw" -o "$os" = "cygwin" ]; then
-    # We need to force the export directives to be copied
-    echo "SECTIONS { .drectve : { *(.drectve) } }" > "$output.script"
-    "${target}ld" -r --enable-stdcall-fixup -o "$output.o" "$output.script" "$@"
-    # Extract the list of exports to make them global
-    "${target}dlltool" --output-def "$output.def" "$@"
+    # Link allowing _address of stdcall function fixups
+    # Preserve the export list (.drectve section)
+    "${target}ld" -r --unique=.drectve --enable-stdcall-fixup -o "$output.o" "$@"
+    # Extract the list of exports to make only them global
+    "${target}dlltool" --output-def "$output.def" "$output.o"
     grep '@' "$output.def" \
       | sed 's/^[[:space:]]*\([^[:space:]]*\).*$/_\1/' \
       > "$output.globals"
     "${target}objcopy" --keep-global-symbols "$output.globals" "$output.o"
+    rm "$output.def" "$output.globals"
   else
     "${target}ld" -r -o "$output.o" "$@"
     # ELF systems are all the same... localize hidden symbols
@@ -59,12 +60,13 @@
       | sed 's/^.* \.hidden //' \
       > "$output.locals"
     "${target}objcopy" --localize-symbols "$output.locals" "$output.o"
+    rm "$output.locals"
   fi
 
   # Create the final archive
   "${target}ar" rc "$output" "$output.o"
   "${target}ranlib" "$output"
-  rm -f "$output.o" "$output.def" "$output.globals" "$output.locals" "$output.script"
+  rm "$output.o"
 else
   "${target}ar" rc "$output" "$@"
   "${target}ranlib" "$output"




More information about the MLton-commit mailing list