From 0ae39f1957c92ca33e7ab158870b92be945eb595 Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Tue, 28 Dec 2010 16:14:30 +0900 Subject: [PATCH] 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. --- tccelf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tccelf.c b/tccelf.c index 6f39d237..c0977a88 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 -- 2.11.4.GIT