Skip to content

Commit

Permalink
universe/go: fix undefined __stack_chk_fail_local errors on x86
Browse files Browse the repository at this point in the history
[ commit ea935baf6775d139ddc1d894259c745949b33605 ]

See: golang/go#58385
  • Loading branch information
nmeum authored and konfetka1989 committed Apr 10, 2023
1 parent 279f88c commit b7110bd
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
From 066b780502c8c87c03f8a5e0bbc16c1c87221cf1 Mon Sep 17 00:00:00 2001
From: Than McIntosh <[email protected]>
Date: Mon, 12 Dec 2022 11:04:05 -0500
Subject: [PATCH] cmd/link: load host archive libc_nonshared.a for
-fstack-protector

For internal linking, at the point where we finish reading libgcc.a,
if the symbol "__stack_chk_local" is still undefined, then read
in the host archive libc_nonshared.a as well.

Updates #57261.

Change-Id: I0b1e485aa50aa7940db8cabcb3b9a7959bf99ce7
Reviewed-on: https://go-review.googlesource.com/c/go/+/456856
Reviewed-by: Cherry Mui <[email protected]>
Run-TryBot: Than McIntosh <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
---
src/cmd/link/internal/ld/lib.go | 19 +++++++++++++++++++
src/runtime/cgo/cgo.go | 4 +---
2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 3b34e40358..17df56f4d5 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -630,6 +630,25 @@ func (ctxt *Link) loadlib() {
}
if *flagLibGCC != "none" {
hostArchive(ctxt, *flagLibGCC)
+ // For glibc systems, the linker setup used by GCC
+ // looks like
+ //
+ // GROUP ( /lib/x86_64-linux-gnu/libc.so.6
+ // /usr/lib/x86_64-linux-gnu/libc_nonshared.a
+ // AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
+ //
+ // where libc_nonshared.a contains a small set of
+ // symbols including "__stack_chk_fail_local" and a
+ // few others. Thus if we are doing internal linking
+ // and "__stack_chk_fail_local" is unresolved (most
+ // likely due to the use of -fstack-protector), try
+ // loading libc_nonshared.a to resolve it.
+ isunresolved := symbolsAreUnresolved(ctxt, []string{"__stack_chk_fail_local"})
+ if isunresolved[0] {
+ if p := ctxt.findLibPath("libc_nonshared.a"); p != "none" {
+ hostArchive(ctxt, p)
+ }
+ }
}
}
}
diff --git a/src/runtime/cgo/cgo.go b/src/runtime/cgo/cgo.go
index b8473e532d..6d721bc8ff 100644
--- a/src/runtime/cgo/cgo.go
+++ b/src/runtime/cgo/cgo.go
@@ -23,9 +23,7 @@ package cgo
#cgo solaris LDFLAGS: -lxnet
#cgo solaris LDFLAGS: -lsocket

-// We use -fno-stack-protector because internal linking won't find
-// the support functions. See issues #52919 and #54313.
-#cgo CFLAGS: -Wall -Werror -fno-stack-protector
+#cgo CFLAGS: -Wall -Werror

#cgo solaris CPPFLAGS: -D_POSIX_PTHREAD_SEMANTICS

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From ba7066a1311a9a232e422e6dd2b82f18a5758750 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <[email protected]>
Date: Tue, 7 Feb 2023 16:39:36 +0100
Subject: [PATCH] cmd/link: check for libssp_nonshared.a instead of
libc_nonshared.a

