aboutsummaryrefslogtreecommitdiff
path: root/tccelf.c
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2010-12-28 16:14:30 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2010-12-28 16:14:30 +0900
commit0ae39f1957c92ca33e7ab158870b92be945eb595 (patch)
tree202ab6dbd176a3971f45de3954b715371f9962e0 /tccelf.c
parent48e325df3cad5cdadef6bb354bbc328d70c6ab32 (diff)
downloadtinycc-0ae39f1957c92ca33e7ab158870b92be945eb595.tar.gz
tinycc-0ae39f1957c92ca33e7ab158870b92be945eb595.tar.bz2
Handle r_addend and R_X86_64_PLT32 properly.
- r_addend should be applied for PLT entries as well - R_X86_64_PLT32 should be handled just like R_X86_64_PC32 - spec says GLOB_DAT and JUMP_SLOT don't need r_addend (not tested) http://www.x86-64.org/documentation/abi.pdf Now we can -run ELF objects generated by GCC.
Diffstat (limited to 'tccelf.c')
-rw-r--r--tccelf.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/tccelf.c b/tccelf.c
index 6f39d23..c0977a8 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -543,7 +543,6 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
val = sym->st_value;
#ifdef TCC_TARGET_X86_64
- /* XXX: not tested */
val += rel->r_addend;
#endif
type = ELFW(R_TYPE)(rel->r_info);
@@ -715,7 +714,9 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
}
*(int *)ptr += val;
break;
- case R_X86_64_PC32: {
+
+ case R_X86_64_PC32:
+ case R_X86_64_PLT32: {
long long diff;
if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
@@ -733,7 +734,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
#ifndef TCC_TARGET_PE
/* XXX: naive support for over 32bit jump */
if (s1->output_type == TCC_OUTPUT_MEMORY) {
- val = add_jmp_table(s1, val);
+ val = add_jmp_table(s1, val) + rel->r_addend;
diff = val - addr;
}
#endif
@@ -744,12 +745,10 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
*(int *)ptr += diff;
}
break;
- case R_X86_64_PLT32:
- *(int *)ptr += val - addr;
- break;
case R_X86_64_GLOB_DAT:
case R_X86_64_JUMP_SLOT:
- *(int *)ptr = val;
+ /* They don't need addend */
+ *(int *)ptr = val - rel->r_addend;
break;
case R_X86_64_GOTPCREL:
#ifndef TCC_TARGET_PE