mirror of
https://github.com/frida/tinycc
synced 2024-12-25 22:46:49 +03:00
0bf262864c
i386 target does not have PC relative loads. Its ABI therefore require ebx register to points to the GOT when executing a PLT entry. This means that PLT entry cannot be used transparently, the compiler needs to expect execution of a PLT entry to be able to use one, that is a PLT entry should only be created if the relocation explicitely asks for it (eg. R_386_PLT32). This patch creates a new target macro PCRELATIVE_DLLPLT to indicate whether a target can do a PC relative load in PLT entry when building a dynamic library. Executable do not normally pose a problem because they are loaded at a fixed address and thus the absolute address of GOT can be used. Note that in such a case, if the compiler does not use a PLT aware relocation for external access then the code relocation will fall on the dynamic loader since there is no PLT entry to relocate too.
60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
#ifdef TARGET_DEFS_ONLY
|
|
|
|
#define EM_TCC_TARGET EM_C60
|
|
|
|
/* relocation type for 32 bit data relocation */
|
|
#define R_DATA_32 R_C60_32
|
|
#define R_DATA_PTR R_C60_32
|
|
#define R_JMP_SLOT R_C60_JMP_SLOT
|
|
#define R_GLOB_DAT R_C60_GLOB_DAT
|
|
#define R_COPY R_C60_COPY
|
|
|
|
#define R_NUM R_C60_NUM
|
|
|
|
#define ELF_START_ADDR 0x00000400
|
|
#define ELF_PAGE_SIZE 0x1000
|
|
|
|
#define HAVE_SECTION_RELOC
|
|
#define PCRELATIVE_DLLPLT 0
|
|
|
|
#else /* !TARGET_DEFS_ONLY */
|
|
|
|
#include "tcc.h"
|
|
|
|
ST_DATA struct reloc_info relocs_info[R_NUM];
|
|
|
|
void relocate_init(Section *sr) {}
|
|
|
|
void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
|
|
{
|
|
switch(type) {
|
|
case R_C60_32:
|
|
*(int *)ptr += val;
|
|
break;
|
|
case R_C60LO16:
|
|
{
|
|
uint32_t orig;
|
|
|
|
/* put the low 16 bits of the absolute address add to what is
|
|
already there */
|
|
orig = ((*(int *)(ptr )) >> 7) & 0xffff;
|
|
orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16;
|
|
|
|
/* patch both at once - assumes always in pairs Low - High */
|
|
*(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) |
|
|
(((val+orig) & 0xffff) << 7);
|
|
*(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) |
|
|
((((val+orig)>>16) & 0xffff) << 7);
|
|
}
|
|
break;
|
|
case R_C60HI16:
|
|
break;
|
|
default:
|
|
fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
|
|
type, (unsigned) addr, ptr, (unsigned) val);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endif /* !TARGET_DEFS_ONLY */
|