See: https://github.com/golang/go/issues/58385
---
src/cmd/link/internal/ld/lib.go | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 17df56f4d5..f593dcd895 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -643,9 +643,11 @@ func (ctxt *Link) loadlib() {
// and "__stack_chk_fail_local" is unresolved (most
// likely due to the use of -fstack-protector), try
// loading libc_nonshared.a to resolve it.
+ //
+ // On Alpine, the library is called libssp_nonshared.a.
isunresolved := symbolsAreUnresolved(ctxt, []string{"__stack_chk_fail_local"})
if isunresolved[0] {
- if p := ctxt.findLibPath("libc_nonshared.a"); p != "none" {
+ if p := ctxt.findLibPath("libssp_nonshared.a"); p != "none" {
hostArchive(ctxt, p)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
From 379e6fa10c844dfb210d3de361a14edf833074b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <[email protected]>
Date: Tue, 7 Feb 2023 08:17:03 +0100
Subject: [PATCH] cmd/link: always check for __stack_chk_fail_local references

Otherwise, tests with `-libgcc none` fail on x86.

See: https://github.com/golang/go/issues/58385
---
src/cmd/link/internal/ld/lib.go | 40 ++++++++++++++++-----------------
1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index f593dcd895..d951e5f58a 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -630,26 +630,26 @@ func (ctxt *Link) loadlib() {
}
if *flagLibGCC != "none" {
hostArchive(ctxt, *flagLibGCC)
- // For glibc systems, the linker setup used by GCC
- // looks like
- //
- // GROUP ( /lib/x86_64-linux-gnu/libc.so.6
- // /usr/lib/x86_64-linux-gnu/libc_nonshared.a
- // AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
- //
- // where libc_nonshared.a contains a small set of
- // symbols including "__stack_chk_fail_local" and a
- // few others. Thus if we are doing internal linking
- // and "__stack_chk_fail_local" is unresolved (most
- // likely due to the use of -fstack-protector), try
- // loading libc_nonshared.a to resolve it.
- //
- // On Alpine, the library is called libssp_nonshared.a.
- isunresolved := symbolsAreUnresolved(ctxt, []string{"__stack_chk_fail_local"})
- if isunresolved[0] {
- if p := ctxt.findLibPath("libssp_nonshared.a"); p != "none" {
- hostArchive(ctxt, p)
- }
+ }
+ // For glibc systems, the linker setup used by GCC
+ // looks like
+ //
+ // GROUP ( /lib/x86_64-linux-gnu/libc.so.6
+ // /usr/lib/x86_64-linux-gnu/libc_nonshared.a
+ // AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
+ //
+ // where libc_nonshared.a contains a small set of
+ // symbols including "__stack_chk_fail_local" and a
+ // few others. Thus if we are doing internal linking
+ // and "__stack_chk_fail_local" is unresolved (most
+ // likely due to the use of -fstack-protector), try
+ // loading libc_nonshared.a to resolve it.
+ //
+ // On Alpine, the library is called libssp_nonshared.a.
+ isunresolved := symbolsAreUnresolved(ctxt, []string{"__stack_chk_fail_local"})
+ if isunresolved[0] {
+ if p := ctxt.findLibPath("libssp_nonshared.a"); p != "none" {
+ hostArchive(ctxt, p)
}
}
}
7 changes: 7 additions & 0 deletions universe/go/APKBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ makedepends="bash go-bootstrap"
checkdepends="binutils-gold"
subpackages="$pkgname-doc"
source="https://go.dev/dl/go$pkgver.src.tar.gz
0001-cmd-link-load-host-archive-libc_nonshared.a-for-fsta.patch
0002-cmd-link-check-for-libssp_nonshared.a-instead-of-lib.patch
0003-cmd-link-always-check-for-__stack_chk_fail_local-ref.patch
tests-filter-overflow-gid.patch
tests-unshare-enosys.patch
tests-unset-GCCGO.patch
Expand Down Expand Up @@ -244,6 +248,9 @@ package() {

sha512sums="
6b59af1094fafbf2dba6b26a5da0c6363d87b0997dd399cde40d9150e00bedd15100c0c8c12e31cfe7e153d2ea45b403764b2d83479d1cda74077179c8cca4d3 go1.20.src.tar.gz
92a4387378773d990d05fc3ed9a57360bc9eb5ec09c1faabd6c252203873abe18ef1ce4c399e78ec6fd4e911e6cdb2c4b2ebb778aaeeaabe0d55710a0415d445 0001-cmd-link-load-host-archive-libc_nonshared.a-for-fsta.patch
17ae436672c166d353d653cf012cbb70093ce03c1520af956927b42afe4b9d789923882aa97e7050f4984db8aa039e90cc107a78e0b4d4f1964a2b456d97b50b 0002-cmd-link-check-for-libssp_nonshared.a-instead-of-lib.patch
d819281963368932d937d2768fb4cbabfec7f5c1d318c73538174875f6510500c0427037c2f4090ff32e4f150ffe362aaef86287ac32b6045468842454628091 0003-cmd-link-always-check-for-__stack_chk_fail_local-ref.patch
9f656adb00d174aeae3fc09eeeba1931a290e8cf9e1d3f5e0f232dcf121d45dba04210f88afbb3915b0d7e21dad5c165de9307f4b53e33ba718d312153391571 tests-filter-overflow-gid.patch
6017caacf77c2911e9e882878fdaa2ed066b76b7e97b2ad776bc33d96b21cabc802966473946642c86a8f985c69adcc5e7ea61684f6d0dbacd468a6aad687229 tests-unshare-enosys.patch
4f3f9dfca1d5b9e8219475aea4b25784c7d9c65ade69e38df4210d8c0115fa62771ff44033bca26b4e53f4efcb350aa9fbbddb69780cdef47000a505ea81a79a tests-unset-GCCGO.patch
Expand Down

0 comments on commit b7110bd

Please sign in to comment.