mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-21 18:25:41 +03:00
67 lines
2.4 KiB
Diff
67 lines
2.4 KiB
Diff
From 066b780502c8c87c03f8a5e0bbc16c1c87221cf1 Mon Sep 17 00:00:00 2001
|
|
From: Than McIntosh <thanm@google.com>
|
|
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 <cherryyz@google.com>
|
|
Run-TryBot: Than McIntosh <thanm@google.com>
|
|
TryBot-Result: Gopher Robot <gobot@golang.org>
|
|
---
|
|
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
|
|
|