diff options
| author | Cherry Mui <cherryyz@google.com> | 2021-09-29 16:47:12 -0400 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2021-09-30 16:43:32 +0000 |
| commit | 9112d296e84315a07d76a24874037448e2affdd7 (patch) | |
| tree | 1311878b8fd98bcb2e91695e78eab0ae6fd2411c /src/cmd/link | |
| parent | d4aed7e42cd187c3031350489dba814f29f215a5 (diff) | |
| download | go-9112d296e84315a07d76a24874037448e2affdd7.tar.xz | |
cmd/link: add runtime.text.N symbols to Mach-O symbol table
On Darwin/ARM64 when external linking, for very large text we
split it into multiple sections. For each section (other than the
first) we create runtime.text.N marker symbols. In CL 316050 I
forgot to add those symbols to the symbol table. This CL does it.
It doesn't actually matter for program execution. But we add them
on ELF when splitting text sections, so we do it here as well.
Also, this makes it easier to tell if we split text sections.
Change-Id: Ida7f8e9431867881e5ee2bc1a2129eeaf83cb878
Reviewed-on: https://go-review.googlesource.com/c/go/+/353209
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/link')
| -rw-r--r-- | src/cmd/link/internal/ld/ld_test.go | 18 | ||||
| -rw-r--r-- | src/cmd/link/internal/ld/macho.go | 8 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/cmd/link/internal/ld/ld_test.go b/src/cmd/link/internal/ld/ld_test.go index 3702a4d08f..2d5a7add9d 100644 --- a/src/cmd/link/internal/ld/ld_test.go +++ b/src/cmd/link/internal/ld/ld_test.go @@ -5,6 +5,7 @@ package ld import ( + "bytes" "debug/pe" "fmt" "internal/testenv" @@ -154,13 +155,22 @@ func TestLargeTextSectionSplitting(t *testing.T) { // is arbitrary; we just need something sufficiently large that uses // external linking. exe := filepath.Join(dir, "go.exe") - out, eerr := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, "-ldflags=-linkmode=external -debugtextsize=1048576", "cmd/go").CombinedOutput() - if eerr != nil { - t.Fatalf("build failure: %s\n%s\n", eerr, string(out)) + out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, "-ldflags=-linkmode=external -debugtextsize=1048576", "cmd/go").CombinedOutput() + if err != nil { + t.Fatalf("build failure: %s\n%s\n", err, string(out)) + } + + // Check that we did split text sections. + out, err = exec.Command(testenv.GoToolPath(t), "tool", "nm", exe).CombinedOutput() + if err != nil { + t.Fatalf("nm failure: %s\n%s\n", err, string(out)) + } + if !bytes.Contains(out, []byte("runtime.text.1")) { + t.Errorf("runtime.text.1 not found, text section not split?") } // Result should be runnable. - _, err := exec.Command(exe, "version").CombinedOutput() + _, err = exec.Command(exe, "version").CombinedOutput() if err != nil { t.Fatal(err) } diff --git a/src/cmd/link/internal/ld/macho.go b/src/cmd/link/internal/ld/macho.go index a577a5308d..8633222ee3 100644 --- a/src/cmd/link/internal/ld/macho.go +++ b/src/cmd/link/internal/ld/macho.go @@ -897,6 +897,14 @@ func collectmachosyms(ctxt *Link) { if ldr.SymType(s) == sym.STEXT { addsym(s) } + for n := range Segtext.Sections[1:] { + s := ldr.Lookup(fmt.Sprintf("runtime.text.%d", n+1), 0) + if s != 0 { + addsym(s) + } else { + break + } + } s = ldr.Lookup("runtime.etext", 0) if ldr.SymType(s) == sym.STEXT { addsym(s) |
