]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: fix another unsigned value causing bugs on Plan 9
authorRob Pike <r@golang.org>
Thu, 2 May 2013 00:00:21 +0000 (17:00 -0700)
committerRob Pike <r@golang.org>
Thu, 2 May 2013 00:00:21 +0000 (17:00 -0700)
"The usual conversions" bite again.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/9103044

src/cmd/ld/data.c

index 37ad2f8c87d5e8b9cd867ba232f1f9ad587193a1..23fc23e5fc3da17747894b071f5fda0310bfeb9a 100644 (file)
@@ -247,7 +247,13 @@ relocsym(Sym *s)
                        o = 0;
                        if(r->sym)
                                o += symaddr(r->sym);
-                       o += r->add - (s->value + r->off + r->siz);
+                       // NOTE: The (int32) cast on the next line works around a bug in Plan 9's 8c
+                       // compiler. The expression s->value + r->off + r->siz is int32 + int32 +
+                       // uchar, and Plan 9 8c incorrectly treats the expression as type uint32
+                       // instead of int32, causing incorrect values when sign extended for adding
+                       // to o. The bug only occurs on Plan 9, because this C program is compiled by
+                       // the standard host compiler (gcc on most other systems).
+                       o += r->add - (s->value + r->off + (int32)r->siz);
                        break;
                case D_SIZE:
                        o = r->sym->size + r->add;