diff options
Diffstat (limited to 'tcc.h')
| -rw-r--r-- | tcc.h | 115 |
1 files changed, 60 insertions, 55 deletions
@@ -42,25 +42,28 @@ #include <setjmp.h> #include <time.h> -#ifdef _WIN32 -#include <windows.h> -#include <sys/timeb.h> -#include <io.h> /* open, close etc. */ -#include <direct.h> /* getcwd */ -#define inline __inline -#define inp next_inp -#ifdef LIBTCC_AS_DLL -# define LIBTCCAPI __declspec(dllexport) -# define PUB_FUNC LIBTCCAPI -#endif -#endif - #ifndef _WIN32 -#include <unistd.h> -#include <sys/time.h> -#include <sys/ucontext.h> -#include <sys/mman.h> -#include <dlfcn.h> +# include <unistd.h> +# include <sys/time.h> +# include <sys/ucontext.h> +# include <sys/mman.h> +# include <dlfcn.h> +#else +# include <windows.h> +# include <sys/timeb.h> +# include <io.h> /* open, close etc. */ +# include <direct.h> /* getcwd */ +# ifdef __GNUC__ +# include <stdint.h> +# else + typedef UINT_PTR uintptr_t; +# endif +# define inline __inline +# define inp next_inp +# ifdef LIBTCC_AS_DLL +# define LIBTCCAPI __declspec(dllexport) +# define PUB_FUNC LIBTCCAPI +# endif #endif #endif /* !CONFIG_TCCBOOT */ @@ -78,6 +81,27 @@ #endif #include "elf.h" +#ifdef TCC_TARGET_X86_64 +# define ELFCLASSW ELFCLASS64 +# define ElfW(type) Elf##64##_##type +# define ELFW(type) ELF##64##_##type +# define ElfW_Rel ElfW(Rela) +# define SHT_RELX SHT_RELA +# define REL_SECTION_FMT ".rela%s" +/* XXX: DLL with PLT would only work with x86-64 for now */ +# define TCC_OUTPUT_DLL_WITH_PLT +#else +# define ELFCLASSW ELFCLASS32 +# define ElfW(type) Elf##32##_##type +# define ELFW(type) ELF##32##_##type +# define ElfW_Rel ElfW(Rel) +# define SHT_RELX SHT_REL +# define REL_SECTION_FMT ".rel%s" +#endif + +/* target address type */ +#define addr_t ElfW(Addr) + #include "stab.h" #include "libtcc.h" @@ -139,13 +163,6 @@ # define CONFIG_TCC_BACKTRACE #endif -/* target address type */ -#if defined TCC_TARGET_X86_64 && (!defined __x86_64__ || defined _WIN32) -# define uplong unsigned long long -#else -# define uplong unsigned long -#endif - /* ------------ path configuration ------------ */ #ifndef CONFIG_SYSROOT @@ -327,7 +344,7 @@ typedef struct Section { int sh_addralign; /* elf section alignment */ int sh_entsize; /* elf entry size */ unsigned long sh_size; /* section size (only used during output) */ - uplong sh_addr; /* address at which the section is relocated */ + addr_t sh_addr; /* address at which the section is relocated */ unsigned long sh_offset; /* file offset */ int nb_hashed_syms; /* used to resize the hash table */ struct Section *link; /* link to another section */ @@ -552,7 +569,7 @@ struct TCCState { int alacarte_link; /* address of text section */ - uplong text_addr; + addr_t text_addr; int has_text_addr; /* symbols to call at load-time / unload-time */ @@ -644,12 +661,12 @@ struct TCCState { #endif #endif -#ifndef TCC_TARGET_PE -#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM +#if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE \ + && (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM) /* write PLT and GOT here */ char *runtime_plt_and_got; unsigned int runtime_plt_and_got_offset; -#endif +# define TCC_HAS_RUNTIME_PLTGOT #endif }; @@ -1007,8 +1024,8 @@ ST_FUNC void *section_ptr_add(Section *sec, unsigned long size); ST_FUNC void section_reserve(Section *sec, unsigned long size); ST_FUNC Section *find_section(TCCState *s1, const char *name); -ST_FUNC void put_extern_sym2(Sym *sym, Section *section, uplong value, unsigned long size, int can_add_underscore); -ST_FUNC void put_extern_sym(Sym *sym, Section *section, uplong value, unsigned long size); +ST_FUNC void put_extern_sym2(Sym *sym, Section *section, addr_t value, unsigned long size, int can_add_underscore); +ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size); ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type); ST_INLN void sym_free(Sym *sym); @@ -1187,8 +1204,8 @@ typedef struct { ST_FUNC Section *new_symtab(TCCState *s1, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags); ST_FUNC int put_elf_str(Section *s, const char *sym); -ST_FUNC int put_elf_sym(Section *s, uplong value, unsigned long size, int info, int other, int shndx, const char *name); -ST_FUNC int add_elf_sym(Section *s, uplong value, unsigned long size, int info, int other, int sh_num, const char *name); +ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name); +ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int sh_num, const char *name); ST_FUNC int find_elf_sym(Section *s, const char *name); ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol); @@ -1204,12 +1221,16 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s); ST_FUNC void tcc_add_linker_symbols(TCCState *s1); ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset); ST_FUNC int tcc_load_archive(TCCState *s1, int fd); -ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name); ST_FUNC void tcc_add_bcheck(TCCState *s1); ST_FUNC void build_got_entries(TCCState *s1); ST_FUNC void tcc_add_runtime(TCCState *s1); +ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err); +#ifdef TCC_IS_NATIVE +ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name); +#endif + #ifndef TCC_TARGET_PE ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level); ST_FUNC int tcc_load_ldscript(TCCState *s1); @@ -1219,24 +1240,6 @@ ST_INLN void inp(void); ST_FUNC int handle_eob(void); #endif -#ifdef TCC_TARGET_X86_64 -# define ELFCLASSW ELFCLASS64 -# define ElfW(type) Elf##64##_##type -# define ELFW(type) ELF##64##_##type -# define ElfW_Rel ElfW(Rela) -# define SHT_RELX SHT_RELA -# define REL_SECTION_FMT ".rela%s" -/* XXX: DLL with PLT would only work with x86-64 for now */ -# define TCC_OUTPUT_DLL_WITH_PLT -#else -# define ELFCLASSW ELFCLASS32 -# define ElfW(type) Elf##32##_##type -# define ELFW(type) ELF##32##_##type -# define ElfW_Rel ElfW(Rel) -# define SHT_RELX SHT_REL -# define REL_SECTION_FMT ".rel%s" -#endif - /* ------------ xxx-gen.c ------------ */ ST_FUNC void gsym_addr(int t, int a); @@ -1319,7 +1322,7 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str); #ifdef TCC_TARGET_PE ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd); ST_FUNC int pe_output_file(TCCState * s1, const char *filename); -ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, const void *value); +ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value); ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2); /* tiny_impdef.c */ ST_FUNC char *get_export_names(FILE *fp); @@ -1329,6 +1332,7 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack); #endif /* ------------ tccrun.c ----------------- */ +#ifdef TCC_IS_NATIVE #ifdef CONFIG_TCC_STATIC #define RTLD_LAZY 0x001 #define RTLD_NOW 0x002 @@ -1339,7 +1343,7 @@ ST_FUNC void *dlopen(const char *filename, int flag); ST_FUNC void dlclose(void *p); //ST_FUNC const char *dlerror(void); ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol); -#elif !defined TCC_TARGET_PE || !defined _WIN32 +#elif !defined _WIN32 ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol); #endif @@ -1349,6 +1353,7 @@ ST_DATA const char **rt_bound_error_msg; ST_DATA void *rt_prog_main; PUB_FUNC void tcc_set_num_callers(int n); #endif +#endif /********************************************************/ /* include the target specific definitions */ |
