From 4566868b41620ba47ef589d8bab9b0906c370cb6 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Tue, 18 Oct 2011 15:58:10 -0400 Subject: [PATCH] 6l, 8l: emit macho dwarf info before linkedit section R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5272050 --- src/cmd/6l/asm.c | 16 +++++++++++++--- src/cmd/8l/asm.c | 16 +++++++++++++--- src/cmd/ld/lib.h | 1 + src/cmd/ld/macho.c | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/cmd/6l/asm.c b/src/cmd/6l/asm.c index 8d599ef30aa..dfb065e51cd 100644 --- a/src/cmd/6l/asm.c +++ b/src/cmd/6l/asm.c @@ -703,7 +703,7 @@ asmb(void) { int32 magic; int a, dynsym; - vlong vl, startva, symo, machlink; + vlong vl, startva, symo, dwarfoff, machlink; ElfEhdr *eh; ElfPhdr *ph, *pph; ElfShdr *sh; @@ -738,8 +738,19 @@ asmb(void) datblk(segdata.vaddr, segdata.filelen); machlink = 0; - if(HEADTYPE == Hdarwin) + if(HEADTYPE == Hdarwin) { + if(debug['v']) + Bprint(&bso, "%5.2f dwarf\n", cputime()); + + dwarfoff = rnd(HEADR+segtext.len, INITRND) + rnd(segdata.filelen, INITRND); + cseek(dwarfoff); + + segdwarf.fileoff = cpos(); + dwarfemitdebugsections(); + segdwarf.filelen = cpos() - segdwarf.fileoff; + machlink = domacholink(); + } switch(HEADTYPE) { default: @@ -811,7 +822,6 @@ asmb(void) dwarfemitdebugsections(); } break; - case Hdarwin: case Hwindows: if(debug['v']) Bprint(&bso, "%5.2f dwarf\n", cputime()); diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c index 03106386c01..119c8364b0a 100644 --- a/src/cmd/8l/asm.c +++ b/src/cmd/8l/asm.c @@ -660,7 +660,7 @@ asmb(void) { int32 v, magic; int a, dynsym; - uint32 symo, startva, machlink; + uint32 symo, startva, dwarfoff, machlink; ElfEhdr *eh; ElfPhdr *ph, *pph; ElfShdr *sh; @@ -691,8 +691,19 @@ asmb(void) datblk(segdata.vaddr, segdata.filelen); machlink = 0; - if(HEADTYPE == Hdarwin) + if(HEADTYPE == Hdarwin) { + if(debug['v']) + Bprint(&bso, "%5.2f dwarf\n", cputime()); + + dwarfoff = rnd(HEADR+segtext.len, INITRND) + rnd(segdata.filelen, INITRND); + cseek(dwarfoff); + + segdwarf.fileoff = cpos(); + dwarfemitdebugsections(); + segdwarf.filelen = cpos() - segdwarf.fileoff; + machlink = domacholink(); + } if(iself) { /* index of elf text section; needed by asmelfsym, double-checked below */ @@ -772,7 +783,6 @@ asmb(void) cflush(); } break; - case Hdarwin: case Hwindows: if(debug['v']) Bprint(&bso, "%5.2f dwarf\n", cputime()); diff --git a/src/cmd/ld/lib.h b/src/cmd/ld/lib.h index d13eea31ed8..f66eb438f06 100644 --- a/src/cmd/ld/lib.h +++ b/src/cmd/ld/lib.h @@ -129,6 +129,7 @@ EXTERN int havedynamic; EXTERN Segment segtext; EXTERN Segment segdata; EXTERN Segment segsym; +EXTERN Segment segdwarf; void addlib(char *src, char *obj); void addlibpath(char *srcref, char *objref, char *file, char *pkg); diff --git a/src/cmd/ld/macho.c b/src/cmd/ld/macho.c index 70133d66516..efcbe0325bd 100644 --- a/src/cmd/ld/macho.c +++ b/src/cmd/ld/macho.c @@ -505,7 +505,7 @@ domacholink(void) size = s1->size + s2->size + s3->size + s4->size; if(size > 0) { - linkoff = rnd(HEADR+segtext.len, INITRND) + rnd(segdata.filelen, INITRND); + linkoff = rnd(HEADR+segtext.len, INITRND) + rnd(segdata.filelen, INITRND) + rnd(segdwarf.filelen, INITRND); cseek(linkoff); cwrite(s1->p, s1->size);