mirror of
https://github.com/golang/go
synced 2024-11-26 18:26:48 -07:00
cmd/link: suppress symbol table on Mach-O when -s
Currently, on Mach-O, we don't strip the symbol table even the -s flag is set. This CL makes it suppress the symbol table, as documented. On Mach-O, even with -s, we still need to keep symbols that are dynamically exported or referenced symbol. Otherwise the dynamic linker cannot resolve them and the binary doesn't run. (Interestingly, for a PIE binary it is okay to strip the symbol table entirely. We keep the dynamic symbols for consistency. And this is also in consistent with what the system "strip" command does.) Change-Id: I39c572553fe0215ae3bdf5349bf2bab7205fbdc9 Reviewed-on: https://go-review.googlesource.com/c/go/+/492744 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
3437ff0d7a
commit
1d84c89bec
@ -894,9 +894,14 @@ func collectmachosyms(ctxt *Link) {
|
||||
nkind[symkind(ldr, s)]++
|
||||
}
|
||||
|
||||
// Add special runtime.text and runtime.etext symbols.
|
||||
// On Mach-O, even with -s, we still need to keep dynamically exported and
|
||||
// referenced symbols. We can strip defined local text and data symbols.
|
||||
// So *FlagS is applied based on symbol type.
|
||||
|
||||
// Add special runtime.text and runtime.etext symbols (which are local).
|
||||
// We've already included this symbol in Textp on darwin if ctxt.DynlinkingGo().
|
||||
// See data.go:/textaddress
|
||||
if !*FlagS {
|
||||
if !ctxt.DynlinkingGo() {
|
||||
s := ldr.Lookup("runtime.text", 0)
|
||||
if ldr.SymType(s) == sym.STEXT {
|
||||
@ -915,9 +920,13 @@ func collectmachosyms(ctxt *Link) {
|
||||
addsym(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add text symbols.
|
||||
for _, s := range ctxt.Textp {
|
||||
if *FlagS && !ldr.AttrCgoExportDynamic(s) {
|
||||
continue
|
||||
}
|
||||
addsym(s)
|
||||
}
|
||||
|
||||
@ -946,11 +955,16 @@ func collectmachosyms(ctxt *Link) {
|
||||
if !shouldBeInSymbolTable(s) {
|
||||
continue
|
||||
}
|
||||
if *FlagS && !ldr.AttrCgoExportDynamic(s) {
|
||||
continue
|
||||
}
|
||||
addsym(s)
|
||||
continue
|
||||
}
|
||||
|
||||
switch t {
|
||||
case sym.SDYNIMPORT, sym.SHOSTOBJ, sym.SUNDEFEXT:
|
||||
// Keep dynamic symbol references even if *FlagS.
|
||||
addsym(s)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user