mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/ld: put read-only relocated data into .data.rel.ro when making a shared object
Currently Go produces shared libraries that cannot be shared between processes because they have relocations against the text segment (not text section). This fixes this by moving some data to sections with magic names recognized by the static linker. The change in genasmsym to add STYPELINK to the switch should fix things on darwin/arm64. Fixes #10914 Updates #9210 Change-Id: Iab4a6678dd04cec6114e683caac5cf31b1063309 Reviewed-on: https://go-review.googlesource.com/14306 Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
14f919578d
commit
5cbca8d84b
13 changed files with 207 additions and 18 deletions
|
|
@ -174,6 +174,12 @@ func DynlinkingGo() bool {
|
|||
return Buildmode == BuildmodeShared || Linkshared
|
||||
}
|
||||
|
||||
// UseRelro returns whether to make use of "read only relocations" aka
|
||||
// relro.
|
||||
func UseRelro() bool {
|
||||
return (Buildmode == BuildmodeCShared || Buildmode == BuildmodeShared) && Iself
|
||||
}
|
||||
|
||||
var (
|
||||
Thestring string
|
||||
Thelinkarch *LinkArch
|
||||
|
|
@ -980,6 +986,9 @@ func hostlink() {
|
|||
argv = append(argv, "-dynamiclib")
|
||||
} else {
|
||||
argv = append(argv, "-Wl,-Bsymbolic")
|
||||
if UseRelro() {
|
||||
argv = append(argv, "-Wl,-z,relro")
|
||||
}
|
||||
argv = append(argv, "-shared")
|
||||
}
|
||||
case BuildmodeShared:
|
||||
|
|
@ -991,7 +1000,10 @@ func hostlink() {
|
|||
// think we may well end up wanting to use -Bsymbolic here
|
||||
// anyway.
|
||||
argv = append(argv, "-Wl,-Bsymbolic-functions")
|
||||
argv = append(argv, "-shared")
|
||||
if UseRelro() {
|
||||
argv = append(argv, "-shared")
|
||||
}
|
||||
argv = append(argv, "-Wl,-z,relro")
|
||||
}
|
||||
|
||||
if Linkshared && Iself {
|
||||
|
|
@ -1771,6 +1783,13 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
|
|||
obj.SGOSTRING,
|
||||
obj.SGOFUNC,
|
||||
obj.SGCBITS,
|
||||
obj.STYPERELRO,
|
||||
obj.SSTRINGRELRO,
|
||||
obj.SGOSTRINGRELRO,
|
||||
obj.SGOFUNCRELRO,
|
||||
obj.SGCBITSRELRO,
|
||||
obj.SRODATARELRO,
|
||||
obj.STYPELINK,
|
||||
obj.SWINDOWS:
|
||||
if !s.Reachable {
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue