mirror of
https://github.com/frida/tinycc
synced 2025-01-12 06:39:51 +03:00
Add support for indirect functions as externals.
Add link support to use indirect functions defined in external modules
This commit is contained in:
parent
82c5edb31c
commit
bcc9137a10
1
elf.h
1
elf.h
@ -436,6 +436,7 @@ typedef struct
|
|||||||
#define STT_SECTION 3 /* Symbol associated with a section */
|
#define STT_SECTION 3 /* Symbol associated with a section */
|
||||||
#define STT_FILE 4 /* Symbol's name is file name */
|
#define STT_FILE 4 /* Symbol's name is file name */
|
||||||
#define STT_NUM 5 /* Number of defined types. */
|
#define STT_NUM 5 /* Number of defined types. */
|
||||||
|
#define STT_GNU_IFUNC 10 /* Symbol is a indirect code object */
|
||||||
#define STT_LOOS 11 /* Start of OS-specific */
|
#define STT_LOOS 11 /* Start of OS-specific */
|
||||||
#define STT_HIOS 12 /* End of OS-specific */
|
#define STT_HIOS 12 /* End of OS-specific */
|
||||||
#define STT_LOPROC 13 /* Start of processor-specific */
|
#define STT_LOPROC 13 /* Start of processor-specific */
|
||||||
|
14
tccelf.c
14
tccelf.c
@ -1514,9 +1514,10 @@ static int elf_output_file(TCCState *s1, const char *filename)
|
|||||||
build_got(s1);
|
build_got(s1);
|
||||||
|
|
||||||
/* scan for undefined symbols and see if they are in the
|
/* scan for undefined symbols and see if they are in the
|
||||||
dynamic symbols. If a symbol STT_FUNC is found, then we
|
dynamic symbols. If a symbol STT_FUNC or STT_GNU_IFUNC
|
||||||
add it in the PLT. If a symbol STT_OBJECT is found, we
|
is found, then we add it in the PLT. If a symbol
|
||||||
add it in the .bss section with a suitable relocation */
|
STT_OBJECT is found, we add it in the .bss section with
|
||||||
|
a suitable relocation */
|
||||||
sym_end = (ElfW(Sym) *)(symtab_section->data +
|
sym_end = (ElfW(Sym) *)(symtab_section->data +
|
||||||
symtab_section->data_offset);
|
symtab_section->data_offset);
|
||||||
if (file_type == TCC_OUTPUT_EXE) {
|
if (file_type == TCC_OUTPUT_EXE) {
|
||||||
@ -1529,7 +1530,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
|
|||||||
if (sym_index) {
|
if (sym_index) {
|
||||||
esym = &((ElfW(Sym) *)s1->dynsymtab_section->data)[sym_index];
|
esym = &((ElfW(Sym) *)s1->dynsymtab_section->data)[sym_index];
|
||||||
type = ELFW(ST_TYPE)(esym->st_info);
|
type = ELFW(ST_TYPE)(esym->st_info);
|
||||||
if (type == STT_FUNC) {
|
if ((type == STT_FUNC) || (type == STT_GNU_IFUNC)) {
|
||||||
put_got_entry(s1, R_JMP_SLOT, esym->st_size,
|
put_got_entry(s1, R_JMP_SLOT, esym->st_size,
|
||||||
esym->st_info,
|
esym->st_info,
|
||||||
sym - (ElfW(Sym) *)symtab_section->data);
|
sym - (ElfW(Sym) *)symtab_section->data);
|
||||||
@ -1626,8 +1627,9 @@ static int elf_output_file(TCCState *s1, const char *filename)
|
|||||||
sym++) {
|
sym++) {
|
||||||
if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
|
if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
|
||||||
#if defined(TCC_OUTPUT_DLL_WITH_PLT)
|
#if defined(TCC_OUTPUT_DLL_WITH_PLT)
|
||||||
if (ELFW(ST_TYPE)(sym->st_info) == STT_FUNC &&
|
if ((ELFW(ST_TYPE)(sym->st_info) == STT_FUNC ||
|
||||||
sym->st_shndx == SHN_UNDEF) {
|
ELFW(ST_TYPE)(sym->st_info) == STT_GNU_IFUNC)
|
||||||
|
&& sym->st_shndx == SHN_UNDEF) {
|
||||||
put_got_entry(s1, R_JMP_SLOT, sym->st_size,
|
put_got_entry(s1, R_JMP_SLOT, sym->st_size,
|
||||||
sym->st_info,
|
sym->st_info,
|
||||||
sym - (ElfW(Sym) *)symtab_section->data);
|
sym - (ElfW(Sym) *)symtab_section->data);
|
||||||
|
6
tccrun.c
6
tccrun.c
@ -306,7 +306,11 @@ static uplong rt_printline(uplong wanted_pc)
|
|||||||
sym < sym_end;
|
sym < sym_end;
|
||||||
sym++) {
|
sym++) {
|
||||||
type = ELFW(ST_TYPE)(sym->st_info);
|
type = ELFW(ST_TYPE)(sym->st_info);
|
||||||
if (type == STT_FUNC) {
|
if (type == STT_FUNC
|
||||||
|
#ifdef STT_GNU_IFUNC
|
||||||
|
|| type == STT_GNU_IFUNC
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
if (wanted_pc >= sym->st_value &&
|
if (wanted_pc >= sym->st_value &&
|
||||||
wanted_pc < sym->st_value + sym->st_size) {
|
wanted_pc < sym->st_value + sym->st_size) {
|
||||||
pstrcpy(last_func_name, sizeof(last_func_name),
|
pstrcpy(last_func_name, sizeof(last_func_name),
|
||||||
|
Loading…
Reference in New Issue
Block a user