diff options
| author | Russ Cox <rsc@golang.org> | 2013-02-28 16:21:58 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-02-28 16:21:58 -0500 |
| commit | 40ed753ebd6b74747816fde7b130116ff7ef9580 (patch) | |
| tree | f62d94145914f754252d7e9857ed37a95d36b7e3 /src/pkg/runtime | |
| parent | 1bf66f081fb34893235a02b29a8eb559e17c248e (diff) | |
| download | go-40ed753ebd6b74747816fde7b130116ff7ef9580.tar.xz | |
cmd/ld: fix symbol table sorting
runtime: double-check that symbol table is sorted
If the symbol table is unsorted, the binary search in findfunc
will not find its func, which will make stack traces stop early.
When the garbage collector starts using the stack tracer,
that would be a serious problem.
The unsorted symbol addresses came from from two things:
1. The symbols in an ELF object are not necessarily sorted,
so sort them before adding them to the symbol list.
2. The __i686.get_pc_thunk.bx symbol is present in multiple
object files and was having its address adjusted multiple
times, producing an incorrect address in the symbol table.
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7440044
Diffstat (limited to 'src/pkg/runtime')
| -rw-r--r-- | src/pkg/runtime/symtab.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/pkg/runtime/symtab.c b/src/pkg/runtime/symtab.c index 2485586855..d7221c4767 100644 --- a/src/pkg/runtime/symtab.c +++ b/src/pkg/runtime/symtab.c @@ -195,12 +195,13 @@ static int32 nfname; static uint32 funcinit; static Lock funclock; +static uintptr lastvalue; static void dofunc(Sym *sym) { Func *f; - + switch(sym->symtype) { case 't': case 'T': @@ -208,6 +209,11 @@ dofunc(Sym *sym) case 'L': if(runtime·strcmp(sym->name, (byte*)"etext") == 0) break; + if(sym->value < lastvalue) { + runtime·printf("symbols out of order: %p before %p\n", lastvalue, sym->value); + runtime·throw("malformed symbol table"); + } + lastvalue = sym->value; if(func == nil) { nfunc++; break; @@ -544,6 +550,7 @@ buildfuncs(void) // count funcs, fnames nfunc = 0; nfname = 0; + lastvalue = 0; walksymtab(dofunc); // Initialize tables. @@ -553,6 +560,7 @@ buildfuncs(void) func[nfunc].entry = (uint64)etext; fname = runtime·mallocgc(nfname*sizeof fname[0], FlagNoPointers, 0, 1); nfunc = 0; + lastvalue = 0; walksymtab(dofunc); // split pc/ln table by func |
