mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-21 08:01:31 +00:00
Teaches go's internal linker to use the GO_LDSO env var as the path for the dynamic linker, instead of defaulting to an FHS /lib path. GO_LDSO is automatically set to the appropriate value by checking $NIX_CC/nix-support/dynamic-linker External linking is set as the default for cross compile situations where CGO is supported. Teaching go to correctly handle cross in the internal linker is hard, and our system linker already knows how to find the right ELF interpreter. For cross situations where CGO is not supported we assume either non-ELF binaries or static binaries will be produced.
45 lines
1.8 KiB
Diff
45 lines
1.8 KiB
Diff
diff --git a/src/cmd/dist/buildruntime.go b/src/cmd/dist/buildruntime.go
|
|
index 87e8867176..dbb635011f 100644
|
|
--- a/src/cmd/dist/buildruntime.go
|
|
+++ b/src/cmd/dist/buildruntime.go
|
|
@@ -62,7 +62,7 @@ func mkbuildcfg(file string) {
|
|
fmt.Fprintf(&buf, "const DefaultGORISCV64 = `%s`\n", goriscv64)
|
|
fmt.Fprintf(&buf, "const defaultGOEXPERIMENT = `%s`\n", goexperiment)
|
|
fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled)
|
|
- fmt.Fprintf(&buf, "const defaultGO_LDSO = `%s`\n", defaultldso)
|
|
+ fmt.Fprintf(&buf, "const DefaultGO_LDSO = `%s`\n", defaultldso)
|
|
fmt.Fprintf(&buf, "const version = `%s`\n", findgoversion())
|
|
fmt.Fprintf(&buf, "const defaultGOOS = runtime.GOOS\n")
|
|
fmt.Fprintf(&buf, "const defaultGOARCH = runtime.GOARCH\n")
|
|
diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go
|
|
index 6ff1d94383..147a7d91c9 100644
|
|
--- a/src/cmd/link/internal/ld/elf.go
|
|
+++ b/src/cmd/link/internal/ld/elf.go
|
|
@@ -1927,8 +1927,12 @@ func asmbElf(ctxt *Link) {
|
|
sh.Flags = uint64(elf.SHF_ALLOC)
|
|
sh.Addralign = 1
|
|
|
|
- if interpreter == "" && buildcfg.GOOS == runtime.GOOS && buildcfg.GOARCH == runtime.GOARCH && buildcfg.GO_LDSO != "" {
|
|
- interpreter = buildcfg.GO_LDSO
|
|
+ if interpreter == "" {
|
|
+ if goLdso := os.Getenv("GO_LDSO"); goLdso != "" {
|
|
+ interpreter = goLdso
|
|
+ } else if buildcfg.GOOS == runtime.GOOS && buildcfg.GOARCH == runtime.GOARCH {
|
|
+ interpreter = buildcfg.DefaultGO_LDSO
|
|
+ }
|
|
}
|
|
|
|
if interpreter == "" {
|
|
diff --git a/src/internal/buildcfg/cfg.go b/src/internal/buildcfg/cfg.go
|
|
index 7e4ee365df..8aaa70fb36 100644
|
|
--- a/src/internal/buildcfg/cfg.go
|
|
+++ b/src/internal/buildcfg/cfg.go
|
|
@@ -33,7 +33,6 @@ var (
|
|
GORISCV64 = goriscv64()
|
|
GOWASM = gowasm()
|
|
ToolTags = toolTags()
|
|
- GO_LDSO = defaultGO_LDSO
|
|
GOFIPS140 = gofips140()
|
|
Version = version
|
|
)
|