Commit 7bdb4a28 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

Revert "cmd/internal/ld: output dwarf in external link mode on darwin"

This reverts commit 8b83306c.

Change-Id: I3fb998bdf11eceef13e3997e336d86e7c5d47a60
Reviewed-on: https://go-review.googlesource.com/10254Reviewed-by: default avatarMinux Ma <minux@golang.org>
parent c013417a
......@@ -533,12 +533,14 @@ func asmb() {
fmt.Fprintf(&ld.Bso, "%5.2f dwarf\n", obj.Cputime())
}
dwarfoff := uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Length), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)))
ld.Cseek(int64(dwarfoff))
if ld.Debug['w'] == 0 { // TODO(minux): enable DWARF Support
dwarfoff := uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Length), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)))
ld.Cseek(int64(dwarfoff))
ld.Segdwarf.Fileoff = uint64(ld.Cpos())
ld.Dwarfemitdebugsections()
ld.Segdwarf.Filelen = uint64(ld.Cpos()) - ld.Segdwarf.Fileoff
ld.Segdwarf.Fileoff = uint64(ld.Cpos())
ld.Dwarfemitdebugsections()
ld.Segdwarf.Filelen = uint64(ld.Cpos()) - ld.Segdwarf.Fileoff
}
machlink = uint32(ld.Domacholink())
}
......@@ -565,7 +567,7 @@ func asmb() {
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Filelen), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)) + int64(machlink))
}
ld.Cseek(int64(symo))
......
......@@ -710,7 +710,7 @@ func asmb() {
symo = int64(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = int64(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = int64(ld.Segdata.Fileoff + uint64(ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND))) + uint64(machlink))
case obj.Hlinux,
obj.Hfreebsd,
......
......@@ -317,12 +317,14 @@ func asmb() {
fmt.Fprintf(&ld.Bso, "%5.2f dwarf\n", obj.Cputime())
}
dwarfoff := uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Length), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)))
ld.Cseek(int64(dwarfoff))
if ld.Debug['w'] == 0 { // TODO(minux): enable DWARF Support
dwarfoff := uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Length), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)))
ld.Cseek(int64(dwarfoff))
ld.Segdwarf.Fileoff = uint64(ld.Cpos())
ld.Dwarfemitdebugsections()
ld.Segdwarf.Filelen = uint64(ld.Cpos()) - ld.Segdwarf.Fileoff
ld.Segdwarf.Fileoff = uint64(ld.Cpos())
ld.Dwarfemitdebugsections()
ld.Segdwarf.Filelen = uint64(ld.Cpos()) - ld.Segdwarf.Fileoff
}
machlink = uint32(ld.Domacholink())
}
......@@ -349,7 +351,7 @@ func asmb() {
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Filelen), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)) + int64(machlink))
}
ld.Cseek(int64(symo))
......
......@@ -551,7 +551,7 @@ func asmb() {
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case obj.Hdarwin:
symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(ld.INITRND))) + uint64(machlink))
symo = uint32(ld.Segdata.Fileoff + uint64(ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND))) + uint64(machlink))
case obj.Hwindows:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
......
......@@ -17,7 +17,6 @@ package ld
import (
"cmd/internal/obj"
"fmt"
"os"
"strings"
)
......@@ -241,7 +240,6 @@ var abbrevs = [DW_NABRV]DWAbbrev{
{DW_AT_low_pc, DW_FORM_addr},
{DW_AT_high_pc, DW_FORM_addr},
{DW_AT_stmt_list, DW_FORM_data4},
{DW_AT_comp_dir, DW_FORM_string},
},
},
......@@ -696,9 +694,6 @@ func adddwarfrel(sec *LSym, sym *LSym, offsetbase int64, siz int, addend int64)
if Iself && Thearch.Thechar == '6' {
addend = 0
}
if HEADTYPE == obj.Hdarwin {
addend += sym.Value
}
switch siz {
case 4:
Thearch.Lput(uint32(addend))
......@@ -1552,13 +1547,6 @@ func flushunit(dwinfo *DWDie, pc int64, pcsym *LSym, unitstart int64, header_len
}
}
func getCompilationDir() string {
if dir, err := os.Getwd(); err == nil {
return dir
}
return "/"
}
func writelines() {
if linesec == nil {
linesec = Linklookup(Ctxt, ".dwarfline", 0)
......@@ -1583,9 +1571,6 @@ func writelines() {
newattr(dwinfo, DW_AT_language, DW_CLS_CONSTANT, int64(lang), 0)
newattr(dwinfo, DW_AT_stmt_list, DW_CLS_PTR, unitstart-lineo, 0)
newattr(dwinfo, DW_AT_low_pc, DW_CLS_ADDRESS, s.Value, s)
// OS X linker requires compilation dir or absolute path in comp unit name to output debug info.
compDir := getCompilationDir()
newattr(dwinfo, DW_AT_comp_dir, DW_CLS_STRING, int64(len(compDir)), compDir)
// Write .debug_line Line Number Program Header (sec 6.2.4)
// Fields marked with (*) must be changed for 64-bit dwarf
......@@ -2098,14 +2083,6 @@ func writedwarfreloc(s *LSym) int64 {
return start
}
func addmachodwarfsect(prev *Section, name string) *Section {
sect := addsection(&Segdwarf, name, 04)
sect.Extnum = prev.Extnum + 1
sym := Linklookup(Ctxt, name, 0)
sym.Sect = sect
return sect
}
/*
* This is the main entry point for generating dwarf. After emitting
* the mandatory debug_abbrev section, it calls writelines() to set up
......@@ -2120,32 +2097,8 @@ func Dwarfemitdebugsections() {
return
}
if Linkmode == LinkExternal {
if !Iself && HEADTYPE != obj.Hdarwin {
return
}
if HEADTYPE == obj.Hdarwin {
sect := Segdata.Sect
// find the last section.
for sect.Next != nil {
sect = sect.Next
}
sect = addmachodwarfsect(sect, ".debug_abbrev")
sect = addmachodwarfsect(sect, ".debug_line")
sect = addmachodwarfsect(sect, ".debug_frame")
sect = addmachodwarfsect(sect, ".debug_info")
}
infosym = Linklookup(Ctxt, ".debug_info", 0)
infosym.Hide = 1
abbrevsym = Linklookup(Ctxt, ".debug_abbrev", 0)
abbrevsym.Hide = 1
linesym = Linklookup(Ctxt, ".debug_line", 0)
linesym.Hide = 1
framesym = Linklookup(Ctxt, ".debug_frame", 0)
framesym.Hide = 1
if Linkmode == LinkExternal && !Iself {
return
}
// For diagnostic messages.
......@@ -2238,15 +2191,6 @@ func Dwarfemitdebugsections() {
for Cpos()&7 != 0 {
Cput(0)
}
if HEADTYPE != obj.Hdarwin {
dwarfemitreloc()
}
}
func dwarfemitreloc() {
if Debug['w'] != 0 { // disable dwarf
return
}
inforeloco = writedwarfreloc(infosec)
inforelocsize = Cpos() - inforeloco
align(inforelocsize)
......@@ -2319,6 +2263,18 @@ func dwarfaddshstrings(shstrtab *LSym) {
elfstrdbg[ElfStrRelDebugLine] = Addstring(shstrtab, ".rel.debug_line")
elfstrdbg[ElfStrRelDebugFrame] = Addstring(shstrtab, ".rel.debug_frame")
}
infosym = Linklookup(Ctxt, ".debug_info", 0)
infosym.Hide = 1
abbrevsym = Linklookup(Ctxt, ".debug_abbrev", 0)
abbrevsym.Hide = 1
linesym = Linklookup(Ctxt, ".debug_line", 0)
linesym.Hide = 1
framesym = Linklookup(Ctxt, ".debug_frame", 0)
framesym.Hide = 1
}
}
......@@ -2464,15 +2420,14 @@ func dwarfaddelfheaders() {
/*
* Macho
*/
func dwarfaddmachoheaders(ms *MachoSeg) {
func dwarfaddmachoheaders() {
if Debug['w'] != 0 { // disable dwarf
return
}
// Zero vsize segments won't be loaded in memory, even so they
// have to be page aligned in the file.
fakestart := Rnd(int64(Segdwarf.Fileoff), 0x1000)
addr := Segdata.Vaddr + Segdata.Length
fakestart := abbrevo &^ 0xfff
nsect := 4
if pubnamessize > 0 {
......@@ -2488,94 +2443,57 @@ func dwarfaddmachoheaders(ms *MachoSeg) {
nsect++
}
if Linkmode != LinkExternal {
ms = newMachoSeg("__DWARF", nsect)
ms.fileoffset = uint64(fakestart)
ms.filesize = Segdwarf.Filelen
ms.vaddr = addr
}
ms := newMachoSeg("__DWARF", nsect)
ms.fileoffset = uint64(fakestart)
ms.filesize = uint64(abbrevo) - uint64(fakestart)
ms.vaddr = ms.fileoffset + Segdata.Vaddr - Segdata.Fileoff
msect := newMachoSect(ms, "__debug_abbrev", "__DWARF")
msect.off = uint32(abbrevo)
msect.size = uint64(abbrevsize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
if abbrevsym != nil {
abbrevsym.Value = int64(msect.addr)
}
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
msect = newMachoSect(ms, "__debug_line", "__DWARF")
msect.off = uint32(lineo)
msect.size = uint64(linesize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
if linesym != nil {
linesym.Value = int64(msect.addr)
}
if linerelocsize > 0 {
msect.nreloc = uint32(len(linesec.R))
msect.reloc = uint32(linereloco)
}
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
msect = newMachoSect(ms, "__debug_frame", "__DWARF")
msect.off = uint32(frameo)
msect.size = uint64(framesize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
if framesym != nil {
framesym.Value = int64(msect.addr)
}
if framerelocsize > 0 {
msect.nreloc = uint32(len(framesec.R))
msect.reloc = uint32(framereloco)
}
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
msect = newMachoSect(ms, "__debug_info", "__DWARF")
msect.off = uint32(infoo)
msect.size = uint64(infosize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
if infosym != nil {
infosym.Value = int64(msect.addr)
}
if inforelocsize > 0 {
msect.nreloc = uint32(len(infosec.R))
msect.reloc = uint32(inforeloco)
}
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
if pubnamessize > 0 {
msect := newMachoSect(ms, "__debug_pubnames", "__DWARF")
msect.off = uint32(pubnameso)
msect.size = uint64(pubnamessize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
}
if pubtypessize > 0 {
msect := newMachoSect(ms, "__debug_pubtypes", "__DWARF")
msect.off = uint32(pubtypeso)
msect.size = uint64(pubtypessize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
}
if arangessize > 0 {
msect := newMachoSect(ms, "__debug_aranges", "__DWARF")
msect.off = uint32(arangeso)
msect.size = uint64(arangessize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
if arangesrelocsize > 0 {
msect.nreloc = uint32(len(arangessec.R))
msect.reloc = uint32(arangesreloco)
}
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
}
// TODO(lvd) fix gdb/python to load MachO (16 char section name limit)
......@@ -2583,9 +2501,8 @@ func dwarfaddmachoheaders(ms *MachoSeg) {
msect := newMachoSect(ms, "__debug_gdb_scripts", "__DWARF")
msect.off = uint32(gdbscripto)
msect.size = uint64(gdbscriptsize)
msect.addr = addr
addr += msect.size
msect.flag = 0x02000000
msect.addr = uint64(msect.off) + Segdata.Vaddr - Segdata.Fileoff
ms.filesize += msect.size
}
}
......
......@@ -922,7 +922,7 @@ func hostlink() {
}
if HEADTYPE == obj.Hdarwin {
argv = append(argv, "-Wl,-no_pie,-pagezero_size,4000000,-headerpad,1144")
argv = append(argv, "-Wl,-no_pie,-pagezero_size,4000000")
}
if HEADTYPE == obj.Hopenbsd {
argv = append(argv, "-Wl,-nopie")
......@@ -1029,25 +1029,6 @@ func hostlink() {
if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil {
Exitf("running %s failed: %v\n%s", argv[0], err, out)
}
if Debug['s'] == 0 && debug_s == 0 && HEADTYPE == obj.Hdarwin {
dsym := fmt.Sprintf("%s/go.dwarf", tmpdir)
if out, err := exec.Command("dsymutil", "-f", outfile, "-o", dsym).CombinedOutput(); err != nil {
Ctxt.Cursym = nil
Exitf("%s: running dsymutil failed: %v\n%s", os.Args[0], err, out)
}
combinedOutput := fmt.Sprintf("%s/go.combined", tmpdir)
if err := machoCombineDwarf(outfile, dsym, combinedOutput); err != nil {
Ctxt.Cursym = nil
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
}
origOutput := fmt.Sprintf("%s/go.orig", tmpdir)
os.Rename(outfile, origOutput)
if err := os.Rename(combinedOutput, outfile); err != nil {
Ctxt.Cursym = nil
Exitf("%s: rename(%s, %s) failed: %v", os.Args[0], combinedOutput, outfile, err)
}
}
}
func ldobj(f *obj.Biobuf, pkg string, length int64, pn string, file string, whence int) {
......
......@@ -443,8 +443,7 @@ func Asmbmacho() {
ms = newMachoSeg("", 40)
ms.fileoffset = Segtext.Fileoff
ms.filesize = Segdwarf.Fileoff + Segdwarf.Filelen - Segtext.Fileoff
ms.vsize = ms.filesize
ms.filesize = Segdata.Fileoff + Segdata.Filelen - Segtext.Fileoff
}
/* segment for zero page */
......@@ -562,8 +561,8 @@ func Asmbmacho() {
}
// TODO: dwarf headers go in ms too
if Debug['s'] == 0 {
dwarfaddmachoheaders(ms)
if Debug['s'] == 0 && Linkmode != LinkExternal {
dwarfaddmachoheaders()
}
a := machowrite()
......@@ -851,5 +850,4 @@ func Machoemitreloc() {
for sect := Segdata.Sect; sect != nil; sect = sect.Next {
machorelocsect(sect, datap)
}
dwarfemitreloc()
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment