From b3336ef5ab0fe6557ebcc062ae8867d28a91b769 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 20 Jun 2019 09:02:05 -0400 Subject: [release-branch.go1.11] cmd/link: revise previous __DWARF segment protection fix Tweak the previous fix for issue 32673 (in CL 182958) to work around problems with c-shared build mode that crop up on some of the builders (10.11, 10.12). We now consistently set vmaddr and vmsize to zero for the DWARF segment regardless of build mode. Fixes #32696. Change-Id: Id1fc213590ad00c28352925e2d754d760e022b5e Reviewed-on: https://go-review.googlesource.com/c/go/+/183237 Reviewed-by: Cherry Zhang Reviewed-by: David Chase Reviewed-on: https://go-review.googlesource.com/c/go/+/183400 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/link/internal/ld/macho_combine_dwarf.go | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cmd/link/internal/ld/macho_combine_dwarf.go b/src/cmd/link/internal/ld/macho_combine_dwarf.go index 7d33f75b54..8c80576371 100644 --- a/src/cmd/link/internal/ld/macho_combine_dwarf.go +++ b/src/cmd/link/internal/ld/macho_combine_dwarf.go @@ -265,7 +265,7 @@ func machoCombineDwarf(ctxt *Link, inexe, dsym, outexe string) (bool, error) { } } // Do the final update of the DWARF segment's load command. - return false, machoUpdateDwarfHeader(&reader, ctxt.BuildMode, compressedSects) + return false, machoUpdateDwarfHeader(&reader, compressedSects, dwarfsize) } // machoCompressSections tries to compress the DWARF segments in dwarfm, @@ -410,7 +410,7 @@ func machoUpdateSections(r loadCmdReader, seg, sect reflect.Value, deltaOffset, } // machoUpdateDwarfHeader updates the DWARF segment load command. -func machoUpdateDwarfHeader(r *loadCmdReader, buildmode BuildMode, compressedSects []*macho.Section) error { +func machoUpdateDwarfHeader(r *loadCmdReader, compressedSects []*macho.Section, dwarfsize uint64) error { var seg, sect interface{} cmd, err := r.Next() if err != nil { @@ -428,8 +428,6 @@ func machoUpdateDwarfHeader(r *loadCmdReader, buildmode BuildMode, compressedSec } segv := reflect.ValueOf(seg).Elem() segv.FieldByName("Offset").SetUint(uint64(dwarfstart)) - segv.FieldByName("Addr").SetUint(uint64(dwarfaddr)) - segv.FieldByName("Prot").SetUint(0) if compressedSects != nil { var segSize uint64 @@ -437,23 +435,27 @@ func machoUpdateDwarfHeader(r *loadCmdReader, buildmode BuildMode, compressedSec segSize += newSect.Size } segv.FieldByName("Filesz").SetUint(segSize) - segv.FieldByName("Memsz").SetUint(uint64(Rnd(int64(segSize), 1<