Commit 40d356e9 authored by Russ Cox's avatar Russ Cox

cmd/ld: generate relocated DWARF in hostobj mode

While we're here, downgrade DWARF to version 2.
We're not using any version 3 features, and OS X gdb
only supports version 2.

Fixes #3436.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/7891044
parent ddddd70c
This diff is collapsed.
...@@ -93,6 +93,7 @@ enum ...@@ -93,6 +93,7 @@ enum
DW_CLS_FLAG, DW_CLS_FLAG,
DW_CLS_PTR, // lineptr, loclistptr, macptr, rangelistptr DW_CLS_PTR, // lineptr, loclistptr, macptr, rangelistptr
DW_CLS_REFERENCE, DW_CLS_REFERENCE,
DW_CLS_ADDRLOC,
DW_CLS_STRING DW_CLS_STRING
}; };
......
...@@ -287,6 +287,7 @@ void ...@@ -287,6 +287,7 @@ void
loadlib(void) loadlib(void)
{ {
int i, w, x; int i, w, x;
Sym *s;
loadinternal("runtime"); loadinternal("runtime");
if(thechar == '5') if(thechar == '5')
...@@ -301,11 +302,20 @@ loadlib(void) ...@@ -301,11 +302,20 @@ loadlib(void)
objfile(library[i].file, library[i].pkg); objfile(library[i].file, library[i].pkg);
} }
if(linkmode == LinkExternal && !iscgo)
linkmode = LinkInternal;
// If we got this far in automatic mode, there were no // If we got this far in automatic mode, there were no
// cgo uses that suggest we need external mode. // cgo uses that suggest we need external mode.
// Switch to internal. // Switch to internal.
if(linkmode == LinkAuto) if(linkmode == LinkAuto) {
linkmode = LinkInternal; linkmode = LinkInternal;
// Drop all the cgo_import_static declarations.
// Turns out we won't be needing them.
for(s = allsym; s != S; s = s->allsym)
if(s->type == SHOSTOBJ)
s->type = 0;
}
// Now that we know the link mode, trim the dynexp list. // Now that we know the link mode, trim the dynexp list.
x = CgoExportDynamic; x = CgoExportDynamic;
...@@ -497,9 +507,11 @@ int mhostobj; ...@@ -497,9 +507,11 @@ int mhostobj;
// These packages can use internal linking mode. // These packages can use internal linking mode.
// Others trigger external mode. // Others trigger external mode.
const char *internalpkg[] = { const char *internalpkg[] = {
"crypto/x509",
"net", "net",
"os/user", "os/user",
"runtime/cgo" "runtime/cgo",
"runtime/race"
}; };
void void
...@@ -618,7 +630,7 @@ hostlink(void) ...@@ -618,7 +630,7 @@ hostlink(void)
break; break;
} }
if(!debug['s']) if(!debug['s'])
argv[argc++] = "-ggdb"; argv[argc++] = "-gdwarf-2";
if(HEADTYPE == Hdarwin) if(HEADTYPE == Hdarwin)
argv[argc++] = "-Wl,-no_pie,-pagezero_size,4000000"; argv[argc++] = "-Wl,-no_pie,-pagezero_size,4000000";
argv[argc++] = "-o"; argv[argc++] = "-o";
......
...@@ -150,7 +150,7 @@ machowrite(void) ...@@ -150,7 +150,7 @@ machowrite(void)
LPUT(0xfeedface); LPUT(0xfeedface);
LPUT(hdr.cpu); LPUT(hdr.cpu);
LPUT(hdr.subcpu); LPUT(hdr.subcpu);
if(isobj) if(linkmode == LinkExternal)
LPUT(1); /* file type - mach object */ LPUT(1); /* file type - mach object */
else else
LPUT(2); /* file type - mach executable */ LPUT(2); /* file type - mach executable */
...@@ -248,7 +248,7 @@ domacho(void) ...@@ -248,7 +248,7 @@ domacho(void)
s->type = SMACHOSYMTAB; s->type = SMACHOSYMTAB;
s->reachable = 1; s->reachable = 1;
if(!isobj) { if(linkmode != LinkExternal) {
s = lookup(".plt", 0); // will be __symbol_stub s = lookup(".plt", 0); // will be __symbol_stub
s->type = SMACHOPLT; s->type = SMACHOPLT;
s->reachable = 1; s->reachable = 1;
...@@ -367,7 +367,7 @@ asmbmacho(void) ...@@ -367,7 +367,7 @@ asmbmacho(void)
} }
ms = nil; ms = nil;
if(isobj) { if(linkmode == LinkExternal) {
/* segment for entire file */ /* segment for entire file */
ms = newMachoSeg("", 40); ms = newMachoSeg("", 40);
ms->fileoffset = segtext.fileoff; ms->fileoffset = segtext.fileoff;
...@@ -375,14 +375,14 @@ asmbmacho(void) ...@@ -375,14 +375,14 @@ asmbmacho(void)
} }
/* segment for zero page */ /* segment for zero page */
if(!isobj) { if(linkmode != LinkExternal) {
ms = newMachoSeg("__PAGEZERO", 0); ms = newMachoSeg("__PAGEZERO", 0);
ms->vsize = va; ms->vsize = va;
} }
/* text */ /* text */
v = rnd(HEADR+segtext.len, INITRND); v = rnd(HEADR+segtext.len, INITRND);
if(!isobj) { if(linkmode != LinkExternal) {
ms = newMachoSeg("__TEXT", 20); ms = newMachoSeg("__TEXT", 20);
ms->vaddr = va; ms->vaddr = va;
ms->vsize = v; ms->vsize = v;
...@@ -396,7 +396,7 @@ asmbmacho(void) ...@@ -396,7 +396,7 @@ asmbmacho(void)
machoshbits(ms, sect, "__TEXT"); machoshbits(ms, sect, "__TEXT");
/* data */ /* data */
if(!isobj) { if(linkmode != LinkExternal) {
w = segdata.len; w = segdata.len;
ms = newMachoSeg("__DATA", 20); ms = newMachoSeg("__DATA", 20);
ms->vaddr = va+v; ms->vaddr = va+v;
...@@ -410,7 +410,7 @@ asmbmacho(void) ...@@ -410,7 +410,7 @@ asmbmacho(void)
for(sect=segdata.sect; sect!=nil; sect=sect->next) for(sect=segdata.sect; sect!=nil; sect=sect->next)
machoshbits(ms, sect, "__DATA"); machoshbits(ms, sect, "__DATA");
if(!isobj) { if(linkmode != LinkExternal) {
switch(thechar) { switch(thechar) {
default: default:
diag("unknown macho architecture"); diag("unknown macho architecture");
...@@ -440,7 +440,7 @@ asmbmacho(void) ...@@ -440,7 +440,7 @@ asmbmacho(void)
s3 = lookup(".linkedit.got", 0); s3 = lookup(".linkedit.got", 0);
s4 = lookup(".machosymstr", 0); s4 = lookup(".machosymstr", 0);
if(!isobj) { if(linkmode != LinkExternal) {
ms = newMachoSeg("__LINKEDIT", 0); ms = newMachoSeg("__LINKEDIT", 0);
ms->vaddr = va+v+rnd(segdata.len, INITRND); ms->vaddr = va+v+rnd(segdata.len, INITRND);
ms->vsize = s1->size + s2->size + s3->size + s4->size; ms->vsize = s1->size + s2->size + s3->size + s4->size;
...@@ -458,7 +458,7 @@ asmbmacho(void) ...@@ -458,7 +458,7 @@ asmbmacho(void)
machodysymtab(); machodysymtab();
if(!isobj) { if(linkmode != LinkExternal) {
ml = newMachoLoad(14, 6); /* LC_LOAD_DYLINKER */ ml = newMachoLoad(14, 6); /* LC_LOAD_DYLINKER */
ml->data[0] = 12; /* offset to string */ ml->data[0] = 12; /* offset to string */
strcpy((char*)&ml->data[1], "/usr/lib/dyld"); strcpy((char*)&ml->data[1], "/usr/lib/dyld");
...@@ -475,7 +475,7 @@ asmbmacho(void) ...@@ -475,7 +475,7 @@ asmbmacho(void)
} }
// TODO: dwarf headers go in ms too // TODO: dwarf headers go in ms too
if(!debug['s'] && !isobj) if(!debug['s'] && linkmode != LinkExternal)
dwarfaddmachoheaders(); dwarfaddmachoheaders();
a = machowrite(); a = machowrite();
...@@ -581,6 +581,9 @@ machosymtab(void) ...@@ -581,6 +581,9 @@ machosymtab(void)
for(i=0; i<nsortsym; i++) { for(i=0; i<nsortsym; i++) {
s = sortsym[i]; s = sortsym[i];
adduint32(symtab, symstr->size); adduint32(symtab, symstr->size);
// Only add _ to C symbols. Go symbols have dot in the name.
if(strstr(s->extname, ".") == nil)
adduint8(symstr, '_'); adduint8(symstr, '_');
addstring(symstr, s->extname); addstring(symstr, s->extname);
if(s->type == SDYNIMPORT || s->type == SHOSTOBJ) { if(s->type == SDYNIMPORT || s->type == SHOSTOBJ) {
......
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