mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link/internal/ld: extract Mach-O load command parsing
We're going to need the ability to extract the LC_VERSION_MIN_* and LC_BUILD_VERSION load commands. This CL adds peekMachoPlatform to do that and in the process simplifies machoCombineDwarf. While here, disable DWARF combining for Apple platforms other than macOS (watchOS, tvOS, bridgeOS), not just iOS. Updates #22395 Change-Id: I4862b0f15ccc87b7be1a6532b4d37b47c8f7f243 Reviewed-on: https://go-review.googlesource.com/c/go/+/168459 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
ba965640a4
commit
0fe1986a72
3 changed files with 109 additions and 58 deletions
|
|
@ -44,6 +44,7 @@ import (
|
|||
"cmd/link/internal/sym"
|
||||
"crypto/sha1"
|
||||
"debug/elf"
|
||||
"debug/macho"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
|
|
@ -1449,11 +1450,24 @@ func (ctxt *Link) hostlink() {
|
|||
}
|
||||
// For os.Rename to work reliably, must be in same directory as outfile.
|
||||
combinedOutput := *flagOutfile + "~"
|
||||
isIOS, err := machoCombineDwarf(ctxt, *flagOutfile, dsym, combinedOutput)
|
||||
exef, err := os.Open(*flagOutfile)
|
||||
if err != nil {
|
||||
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
|
||||
}
|
||||
if !isIOS {
|
||||
defer exef.Close()
|
||||
exem, err := macho.NewFile(exef)
|
||||
if err != nil {
|
||||
Exitf("%s: parsing Mach-O header failed: %v", os.Args[0], err)
|
||||
}
|
||||
load, err := peekMachoPlatform(exem)
|
||||
if err != nil {
|
||||
Exitf("%s: failed to parse Mach-O load commands: %v", os.Args[0], err)
|
||||
}
|
||||
// Only macOS supports unmapped segments such as our __DWARF segment.
|
||||
if load == nil || load.platform == PLATFORM_MACOS {
|
||||
if err := machoCombineDwarf(ctxt, exef, exem, dsym, combinedOutput); err != nil {
|
||||
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
|
||||
}
|
||||
os.Remove(*flagOutfile)
|
||||
if err := os.Rename(combinedOutput, *flagOutfile); err != nil {
|
||||
Exitf("%s: %v", os.Args[0], err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue