build: fix rpath support on Linux

This commit is contained in:
Aofei Sheng
2024-07-15 22:45:15 +08:00
parent 607e3bbc11
commit afa9a00259
2 changed files with 4 additions and 2 deletions

BIN
_demo/hello/hello Executable file

Binary file not shown.

View File

@@ -329,8 +329,6 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, llFiles
args = append(
args,
"-o", app,
"-rpath", "@loader_path",
"-rpath", "@loader_path/../lib",
"-fuse-ld=lld",
"-Wno-override-module",
// "-O2", // FIXME: This will cause TestFinalizer in _test/bdwgc.go to fail on macOS.
@@ -339,6 +337,8 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, llFiles
case "darwin": // ld64.lld (macOS)
args = append(
args,
"-rpath", "@loader_path",
"-rpath", "@loader_path/../lib",
"-Xlinker", "-dead_strip",
)
case "windows": // lld-link (Windows)
@@ -346,6 +346,8 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, llFiles
default: // ld.lld (Unix), wasm-ld (WebAssembly)
args = append(
args,
"-rpath", "$ORIGIN",
"-rpath", "$ORIGIN/../lib",
"-Xlinker", "--gc-sections",
"-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions.
)