| ... |
... |
@@ -10,14 +10,57 @@ OBSERVED_SYMBOLS=observed_symbols.txt |
|
10
|
10
|
# Get rts Symbols listed in RtsSymbols.c
|
|
11
|
11
|
./Main dump | sort > $DECLARED_SYMBOLS
|
|
12
|
12
|
|
|
13
|
|
-# Get rts DLL exports from the DLL
|
|
14
|
|
-# Match e.g.:
|
|
15
|
|
-# libHSrts-1.0.3-ghc9.15.20260710.dll => /home/alice/s p a c e/myApp/bin/libHSrts-1.0.3-ghc9.15.20260710.dll (0x7ffebc9a0000)
|
|
16
|
|
-RTS_DYLIB_PATH=$(ldd ./Main | awk '/^[[:space:]]*libHSrts-.* => .+$/ {
|
|
17
|
|
- sub(/^[[:space:]]*libHSrts-.* => /, "")
|
|
18
|
|
- sub(/ \([^(]*\)$/, "")
|
|
19
|
|
- print
|
|
20
|
|
-}')
|
|
|
13
|
+# Find the path of the RTS shared object that ./Main is linked against
|
|
|
14
|
+if command -v ldd > /dev/null 2>&1; then
|
|
|
15
|
+ # Match e.g.:
|
|
|
16
|
+ # libHSrts-1.0.3-ghc9.15.20260710.so => /home/alice/s p a c e/myApp/lib/libHSrts-1.0.3-ghc9.15.20260710.so (0x7ffebc9a0000)
|
|
|
17
|
+ RTS_DYLIB_PATH=$(ldd ./Main | awk '/^[[:space:]]*libHSrts-.* => .+$/ {
|
|
|
18
|
+ sub(/^[[:space:]]*libHSrts-.* => /, "")
|
|
|
19
|
+ sub(/ \([^(]*\)$/, "")
|
|
|
20
|
+ print
|
|
|
21
|
+ }')
|
|
|
22
|
+elif command -v otool > /dev/null 2>&1; then
|
|
|
23
|
+ # macOS has no ldd. Use otool to find the RTS install name, e.g.:
|
|
|
24
|
+ # @rpath/libHSrts-1.0.3-ghc9.15.20260710.dylib (compatibility version 0.0.0, current version 0.0.0)
|
|
|
25
|
+ RTS_INSTALL_NAME=$(otool -L ./Main | awk '/^[[:space:]]*[^[:space:]].*\/libHSrts-[^\/]*\.dylib \(/ {
|
|
|
26
|
+ sub(/^[[:space:]]*/, "")
|
|
|
27
|
+ sub(/ \([^(]*\)$/, "")
|
|
|
28
|
+ print
|
|
|
29
|
+ exit
|
|
|
30
|
+ }')
|
|
|
31
|
+
|
|
|
32
|
+ case "$RTS_INSTALL_NAME" in
|
|
|
33
|
+ @rpath/*)
|
|
|
34
|
+ # Resolve @rpath against the LC_RPATH entries of ./Main e.g.:
|
|
|
35
|
+ # cmd LC_RPATH
|
|
|
36
|
+ # cmdsize 120
|
|
|
37
|
+ # path /Users/alice/s p a c e/lib/rts-1.0.3 (offset 12)
|
|
|
38
|
+ MAIN_DIR=$(cd "$(dirname ./Main)" && pwd)
|
|
|
39
|
+ RTS_DYLIB_PATH="not found"
|
|
|
40
|
+ while IFS= read -r RPATH; do
|
|
|
41
|
+ RPATH="${RPATH/#@loader_path/$MAIN_DIR}"
|
|
|
42
|
+ RPATH="${RPATH/#@executable_path/$MAIN_DIR}"
|
|
|
43
|
+ CANDIDATE="$RPATH/${RTS_INSTALL_NAME#@rpath/}"
|
|
|
44
|
+ if [ -f "$CANDIDATE" ]; then
|
|
|
45
|
+ RTS_DYLIB_PATH="$CANDIDATE"
|
|
|
46
|
+ break
|
|
|
47
|
+ fi
|
|
|
48
|
+ done < <(otool -l ./Main | awk '
|
|
|
49
|
+ $1 == "cmd" { in_rpath = ($2 == "LC_RPATH") }
|
|
|
50
|
+ in_rpath && $1 == "path" {
|
|
|
51
|
+ sub(/^[[:space:]]*path /, "")
|
|
|
52
|
+ sub(/ \(offset [0-9]+\)$/, "")
|
|
|
53
|
+ print
|
|
|
54
|
+ }')
|
|
|
55
|
+ ;;
|
|
|
56
|
+ *)
|
|
|
57
|
+ RTS_DYLIB_PATH="$RTS_INSTALL_NAME"
|
|
|
58
|
+ ;;
|
|
|
59
|
+ esac
|
|
|
60
|
+else
|
|
|
61
|
+ echo "Neither ldd nor otool is available to find the RTS DSO" 1>&2
|
|
|
62
|
+ exit 1
|
|
|
63
|
+fi
|
|
21
|
64
|
|
|
22
|
65
|
if [ -z "$RTS_DYLIB_PATH" -o "$RTS_DYLIB_PATH" = "not found" ]; then
|
|
23
|
66
|
echo "Could not find path to RTS DSO: \"$RTS_DYLIB_PATH\"" 1>&2
|