From 738606dbd5608cb2ed6789beecea40712809c397 Mon Sep 17 00:00:00 2001 From: Edmund Grimley Evans Date: Sat, 21 Feb 2015 21:29:03 +0000 Subject: Use RELA relocations properly for R_DATA_PTR on x86_64. libtcc.c: Add greloca, a generalisation of greloc that takes an addend. tcc.h: Add greloca and put_elf_reloca. tccelf.c: Add put_elf_reloca, a generalisation of put_elf_reloc. tccgen.c: On x86_64, use greloca instead of greloc in init_putv. --- tccelf.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tccelf.c') diff --git a/tccelf.c b/tccelf.c index 02caa68..dc0a144 100644 --- a/tccelf.c +++ b/tccelf.c @@ -269,8 +269,8 @@ ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, } /* put relocation */ -ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, - int type, int symbol) +ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, + int type, int symbol, unsigned long addend) { char buf[256]; Section *sr; @@ -292,10 +292,19 @@ ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, rel->r_offset = offset; rel->r_info = ELFW(R_INFO)(symbol, type); #ifdef TCC_TARGET_X86_64 - rel->r_addend = 0; + rel->r_addend = addend; +#else + if (addend) + tcc_error("non-zero addend on REL architecture"); #endif } +ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, + int type, int symbol) +{ + put_elf_reloca(symtab, s, offset, type, symbol, 0); +} + /* put stab debug information */ ST_FUNC void put_stabs(const char *str, int type, int other, int desc, -- cgit v1.3.1