]> Cypherpunks repositories - gostls13.git/commitdiff
ld: modify macho linkedit segment to enable OS X code signing
authorMikkel Krautz <mikkel@krautz.dk>
Tue, 18 Oct 2011 20:31:03 +0000 (16:31 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 18 Oct 2011 20:31:03 +0000 (16:31 -0400)
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

index efcbe0325bdb2c4150b5067a0860580c45f571e8..05638f7254212913e08fc2aa0eda9c41214a8b94 100644 (file)
@@ -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;