Commit 44cf814d authored by Elias Naur's avatar Elias Naur Committed by Russ Cox

runtime, cmd/ld: make code more position-independent

Change the stack unwinding code to compensate for the dynamic
relocation of symbols.
Change the gc instruction GC_CALL to use a relative offset instead of
an absolute address.

R=golang-dev
CC=golang-dev
https://golang.org/cl/7248048
parent 11d16dc5
......@@ -748,7 +748,6 @@ setuint64(Sym *s, vlong r, uint64 v)
setuintxx(s, r, v, 8);
}
/*
static vlong
addaddrpcrelplus(Sym *s, Sym *t, int32 add)
{
......@@ -769,7 +768,6 @@ addaddrpcrelplus(Sym *s, Sym *t, int32 add)
r->add = add;
return i;
}
*/
vlong
addaddrplus(Sym *s, Sym *t, int32 add)
......@@ -951,7 +949,7 @@ gcaddsym(Sym *gc, Sym *s, int32 off)
//print("gcaddsym: %s %d %s\n", s->name, s->size, gotype->name);
adduintxx(gc, GC_CALL, PtrSize);
adduintxx(gc, off, PtrSize);
addaddrplus(gc, decodetype_gc(gotype), 1*PtrSize);
addaddrpcrelplus(gc, decodetype_gc(gotype), 4*PtrSize);
} else {
//print("gcaddsym: %s %d <unknown type>\n", s->name, s->size);
for(a = -off&(PtrSize-1); a+PtrSize<=s->size; a+=PtrSize) {
......
......@@ -663,7 +663,7 @@ scanblock(Workbuf *wbuf, Obj *wp, uintptr nobj, bool keepworking)
// Stack push.
*stack_ptr-- = stack_top;
stack_top = (Frame){1, 0, stack_top.b + pc[1], pc+3 /*return address*/};
pc = (uintptr*)pc[2]; // target of the CALL instruction
pc = (uintptr*)((byte*)pc + (uintptr)pc[2]); // target of the CALL instruction
continue;
case GC_MAP_PTR:
......
......@@ -12,6 +12,7 @@
// Meaning of arguments:
// off Offset (in bytes) from the start of the current object
// objgc Pointer to GC info of an object
// objgcrel Offset to GC info of an object
// len Length of an array
// elemsize Size (in bytes) of an element
// size Size (in bytes)
......@@ -21,7 +22,7 @@ enum {
GC_APTR, // Pointer to an arbitrary object. Args: (off)
GC_ARRAY_START, // Start an array with a fixed length. Args: (off, len, elemsize)
GC_ARRAY_NEXT, // The next element of an array. Args: none
GC_CALL, // Call a subroutine. Args: (off, objgc)
GC_CALL, // Call a subroutine. Args: (off, objgcrel)
GC_MAP_PTR, // Go map. Args: (off, MapType*)
GC_STRING, // Go string. Args: (off)
GC_EFACE, // interface{}. Args: (off)
......
......@@ -93,6 +93,7 @@ walksymtab(void (*fn)(Sym*))
static Func *func;
static int32 nfunc;
extern byte reloffset[];
static byte **fname;
static int32 nfname;
......@@ -118,7 +119,7 @@ dofunc(Sym *sym)
}
f = &func[nfunc++];
f->name = runtime·gostringnocopy(sym->name);
f->entry = sym->value;
f->entry = sym->value + (uint64)reloffset;
if(sym->symtype == 'L' || sym->symtype == 'l')
f->frame = -sizeof(uintptr);
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment