2016-12-06 04:40:59 +08:00
|
|
|
#ifdef TARGET_DEFS_ONLY
|
|
|
|
|
|
|
|
#define EM_TCC_TARGET EM_X86_64
|
|
|
|
|
|
|
|
/* relocation type for 32 bit data relocation */
|
2016-09-27 23:04:39 +08:00
|
|
|
#define R_DATA_32 R_X86_64_32S
|
2016-12-06 04:40:59 +08:00
|
|
|
#define R_DATA_PTR R_X86_64_64
|
|
|
|
#define R_JMP_SLOT R_X86_64_JUMP_SLOT
|
|
|
|
#define R_GLOB_DAT R_X86_64_GLOB_DAT
|
|
|
|
#define R_COPY R_X86_64_COPY
|
2017-05-07 10:41:40 +08:00
|
|
|
#define R_RELATIVE R_X86_64_RELATIVE
|
2016-12-06 04:40:59 +08:00
|
|
|
|
|
|
|
#define R_NUM R_X86_64_NUM
|
|
|
|
|
|
|
|
#define ELF_START_ADDR 0x400000
|
|
|
|
#define ELF_PAGE_SIZE 0x200000
|
|
|
|
|
2016-12-10 17:14:29 +08:00
|
|
|
#define PCRELATIVE_DLLPLT 1
|
2016-12-16 00:01:22 +08:00
|
|
|
#define RELOCATE_DLLPLT 1
|
2016-11-12 23:16:06 +08:00
|
|
|
|
2016-12-06 04:40:59 +08:00
|
|
|
#else /* !TARGET_DEFS_ONLY */
|
|
|
|
|
|
|
|
#include "tcc.h"
|
|
|
|
|
2022-05-08 05:16:13 +08:00
|
|
|
#ifdef NEED_RELOC_TYPE
|
2016-12-11 01:22:08 +08:00
|
|
|
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
|
|
|
|
relocations, returns -1. */
|
|
|
|
int code_reloc (int reloc_type)
|
|
|
|
{
|
|
|
|
switch (reloc_type) {
|
|
|
|
case R_X86_64_32:
|
|
|
|
case R_X86_64_32S:
|
|
|
|
case R_X86_64_64:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_GOTPC32:
|
|
|
|
case R_X86_64_GOTPC64:
|
2016-12-11 01:22:08 +08:00
|
|
|
case R_X86_64_GOTPCREL:
|
|
|
|
case R_X86_64_GOTPCRELX:
|
|
|
|
case R_X86_64_REX_GOTPCRELX:
|
|
|
|
case R_X86_64_GOTTPOFF:
|
|
|
|
case R_X86_64_GOT32:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_GOT64:
|
2016-12-11 01:22:08 +08:00
|
|
|
case R_X86_64_GLOB_DAT:
|
|
|
|
case R_X86_64_COPY:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_RELATIVE:
|
2017-05-16 13:03:26 +08:00
|
|
|
case R_X86_64_GOTOFF64:
|
2020-09-08 20:31:58 +08:00
|
|
|
case R_X86_64_TLSGD:
|
|
|
|
case R_X86_64_TLSLD:
|
|
|
|
case R_X86_64_DTPOFF32:
|
|
|
|
case R_X86_64_TPOFF32:
|
2022-05-08 00:10:59 +08:00
|
|
|
case R_X86_64_DTPOFF64:
|
|
|
|
case R_X86_64_TPOFF64:
|
2016-12-11 01:22:08 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case R_X86_64_PC32:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_PC64:
|
2016-12-11 01:22:08 +08:00
|
|
|
case R_X86_64_PLT32:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_PLTOFF64:
|
2016-12-11 01:22:08 +08:00
|
|
|
case R_X86_64_JUMP_SLOT:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-08 12:38:09 +08:00
|
|
|
/* Returns an enumerator to describe whether and when the relocation needs a
|
2016-12-11 01:22:08 +08:00
|
|
|
GOT and/or PLT entry to be created. See tcc.h for a description of the
|
|
|
|
different values. */
|
|
|
|
int gotplt_entry_type (int reloc_type)
|
|
|
|
{
|
|
|
|
switch (reloc_type) {
|
|
|
|
case R_X86_64_GLOB_DAT:
|
|
|
|
case R_X86_64_JUMP_SLOT:
|
|
|
|
case R_X86_64_COPY:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_RELATIVE:
|
2016-12-11 01:22:08 +08:00
|
|
|
return NO_GOTPLT_ENTRY;
|
|
|
|
|
2016-12-18 12:18:19 +08:00
|
|
|
/* The following relocs wouldn't normally need GOT or PLT
|
|
|
|
slots, but we need them for simplicity in the link
|
|
|
|
editor part. See our caller for comments. */
|
2016-12-11 01:22:08 +08:00
|
|
|
case R_X86_64_32:
|
|
|
|
case R_X86_64_32S:
|
|
|
|
case R_X86_64_64:
|
|
|
|
case R_X86_64_PC32:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_PC64:
|
2016-12-11 01:22:08 +08:00
|
|
|
return AUTO_GOTPLT_ENTRY;
|
|
|
|
|
|
|
|
case R_X86_64_GOTTPOFF:
|
|
|
|
return BUILD_GOT_ONLY;
|
|
|
|
|
|
|
|
case R_X86_64_GOT32:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_GOT64:
|
|
|
|
case R_X86_64_GOTPC32:
|
|
|
|
case R_X86_64_GOTPC64:
|
2017-05-16 13:03:26 +08:00
|
|
|
case R_X86_64_GOTOFF64:
|
2016-12-11 01:22:08 +08:00
|
|
|
case R_X86_64_GOTPCREL:
|
|
|
|
case R_X86_64_GOTPCRELX:
|
2020-09-08 20:31:58 +08:00
|
|
|
case R_X86_64_TLSGD:
|
|
|
|
case R_X86_64_TLSLD:
|
|
|
|
case R_X86_64_DTPOFF32:
|
|
|
|
case R_X86_64_TPOFF32:
|
2022-05-08 00:10:59 +08:00
|
|
|
case R_X86_64_DTPOFF64:
|
|
|
|
case R_X86_64_TPOFF64:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_REX_GOTPCRELX:
|
2016-12-11 01:22:08 +08:00
|
|
|
case R_X86_64_PLT32:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_PLTOFF64:
|
2016-12-11 01:22:08 +08:00
|
|
|
return ALWAYS_GOTPLT_ENTRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-05-08 05:16:13 +08:00
|
|
|
#ifdef NEED_BUILD_GOT
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
|
2016-12-16 00:01:22 +08:00
|
|
|
{
|
2021-10-22 13:39:54 +08:00
|
|
|
Section *plt = s1->plt;
|
2016-12-16 00:01:22 +08:00
|
|
|
uint8_t *p;
|
|
|
|
int modrm;
|
|
|
|
unsigned plt_offset, relofs;
|
|
|
|
|
|
|
|
modrm = 0x25;
|
|
|
|
|
2017-05-08 12:38:09 +08:00
|
|
|
/* empty PLT: create PLT0 entry that pushes the library identifier
|
2016-12-16 00:01:22 +08:00
|
|
|
(GOT + PTR_SIZE) and jumps to ld.so resolution routine
|
|
|
|
(GOT + 2 * PTR_SIZE) */
|
|
|
|
if (plt->data_offset == 0) {
|
2021-10-22 13:39:54 +08:00
|
|
|
p = section_ptr_add(plt, 16);
|
2016-12-16 00:01:22 +08:00
|
|
|
p[0] = 0xff; /* pushl got + PTR_SIZE */
|
|
|
|
p[1] = modrm + 0x10;
|
|
|
|
write32le(p + 2, PTR_SIZE);
|
|
|
|
p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */
|
|
|
|
p[7] = modrm;
|
|
|
|
write32le(p + 8, PTR_SIZE * 2);
|
|
|
|
}
|
|
|
|
plt_offset = plt->data_offset;
|
|
|
|
|
|
|
|
/* The PLT slot refers to the relocation entry it needs via offset.
|
|
|
|
The reloc entry is created below, so its offset is the current
|
|
|
|
data_offset */
|
2021-10-22 13:39:54 +08:00
|
|
|
relofs = s1->plt->reloc ? s1->plt->reloc->data_offset : 0;
|
2016-12-16 00:01:22 +08:00
|
|
|
|
|
|
|
/* Jump to GOT entry where ld.so initially put the address of ip + 4 */
|
2021-10-22 13:39:54 +08:00
|
|
|
p = section_ptr_add(plt, 16);
|
2016-12-16 00:01:22 +08:00
|
|
|
p[0] = 0xff; /* jmp *(got + x) */
|
|
|
|
p[1] = modrm;
|
|
|
|
write32le(p + 2, got_offset);
|
|
|
|
p[6] = 0x68; /* push $xxx */
|
|
|
|
/* On x86-64, the relocation is referred to by _index_ */
|
2020-12-18 22:24:32 +08:00
|
|
|
write32le(p + 7, relofs / sizeof (ElfW_Rel) - 1);
|
2016-12-16 00:01:22 +08:00
|
|
|
p[11] = 0xe9; /* jmp plt_start */
|
|
|
|
write32le(p + 12, -(plt->data_offset));
|
|
|
|
return plt_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* relocate the PLT: compute addresses and offsets in the PLT now that final
|
|
|
|
address for PLT and GOT are known (see fill_program_header) */
|
2021-10-22 13:39:54 +08:00
|
|
|
ST_FUNC void relocate_plt(TCCState *s1)
|
2016-12-16 00:01:22 +08:00
|
|
|
{
|
|
|
|
uint8_t *p, *p_end;
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (!s1->plt)
|
2016-12-16 00:01:22 +08:00
|
|
|
return;
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
p = s1->plt->data;
|
|
|
|
p_end = p + s1->plt->data_offset;
|
2016-12-16 00:01:22 +08:00
|
|
|
|
|
|
|
if (p < p_end) {
|
2021-10-22 13:39:54 +08:00
|
|
|
int x = s1->got->sh_addr - s1->plt->sh_addr - 6;
|
2016-12-16 00:01:22 +08:00
|
|
|
add32le(p + 2, x);
|
|
|
|
add32le(p + 8, x - 6);
|
|
|
|
p += 16;
|
|
|
|
while (p < p_end) {
|
2021-10-22 13:39:54 +08:00
|
|
|
add32le(p + 2, x + (s1->plt->data - p));
|
2016-12-16 00:01:22 +08:00
|
|
|
p += 16;
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 22:24:32 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s1->plt->reloc) {
|
2020-12-18 22:24:32 +08:00
|
|
|
ElfW_Rel *rel;
|
2021-10-22 13:39:54 +08:00
|
|
|
int x = s1->plt->sh_addr + 16 + 6;
|
|
|
|
p = s1->got->data;
|
|
|
|
for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
|
2021-01-28 21:20:05 +08:00
|
|
|
write64le(p + rel->r_offset, x);
|
2020-12-18 22:24:32 +08:00
|
|
|
x += 16;
|
|
|
|
}
|
|
|
|
}
|
2016-12-16 00:01:22 +08:00
|
|
|
}
|
2019-12-10 03:32:13 +08:00
|
|
|
#endif
|
2020-06-27 23:15:06 +08:00
|
|
|
#endif
|
2019-06-23 08:10:10 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
|
2016-11-12 23:16:06 +08:00
|
|
|
{
|
|
|
|
int sym_index, esym_index;
|
|
|
|
|
|
|
|
sym_index = ELFW(R_SYM)(rel->r_info);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case R_X86_64_64:
|
2022-05-29 03:00:40 +08:00
|
|
|
if (s1->output_type & TCC_OUTPUT_DYN) {
|
2021-10-22 13:39:54 +08:00
|
|
|
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
2016-11-12 23:16:06 +08:00
|
|
|
qrel->r_offset = rel->r_offset;
|
|
|
|
if (esym_index) {
|
|
|
|
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64);
|
2017-05-12 15:31:09 +08:00
|
|
|
qrel->r_addend = rel->r_addend;
|
2016-11-12 23:16:06 +08:00
|
|
|
qrel++;
|
|
|
|
break;
|
|
|
|
} else {
|
2017-05-12 15:31:09 +08:00
|
|
|
qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
|
|
|
|
qrel->r_addend = read64le(ptr) + val;
|
2016-11-12 23:16:06 +08:00
|
|
|
qrel++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add64le(ptr, val);
|
|
|
|
break;
|
|
|
|
case R_X86_64_32:
|
|
|
|
case R_X86_64_32S:
|
2022-05-29 03:00:40 +08:00
|
|
|
if (s1->output_type & TCC_OUTPUT_DYN) {
|
2016-11-12 23:16:06 +08:00
|
|
|
/* XXX: this logic may depend on TCC's codegen
|
|
|
|
now TCC uses R_X86_64_32 even for a 64bit pointer */
|
2020-01-18 05:58:39 +08:00
|
|
|
qrel->r_offset = rel->r_offset;
|
2016-11-12 23:16:06 +08:00
|
|
|
qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
|
|
|
|
/* Use sign extension! */
|
|
|
|
qrel->r_addend = (int)read32le(ptr) + val;
|
|
|
|
qrel++;
|
|
|
|
}
|
|
|
|
add32le(ptr, val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_X86_64_PC32:
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s1->output_type == TCC_OUTPUT_DLL) {
|
2016-11-12 23:16:06 +08:00
|
|
|
/* DLL relocation */
|
2021-10-22 13:39:54 +08:00
|
|
|
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
2016-11-12 23:16:06 +08:00
|
|
|
if (esym_index) {
|
|
|
|
qrel->r_offset = rel->r_offset;
|
|
|
|
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC32);
|
|
|
|
/* Use sign extension! */
|
|
|
|
qrel->r_addend = (int)read32le(ptr) + rel->r_addend;
|
|
|
|
qrel++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto plt32pc32;
|
|
|
|
|
|
|
|
case R_X86_64_PLT32:
|
2017-05-12 15:31:09 +08:00
|
|
|
/* fallthrough: val already holds the PLT slot address */
|
2016-11-12 23:16:06 +08:00
|
|
|
|
2017-05-12 15:31:09 +08:00
|
|
|
plt32pc32:
|
|
|
|
{
|
2016-11-12 23:16:06 +08:00
|
|
|
long long diff;
|
|
|
|
diff = (long long)val - addr;
|
|
|
|
if (diff < -2147483648LL || diff > 2147483647LL) {
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_error("internal error: relocation failed");
|
2016-11-12 23:16:06 +08:00
|
|
|
}
|
|
|
|
add32le(ptr, diff);
|
|
|
|
}
|
|
|
|
break;
|
2017-05-12 15:31:09 +08:00
|
|
|
|
2022-04-12 13:11:52 +08:00
|
|
|
case R_X86_64_COPY:
|
|
|
|
break;
|
|
|
|
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_PLTOFF64:
|
2021-10-22 13:39:54 +08:00
|
|
|
add64le(ptr, val - s1->got->sh_addr + rel->r_addend);
|
2017-05-12 15:31:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case R_X86_64_PC64:
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s1->output_type == TCC_OUTPUT_DLL) {
|
2017-05-12 15:31:09 +08:00
|
|
|
/* DLL relocation */
|
2021-10-22 13:39:54 +08:00
|
|
|
esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
|
2017-05-12 15:31:09 +08:00
|
|
|
if (esym_index) {
|
|
|
|
qrel->r_offset = rel->r_offset;
|
|
|
|
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC64);
|
|
|
|
qrel->r_addend = read64le(ptr) + rel->r_addend;
|
|
|
|
qrel++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add64le(ptr, val - addr);
|
|
|
|
break;
|
|
|
|
|
2016-11-12 23:16:06 +08:00
|
|
|
case R_X86_64_GLOB_DAT:
|
|
|
|
case R_X86_64_JUMP_SLOT:
|
|
|
|
/* They don't need addend */
|
|
|
|
write64le(ptr, val - rel->r_addend);
|
|
|
|
break;
|
|
|
|
case R_X86_64_GOTPCREL:
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_GOTPCRELX:
|
|
|
|
case R_X86_64_REX_GOTPCRELX:
|
2021-10-22 13:39:54 +08:00
|
|
|
add32le(ptr, s1->got->sh_addr - addr +
|
|
|
|
get_sym_attr(s1, sym_index, 0)->got_offset - 4);
|
2016-11-12 23:16:06 +08:00
|
|
|
break;
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_GOTPC32:
|
2021-10-22 13:39:54 +08:00
|
|
|
add32le(ptr, s1->got->sh_addr - addr + rel->r_addend);
|
2017-05-12 15:31:09 +08:00
|
|
|
break;
|
|
|
|
case R_X86_64_GOTPC64:
|
2021-10-22 13:39:54 +08:00
|
|
|
add64le(ptr, s1->got->sh_addr - addr + rel->r_addend);
|
2017-05-12 15:31:09 +08:00
|
|
|
break;
|
2016-11-12 23:16:06 +08:00
|
|
|
case R_X86_64_GOTTPOFF:
|
2021-10-22 13:39:54 +08:00
|
|
|
add32le(ptr, val - s1->got->sh_addr);
|
2016-11-12 23:16:06 +08:00
|
|
|
break;
|
|
|
|
case R_X86_64_GOT32:
|
|
|
|
/* we load the got offset */
|
2021-10-22 13:39:54 +08:00
|
|
|
add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
|
2016-11-12 23:16:06 +08:00
|
|
|
break;
|
2017-05-12 15:31:09 +08:00
|
|
|
case R_X86_64_GOT64:
|
|
|
|
/* we load the got offset */
|
2021-10-22 13:39:54 +08:00
|
|
|
add64le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
|
2017-05-12 15:31:09 +08:00
|
|
|
break;
|
2017-05-16 13:03:26 +08:00
|
|
|
case R_X86_64_GOTOFF64:
|
2021-10-22 13:39:54 +08:00
|
|
|
add64le(ptr, val - s1->got->sh_addr);
|
2017-05-16 13:03:26 +08:00
|
|
|
break;
|
2020-09-08 20:31:58 +08:00
|
|
|
case R_X86_64_TLSGD:
|
|
|
|
{
|
|
|
|
static const unsigned char expect[] = {
|
|
|
|
/* .byte 0x66; lea 0(%rip),%rdi */
|
|
|
|
0x66, 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
/* .word 0x6666; rex64; call __tls_get_addr@PLT */
|
|
|
|
0x66, 0x66, 0x48, 0xe8, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
static const unsigned char replace[] = {
|
|
|
|
/* mov %fs:0,%rax */
|
|
|
|
0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
/* lea -4(%rax),%rax */
|
|
|
|
0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
|
|
|
if (memcmp (ptr-4, expect, sizeof(expect)) == 0) {
|
|
|
|
ElfW(Sym) *sym;
|
|
|
|
Section *sec;
|
|
|
|
int32_t x;
|
|
|
|
|
|
|
|
memcpy(ptr-4, replace, sizeof(replace));
|
|
|
|
rel[1].r_info = ELFW(R_INFO)(0, R_X86_64_NONE);
|
|
|
|
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
2021-10-22 13:39:54 +08:00
|
|
|
sec = s1->sections[sym->st_shndx];
|
2020-09-08 20:31:58 +08:00
|
|
|
x = sym->st_value - sec->sh_addr - sec->data_offset;
|
|
|
|
add32le(ptr + 8, x);
|
|
|
|
}
|
|
|
|
else
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_error("unexpected R_X86_64_TLSGD pattern");
|
2020-09-08 20:31:58 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R_X86_64_TLSLD:
|
|
|
|
{
|
|
|
|
static const unsigned char expect[] = {
|
|
|
|
/* lea 0(%rip),%rdi */
|
|
|
|
0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
/* call __tls_get_addr@PLT */
|
|
|
|
0xe8, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
static const unsigned char replace[] = {
|
|
|
|
/* data16 data16 data16 mov %fs:0,%rax */
|
|
|
|
0x66, 0x66, 0x66, 0x64, 0x48, 0x8b, 0x04, 0x25,
|
|
|
|
0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
|
|
|
if (memcmp (ptr-3, expect, sizeof(expect)) == 0) {
|
|
|
|
memcpy(ptr-3, replace, sizeof(replace));
|
|
|
|
rel[1].r_info = ELFW(R_INFO)(0, R_X86_64_NONE);
|
|
|
|
}
|
|
|
|
else
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_error("unexpected R_X86_64_TLSLD pattern");
|
2020-09-08 20:31:58 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R_X86_64_DTPOFF32:
|
|
|
|
case R_X86_64_TPOFF32:
|
|
|
|
{
|
|
|
|
ElfW(Sym) *sym;
|
|
|
|
Section *sec;
|
|
|
|
int32_t x;
|
|
|
|
|
|
|
|
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
2021-10-22 13:39:54 +08:00
|
|
|
sec = s1->sections[sym->st_shndx];
|
2020-09-08 20:31:58 +08:00
|
|
|
x = val - sec->sh_addr - sec->data_offset;
|
|
|
|
add32le(ptr, x);
|
|
|
|
}
|
|
|
|
break;
|
2022-05-08 00:10:59 +08:00
|
|
|
case R_X86_64_DTPOFF64:
|
|
|
|
case R_X86_64_TPOFF64:
|
|
|
|
{
|
|
|
|
ElfW(Sym) *sym;
|
|
|
|
Section *sec;
|
|
|
|
int32_t x;
|
|
|
|
|
|
|
|
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
|
|
|
sec = s1->sections[sym->st_shndx];
|
|
|
|
x = val - sec->sh_addr - sec->data_offset;
|
|
|
|
add64le(ptr, x);
|
|
|
|
}
|
|
|
|
break;
|
2020-09-08 20:31:58 +08:00
|
|
|
case R_X86_64_NONE:
|
|
|
|
break;
|
2016-12-16 00:01:22 +08:00
|
|
|
case R_X86_64_RELATIVE:
|
2017-12-13 00:57:20 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
2021-10-22 13:39:54 +08:00
|
|
|
add32le(ptr, val - s1->pe_imagebase);
|
2017-12-13 00:57:20 +08:00
|
|
|
#endif
|
2016-12-16 00:01:22 +08:00
|
|
|
/* do nothing */
|
|
|
|
break;
|
2022-04-12 13:11:52 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
|
|
|
|
type, (unsigned)addr, ptr, (unsigned)val);
|
|
|
|
break;
|
2016-11-12 23:16:06 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-06 04:40:59 +08:00
|
|
|
|
|
|
|
#endif /* !TARGET_DEFS_ONLY */
|