]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: abort if (32-bit) address relocation is negative on amd64.
authorShenghou Ma <minux.ma@gmail.com>
Tue, 20 May 2014 02:39:42 +0000 (22:39 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 20 May 2014 02:39:42 +0000 (22:39 -0400)
Update #7980
This CL make the linker abort for the example program. For Go 1.4,
we need to find a general way to handle large memory model programs.

LGTM=dave, josharian, iant
R=iant, dave, josharian
CC=golang-codereviews
https://golang.org/cl/91500046

src/cmd/ld/data.c

index 24969db55b139dc593a5316538dfee594d5c2bc7..55d020710e01695023132e2a96956efce232f3c7 100644 (file)
@@ -243,6 +243,16 @@ relocsym(LSym *s)
                                break;
                        }
                        o = symaddr(r->sym) + r->add;
+
+                       // On amd64, 4-byte offsets will be sign-extended, so it is impossible to
+                       // access more than 2GB of static data; fail at link time is better than
+                       // fail at runtime. See http://golang.org/issue/7980.
+                       // Instead of special casing only amd64, we treat this as an error on all
+                       // 64-bit architectures so as to be future-proof.
+                       if((int32)o < 0 && PtrSize > 4 && siz == 4) {
+                               diag("non-pc-relative relocation address is too big: %#llux", o);
+                               errorexit();
+                       }
                        break;
                case R_CALL:
                case R_PCREL: