From 78ad19f214394a1cb1e96d448bacb84011204452 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Tue, 18 Oct 2011 16:31:03 -0400 Subject: [PATCH] ld: modify macho linkedit segment to enable OS X code signing Move string table to the end of the __LINKEDIT segment. This change allows Apple's codesign(1) utility to successfully sign Go binaries, as long as they don't contain DWARF data (-w flag to 8l/6l). This is because codesign(1) expects the string table to be the last part of the file. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5271050 --- src/cmd/ld/macho.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cmd/ld/macho.c b/src/cmd/ld/macho.c index efcbe0325b..05638f7254 100644 --- a/src/cmd/ld/macho.c +++ b/src/cmd/ld/macho.c @@ -413,9 +413,9 @@ asmbmacho(void) // must match domacholink below s1 = lookup(".dynsym", 0); - s2 = lookup(".dynstr", 0); - s3 = lookup(".linkedit.plt", 0); - s4 = lookup(".linkedit.got", 0); + s2 = lookup(".linkedit.plt", 0); + s3 = lookup(".linkedit.got", 0); + s4 = lookup(".dynstr", 0); ms = newMachoSeg("__LINKEDIT", 0); ms->vaddr = va+v+rnd(segdata.len, INITRND); @@ -428,8 +428,8 @@ asmbmacho(void) ml = newMachoLoad(2, 4); /* LC_SYMTAB */ ml->data[0] = linkoff; /* symoff */ ml->data[1] = s1->size / (macho64 ? 16 : 12); /* nsyms */ - ml->data[2] = linkoff + s1->size; /* stroff */ - ml->data[3] = s2->size; /* strsize */ + ml->data[2] = linkoff + s1->size + s2->size + s3->size; /* stroff */ + ml->data[3] = s4->size; /* strsize */ ml = newMachoLoad(11, 18); /* LC_DYSYMTAB */ ml->data[0] = 0; /* ilocalsym */ @@ -444,8 +444,8 @@ asmbmacho(void) ml->data[9] = 0; /* nmodtab */ ml->data[10] = 0; /* extrefsymoff */ ml->data[11] = 0; /* nextrefsyms */ - ml->data[12] = linkoff + s1->size + s2->size; /* indirectsymoff */ - ml->data[13] = (s3->size + s4->size) / 4; /* nindirectsyms */ + ml->data[12] = linkoff + s1->size; /* indirectsymoff */ + ml->data[13] = (s2->size + s3->size) / 4; /* nindirectsyms */ ml->data[14] = 0; /* extreloff */ ml->data[15] = 0; /* nextrel */ ml->data[16] = 0; /* locreloff */ @@ -495,12 +495,12 @@ domacholink(void) // write data that will be linkedit section s1 = lookup(".dynsym", 0); relocsym(s1); - s2 = lookup(".dynstr", 0); - s3 = lookup(".linkedit.plt", 0); - s4 = lookup(".linkedit.got", 0); + s2 = lookup(".linkedit.plt", 0); + s3 = lookup(".linkedit.got", 0); + s4 = lookup(".dynstr", 0); - while(s2->size%4) - adduint8(s2, 0); + while(s4->size%4) + adduint8(s4, 0); size = s1->size + s2->size + s3->size + s4->size; -- 2.50.0