Attention is currently required from: Ian Lance Taylor, Russ Cox.
Patch set 1:Code-Review +2
2 comments:
Patchset:
R=go1.20
File src/cmd/link/internal/ld/elf.go:
Patch Set #1, Line 1792: case "/lib/ld-linux-x86-64.so.2":
Is this only needed for amd64? I think musl supports other platforms, e.g. ppc64le. Do they use the same dynamic interpreter path as glibc there?
Another possibility is maybe to turn thearch.Linuxdynld into a list, and we can use the first one that works. That might make pre-architecture settings easier.
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Russ Cox.
1 comment:
Patchset:
I think this is probably a good idea. Thanks.
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Cherry Mui, Ian Lance Taylor, Russ Cox.
1 comment:
File src/cmd/link/internal/ld/elf.go:
Patch Set #1, Line 1792: case "/lib/ld-linux-x86-64.so.2":
Is this only needed for amd64? I think musl supports other platforms, e.g. ppc64le. […]
There are musl users on ppc64le. The path to the musl interpreter is not the same as glibc.
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Lynn Boger, Russ Cox.
Patch set 2:Code-Review +2
2 comments:
Patchset:
LGTM, thanks.
File src/cmd/link/internal/ld/elf.go:
Patch Set #1, Line 1792: case "/lib/ld-linux-x86-64.so.2":
Thanks. I have added all the architectures using Ian's comment at […]
ARM64 seems not added.
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
Patchset:
This needs the fix in CL 417614, the path should be ld64.so.2 for ppc64le.
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
File src/cmd/link/internal/ppc64/obj.go:
Patch Set #3, Line 45: musl = "/lib/ld-musl-powerpcle.so.1"
This should be /lib/ld-musl-powerpc64le.so.1.
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
File src/cmd/link/internal/ppc64/obj.go:
Patch Set #3, Line 45: powerpcle
I think this should be /lib/ld-musl-powerpc64le.so.1 based on what I see in alpine today. I am guessing ppc64 should be /lib/ld-musl-powerpc64.so.1 too, but I can't confirm.
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Cherry Mui, Lynn Boger, Paul Murphy, Russ Cox.
1 comment:
File src/cmd/link/internal/ld/elf.go:
Patch Set #1, Line 1792: case "/lib/ld-linux-x86-64.so.2":
Added ARM64, thanks. Will wait to hear from Lynn about ppc64 and ppc64le.
Done
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
Gopher Robot submitted this change.
2 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: src/cmd/link/internal/arm64/obj.go
Insertions: 3, Deletions: 2.
The diff is too large to show. Please review the diff.
```
```
The name of the file: src/cmd/link/internal/ppc64/obj.go
Insertions: 9, Deletions: 7.
The diff is too large to show. Please review the diff.
```
cmd/link: detect glibc vs musl ldso at link time
Doing the test at link time lets us distribute one Linux toolchain
that works on both glibc-based and musl-based Linux systems.
The old way built a toolchain that only ran on one or the other.
Fixes #54197.
Change-Id: Iaae8c274c78e1091eee828a720b49646be9bfffe
Reviewed-on: https://go-review.googlesource.com/c/go/+/420774
Auto-Submit: Russ Cox <r...@golang.org>
Reviewed-by: Cherry Mui <cher...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Run-TryBot: Russ Cox <r...@golang.org>
---
M src/cmd/link/internal/amd64/obj.go
M src/cmd/link/internal/arm/obj.go
M src/cmd/link/internal/arm64/obj.go
M src/cmd/link/internal/ld/elf.go
M src/cmd/link/internal/ld/lib.go
M src/cmd/link/internal/loong64/obj.go
M src/cmd/link/internal/mips/obj.go
M src/cmd/link/internal/mips64/obj.go
M src/cmd/link/internal/ppc64/obj.go
M src/cmd/link/internal/s390x/obj.go
M src/cmd/link/internal/x86/obj.go
M src/make.bash
12 files changed, 57 insertions(+), 18 deletions(-)
diff --git a/src/cmd/link/internal/amd64/obj.go b/src/cmd/link/internal/amd64/obj.go
index d09c90e..f46045b 100644
--- a/src/cmd/link/internal/amd64/obj.go
+++ b/src/cmd/link/internal/amd64/obj.go
@@ -65,6 +65,7 @@
TLSIEtoLE: tlsIEtoLE,
Linuxdynld: "/lib64/ld-linux-x86-64.so.2",
+ LinuxdynldMusl: "/lib/ld-musl-x84_64.so.1",
Freebsddynld: "/libexec/ld-elf.so.1",
Openbsddynld: "/usr/libexec/ld.so",
Netbsddynld: "/libexec/ld.elf_so",
diff --git a/src/cmd/link/internal/arm/obj.go b/src/cmd/link/internal/arm/obj.go
index b7d1498..6da0c77 100644
--- a/src/cmd/link/internal/arm/obj.go
+++ b/src/cmd/link/internal/arm/obj.go
@@ -63,6 +63,7 @@
PEreloc1: pereloc1,
Linuxdynld: "/lib/ld-linux.so.3", // 2 for OABI, 3 for EABI
+ LinuxdynldMusl: "/lib/ld-musl-arm.so.1",
Freebsddynld: "/usr/libexec/ld-elf.so.1",
Openbsddynld: "/usr/libexec/ld.so",
Netbsddynld: "/libexec/ld.elf_so",
diff --git a/src/cmd/link/internal/arm64/obj.go b/src/cmd/link/internal/arm64/obj.go
index 9c74598..a47be0b 100644
--- a/src/cmd/link/internal/arm64/obj.go
+++ b/src/cmd/link/internal/arm64/obj.go
@@ -62,8 +62,9 @@
PEreloc1: pereloc1,
Trampoline: trampoline,
- Androiddynld: "/system/bin/linker64",
- Linuxdynld: "/lib/ld-linux-aarch64.so.1",
+ Androiddynld: "/system/bin/linker64",
+ Linuxdynld: "/lib/ld-linux-aarch64.so.1",
+ LinuxdynldMusl: "/lib/ld-musl-aarch64.so.1",
Freebsddynld: "/usr/libexec/ld-elf.so.1",
Openbsddynld: "/usr/libexec/ld.so",
diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go
index 2566ded..040978e 100644
--- a/src/cmd/link/internal/ld/elf.go
+++ b/src/cmd/link/internal/ld/elf.go
@@ -15,6 +15,7 @@
"encoding/hex"
"fmt"
"internal/buildcfg"
+ "os"
"path/filepath"
"runtime"
"sort"
@@ -1782,6 +1783,16 @@
}
} else {
interpreter = thearch.Linuxdynld
+ // If interpreter does not exist, try musl instead.
+ // This lets the same cmd/link binary work on
+ // both glibc-based and musl-based systems.
+ if _, err := os.Stat(interpreter); err != nil {
+ if musl := thearch.LinuxdynldMusl; musl != "" {
+ if _, err := os.Stat(musl); err == nil {
+ interpreter = musl
+ }
+ }
+ }
}
case objabi.Hfreebsd:
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 18910dd..c265d73 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -183,6 +183,7 @@
Androiddynld string
Linuxdynld string
+ LinuxdynldMusl string
Freebsddynld string
Netbsddynld string
Openbsddynld string
diff --git a/src/cmd/link/internal/loong64/obj.go b/src/cmd/link/internal/loong64/obj.go
index b564dfd..0a5bb0a 100644
--- a/src/cmd/link/internal/loong64/obj.go
+++ b/src/cmd/link/internal/loong64/obj.go
@@ -31,6 +31,7 @@
Gentext: gentext,
Linuxdynld: "/lib64/ld.so.1",
+ LinuxdynldMusl: "/lib64/ld-musl-loongarch.so.1",
Freebsddynld: "XXX",
Openbsddynld: "XXX",
Netbsddynld: "XXX",
diff --git a/src/cmd/link/internal/mips/obj.go b/src/cmd/link/internal/mips/obj.go
index 5ca7582..f03c9ab 100644
--- a/src/cmd/link/internal/mips/obj.go
+++ b/src/cmd/link/internal/mips/obj.go
@@ -39,8 +39,10 @@
func Init() (*sys.Arch, ld.Arch) {
arch := sys.ArchMIPS
+ musl := "/lib/ld-musl-mips.so.1"
if buildcfg.GOARCH == "mipsle" {
arch = sys.ArchMIPSLE
+ musl = "/lib/ld-musl-mipsel.so.1"
}
theArch := ld.Arch{
@@ -60,7 +62,8 @@
Gentext: gentext,
Machoreloc1: machoreloc1,
- Linuxdynld: "/lib/ld.so.1",
+ Linuxdynld: "/lib/ld.so.1",
+ LinuxdynldMusl: musl,
Freebsddynld: "XXX",
Openbsddynld: "XXX",
diff --git a/src/cmd/link/internal/mips64/obj.go b/src/cmd/link/internal/mips64/obj.go
index 544e1ef..557d799 100644
--- a/src/cmd/link/internal/mips64/obj.go
+++ b/src/cmd/link/internal/mips64/obj.go
@@ -39,8 +39,10 @@
func Init() (*sys.Arch, ld.Arch) {
arch := sys.ArchMIPS64
+ musl := "/lib/ld-musl-mips64.so.1"
if buildcfg.GOARCH == "mips64le" {
arch = sys.ArchMIPS64LE
+ musl = "/lib/ld-musl-mips64el.so.1"
}
theArch := ld.Arch{
@@ -60,6 +62,7 @@
Machoreloc1: machoreloc1,
Linuxdynld: "/lib64/ld64.so.1",
+ LinuxdynldMusl: musl,
Freebsddynld: "XXX",
Openbsddynld: "/usr/libexec/ld.so",
Netbsddynld: "XXX",
diff --git a/src/cmd/link/internal/ppc64/obj.go b/src/cmd/link/internal/ppc64/obj.go
index bca8fa9..f580c55 100644
--- a/src/cmd/link/internal/ppc64/obj.go
+++ b/src/cmd/link/internal/ppc64/obj.go
@@ -40,10 +40,12 @@
func Init() (*sys.Arch, ld.Arch) {
arch := sys.ArchPPC64LE
dynld := "/lib64/ld64.so.2"
+ musl := "/lib/ld-musl-powerpc64le.so.1"
if buildcfg.GOARCH == "ppc64" {
arch = sys.ArchPPC64
dynld = "/lib64/ld64.so.1"
+ musl = "/lib/ld-musl-powerpc64.so.1"
}
theArch := ld.Arch{
@@ -68,6 +70,8 @@
Xcoffreloc1: xcoffreloc1,
Linuxdynld: dynld,
+ LinuxdynldMusl: musl,
+
Freebsddynld: "XXX",
Openbsddynld: "XXX",
Netbsddynld: "XXX",
diff --git a/src/cmd/link/internal/s390x/obj.go b/src/cmd/link/internal/s390x/obj.go
index 8acc1d4..3aa8948 100644
--- a/src/cmd/link/internal/s390x/obj.go
+++ b/src/cmd/link/internal/s390x/obj.go
@@ -56,7 +56,8 @@
Gentext: gentext,
Machoreloc1: machoreloc1,
- Linuxdynld: "/lib64/ld64.so.1",
+ Linuxdynld: "/lib64/ld64.so.1",
+ LinuxdynldMusl: "/lib/ld-musl-s390x.so.1",
// not relevant for s390x
Freebsddynld: "XXX",
diff --git a/src/cmd/link/internal/x86/obj.go b/src/cmd/link/internal/x86/obj.go
index a19437d..b0a129e 100644
--- a/src/cmd/link/internal/x86/obj.go
+++ b/src/cmd/link/internal/x86/obj.go
@@ -61,11 +61,12 @@
Machoreloc1: machoreloc1,
PEreloc1: pereloc1,
- Linuxdynld: "/lib/ld-linux.so.2",
- Freebsddynld: "/usr/libexec/ld-elf.so.1",
- Openbsddynld: "/usr/libexec/ld.so",
- Netbsddynld: "/usr/libexec/ld.elf_so",
- Solarisdynld: "/lib/ld.so.1",
+ Linuxdynld: "/lib/ld-linux.so.2",
+ LinuxdynldMusl: "/lib/ld-musl-i386.so.1",
+ Freebsddynld: "/usr/libexec/ld-elf.so.1",
+ Openbsddynld: "/usr/libexec/ld.so",
+ Netbsddynld: "/usr/libexec/ld.elf_so",
+ Solarisdynld: "/lib/ld.so.1",
}
return arch, theArch
diff --git a/src/make.bash b/src/make.bash
index ab2ce19..54bb070 100755
--- a/src/make.bash
+++ b/src/make.bash
@@ -133,15 +133,6 @@
export CGO_ENABLED=0
fi
-# Test which linker/loader our system is using, if GO_LDSO is not set.
-if [ -z "$GO_LDSO" ] && type readelf >/dev/null 2>&1; then
- if echo "int main() { return 0; }" | ${CC:-cc} -o ./test-musl-ldso -x c - >/dev/null 2>&1; then
- LDSO=$(readelf -l ./test-musl-ldso | grep 'interpreter:' | sed -e 's/^.*interpreter: \(.*\)[]]/\1/') >/dev/null 2>&1
- [ -z "$LDSO" ] || export GO_LDSO="$LDSO"
- rm -f ./test-musl-ldso
- fi
-fi
-
# Clean old generated file that will cause problems in the build.
rm -f ./runtime/runtime_defs.go
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patchset:
To view, visit change 420774. To unsubscribe, or for help writing mail filters, visit settings.