]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/8l: accept R_386_GOT32 in push instruction
authorRuss Cox <rsc@golang.org>
Mon, 6 Oct 2014 18:17:48 +0000 (14:17 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 6 Oct 2014 18:17:48 +0000 (14:17 -0400)
Fixes #8382.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/149540045

src/cmd/8l/asm.c

index c135dce709ed62eeee47f626f9451007438656ef..98c04240374fd4f70171d18eaff226af1b504da6 100644 (file)
@@ -117,13 +117,21 @@ adddynrel(LSym *s, Reloc *r)
        case 256 + R_386_GOT32:
                if(targ->type != SDYNIMPORT) {
                        // have symbol
-                       // turn MOVL of GOT entry into LEAL of symbol itself
-                       if(r->off < 2 || s->p[r->off-2] != 0x8b) {
-                               diag("unexpected GOT reloc for non-dynamic symbol %s", targ->name);
+                       if(r->off >= 2 && s->p[r->off-2] == 0x8b) {
+                               // turn MOVL of GOT entry into LEAL of symbol address, relative to GOT.
+                               s->p[r->off-2] = 0x8d;
+                               r->type = R_GOTOFF;
                                return;
                        }
-                       s->p[r->off-2] = 0x8d;
-                       r->type = R_GOTOFF;
+                       if(r->off >= 2 && s->p[r->off-2] == 0xff && s->p[r->off-1] == 0xb3) {
+                               // turn PUSHL of GOT entry into PUSHL of symbol itself.
+                               // use unnecessary SS prefix to keep instruction same length.
+                               s->p[r->off-2] = 0x36;
+                               s->p[r->off-1] = 0x68;
+                               r->type = R_ADDR;
+                               return;
+                       }
+                       diag("unexpected GOT reloc for non-dynamic symbol %s", targ->name);
                        return;
                }
                addgotsym(ctxt, targ);