From d35211328e772118fb8967af22b0c309b6341a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Moln=C3=A1r?= Date: Fri, 7 Jul 2006 08:51:48 +0200 Subject: [PATCH] ElfLinker: rela support added --- src/linker.cpp | 12 ++++++++++-- src/linker.h | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/linker.cpp b/src/linker.cpp index 6c03a83e..f26abf7c 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -426,9 +426,16 @@ void ElfLinker::preprocessRelocations(char *start, const char *end) char *t = strstr(start, type); t[strlen(type)] = 0; + unsigned add = 0; + if (char *p = strstr(symbol, "+0x")) + { + *p = 0; + sscanf(p + 3, "%x", &add); + } + assert(nrelocations < TABLESIZE(relocations)); relocations[nrelocations++] = Relocation(section, offset, t, - findSymbol(symbol)); + findSymbol(symbol), add); //printf("relocation %s %x preprocessed\n", section->name, offset); } @@ -607,7 +614,8 @@ void ElfLinker::relocate() printf("undefined symbol '%s' referenced\n", rel->value->name); abort(); } - unsigned value = rel->value->section->offset + rel->value->offset; + unsigned value = rel->value->section->offset + + rel->value->offset + rel->add; upx_byte *location = rel->section->output + rel->offset; relocate1(rel, location, value, rel->type); diff --git a/src/linker.h b/src/linker.h index 285cd537..d1c9e975 100644 --- a/src/linker.h +++ b/src/linker.h @@ -189,10 +189,12 @@ protected: unsigned offset; const char *type; Symbol *value; + unsigned add; // used in .rela relocations Relocation(){} - Relocation(Section *s, unsigned o, const char *t, Symbol *v) : - section(s), offset(o), type(t), value(v) + Relocation(Section *s, unsigned o, const char *t, + Symbol *v, unsigned a) : + section(s), offset(o), type(t), value(v), add(a) {} };