Merge pull request #1234 from visualfc/rpath

internal/build: fix warning duplicate -rpath
This commit is contained in:
xushiwei
2025-08-26 13:56:44 +08:00
committed by GitHub

View File

@@ -740,16 +740,20 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, global l
} }
if IsFullRpathEnabled() { if IsFullRpathEnabled() {
exargs := make([]string, 0, ctx.nLibdir<<1)
// Treat every link-time library search path, specified by the -L parameter, as a runtime search path as well. // Treat every link-time library search path, specified by the -L parameter, as a runtime search path as well.
// This is to ensure the final executable can locate libraries with a relocatable install_name // This is to ensure the final executable can locate libraries with a relocatable install_name
// (e.g., "@rpath/libfoo.dylib") at runtime. // (e.g., "@rpath/libfoo.dylib") at runtime.
rpaths := make(map[string]none)
for _, arg := range linkArgs { for _, arg := range linkArgs {
if strings.HasPrefix(arg, "-L") { if strings.HasPrefix(arg, "-L") {
exargs = append(exargs, "-rpath", arg[2:]) path := arg[2:]
if _, ok := rpaths[path]; ok {
continue
}
rpaths[path] = none{}
linkArgs = append(linkArgs, "-rpath", path)
} }
} }
linkArgs = append(linkArgs, exargs...)
} }
err = linkObjFiles(ctx, orgApp, objFiles, linkArgs, verbose) err = linkObjFiles(ctx, orgApp, objFiles, linkArgs, verbose)