History

portability: fix void* <-> target address conversion confusion

- #define addr_t as ElfW(Addr) - replace uplong by addr_t - #define TCC_HAS_RUNTIME_PLTGOT and use it

grischka committed 13 years ago

Commit 82bcbd01 parent 31864556 files · +136 −130Browse files

Unified · Split

6 files
  1. libtcc.c +6 −6
  2. tcc.h +60 −55
  3. tcccoff.c +1 −1
  4. tccelf.c +40 −37
  5. tccpe.c +7 −7
  6. tccrun.c +22 −24
libtcc.c+6−6
@@ -423,7 +423,7 @@ ST_FUNC Section *find_section(TCCState *s1, const char *name) · 422 unmodified lines
423423 /* update sym->c so that it points to an external symbol in section
424424 'section' with value 'value' */
425425 ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
426− uplong value, unsigned long size,
426+ addr_t value, unsigned long size,
427427 int can_add_underscore)
428428 {
429429 int sym_type, sym_bind, sh_num, info, other;
@@ -527,7 +527,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 97 unmodified lines
527527 }
528528
529529 ST_FUNC void put_extern_sym(Sym *sym, Section *section,
530− uplong value, unsigned long size)
530+ addr_t value, unsigned long size)
531531 {
532532 put_extern_sym2(sym, section, value, size, 1);
533533 }
@@ -1279,11 +1279,11 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) · 745 unmodified lines
12791279 LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val)
12801280 {
12811281 #ifdef TCC_TARGET_PE
1282− pe_putimport(s, 0, name, val);
1282+pe_putimport(s, 0, name, (uintptr_t)val);
12831283 #else
1284− add_elf_sym(symtab_section, (uplong)val, 0,
1285− ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1286− SHN_ABS, name);
1284+add_elf_sym(symtab_section, (uintptr_t)val, 0,
1285+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1286+ SHN_ABS, name);
12871287 #endif
12881288 return 0;
12891289 }
tcc.h+60−55
@@ -42,25 +42,28 @@ · 41 unmodified lines
4242 #include <setjmp.h>
4343 #include <time.h>
4444
45−#ifdef _WIN32
46−#include <windows.h>
47−#include <sys/timeb.h>
48−#include <io.h> /* open, close etc. */
49−#include <direct.h> /* getcwd */
50−#define inline __inline
51−#define inp next_inp
52−#ifdef LIBTCC_AS_DLL
53−# define LIBTCCAPI __declspec(dllexport)
54−# define PUB_FUNC LIBTCCAPI
55−#endif
56−#endif
57−
5845 #ifndef _WIN32
59−#include <unistd.h>
60−#include <sys/time.h>
61−#include <sys/ucontext.h>
62−#include <sys/mman.h>
63−#include <dlfcn.h>
46+# include <unistd.h>
47+# include <sys/time.h>
48+# include <sys/ucontext.h>
49+# include <sys/mman.h>
50+# include <dlfcn.h>
51+#else
52+# include <windows.h>
53+# include <sys/timeb.h>
54+# include <io.h> /* open, close etc. */
55+# include <direct.h> /* getcwd */
56+# ifdef __GNUC__
57+# include <stdint.h>
58+# else
59+ typedef UINT_PTR uintptr_t;
60+# endif
61+# define inline __inline
62+# define inp next_inp
63+# ifdef LIBTCC_AS_DLL
64+# define LIBTCCAPI __declspec(dllexport)
65+# define PUB_FUNC LIBTCCAPI
66+# endif
6467 #endif
6568
6669 #endif /* !CONFIG_TCCBOOT */
@@ -78,6 +81,27 @@ · 11 unmodified lines
7881 #endif
7982
8083 #include "elf.h"
84+#ifdef TCC_TARGET_X86_64
85+# define ELFCLASSW ELFCLASS64
86+# define ElfW(type) Elf##64##_##type
87+# define ELFW(type) ELF##64##_##type
88+# define ElfW_Rel ElfW(Rela)
89+# define SHT_RELX SHT_RELA
90+# define REL_SECTION_FMT ".rela%s"
91+/* XXX: DLL with PLT would only work with x86-64 for now */
92+# define TCC_OUTPUT_DLL_WITH_PLT
93+#else
94+# define ELFCLASSW ELFCLASS32
95+# define ElfW(type) Elf##32##_##type
96+# define ELFW(type) ELF##32##_##type
97+# define ElfW_Rel ElfW(Rel)
98+# define SHT_RELX SHT_REL
99+# define REL_SECTION_FMT ".rel%s"
100+#endif
101+
102+/* target address type */
103+#define addr_t ElfW(Addr)
104+
81105 #include "stab.h"
82106 #include "libtcc.h"
83107
@@ -139,13 +163,6 @@ · 55 unmodified lines
139163 # define CONFIG_TCC_BACKTRACE
140164 #endif
141165
142−/* target address type */
143−#if defined TCC_TARGET_X86_64 && (!defined __x86_64__ || defined _WIN32)
144−# define uplong unsigned long long
145−#else
146−# define uplong unsigned long
147−#endif
148−
149166 /* ------------ path configuration ------------ */
150167
151168 #ifndef CONFIG_SYSROOT
@@ -327,7 +344,7 @@ typedef struct Section { · 175 unmodified lines
327344 int sh_addralign; /* elf section alignment */
328345 int sh_entsize; /* elf entry size */
329346 unsigned long sh_size; /* section size (only used during output) */
330− uplong sh_addr; /* address at which the section is relocated */
347+ addr_t sh_addr; /* address at which the section is relocated */
331348 unsigned long sh_offset; /* file offset */
332349 int nb_hashed_syms; /* used to resize the hash table */
333350 struct Section *link; /* link to another section */
@@ -552,7 +569,7 @@ struct TCCState { · 218 unmodified lines
552569 int alacarte_link;
553570
554571 /* address of text section */
555− uplong text_addr;
572+ addr_t text_addr;
556573 int has_text_addr;
557574
558575 /* symbols to call at load-time / unload-time */
@@ -644,12 +661,12 @@ struct TCCState { · 85 unmodified lines
644661 #endif
645662 #endif
646663
647−#ifndef TCC_TARGET_PE
648−#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
664+#if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE \
665+ && (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM)
649666 /* write PLT and GOT here */
650667 char *runtime_plt_and_got;
651668 unsigned int runtime_plt_and_got_offset;
652−#endif
669+# define TCC_HAS_RUNTIME_PLTGOT
653670 #endif
654671 };
655672
@@ -1007,8 +1024,8 @@ ST_FUNC void *section_ptr_add(Section *sec, unsigned long size); · 351 unmodified lines
10071024 ST_FUNC void section_reserve(Section *sec, unsigned long size);
10081025 ST_FUNC Section *find_section(TCCState *s1, const char *name);
10091026
1010−ST_FUNC void put_extern_sym2(Sym *sym, Section *section, uplong value, unsigned long size, int can_add_underscore);
1011−ST_FUNC void put_extern_sym(Sym *sym, Section *section, uplong value, unsigned long size);
1027+ST_FUNC void put_extern_sym2(Sym *sym, Section *section, addr_t value, unsigned long size, int can_add_underscore);
1028+ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
10121029 ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
10131030
10141031 ST_INLN void sym_free(Sym *sym);
@@ -1187,8 +1204,8 @@ typedef struct { · 172 unmodified lines
11871204 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);
11881205
11891206 ST_FUNC int put_elf_str(Section *s, const char *sym);
1190−ST_FUNC int put_elf_sym(Section *s, uplong value, unsigned long size, int info, int other, int shndx, const char *name);
1191−ST_FUNC int add_elf_sym(Section *s, uplong value, unsigned long size, int info, int other, int sh_num, const char *name);
1207+ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1208+ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int sh_num, const char *name);
11921209 ST_FUNC int find_elf_sym(Section *s, const char *name);
11931210 ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
11941211
@@ -1204,12 +1221,16 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s); · 9 unmodified lines
12041221 ST_FUNC void tcc_add_linker_symbols(TCCState *s1);
12051222 ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
12061223 ST_FUNC int tcc_load_archive(TCCState *s1, int fd);
1207−ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
12081224 ST_FUNC void tcc_add_bcheck(TCCState *s1);
12091225
12101226 ST_FUNC void build_got_entries(TCCState *s1);
12111227 ST_FUNC void tcc_add_runtime(TCCState *s1);
12121228
1229+ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err);
1230+#ifdef TCC_IS_NATIVE
1231+ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
1232+#endif
1233+
12131234 #ifndef TCC_TARGET_PE
12141235 ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
12151236 ST_FUNC int tcc_load_ldscript(TCCState *s1);
@@ -1219,24 +1240,6 @@ ST_INLN void inp(void); · 3 unmodified lines
12191240 ST_FUNC int handle_eob(void);
12201241 #endif
12211242
1222−#ifdef TCC_TARGET_X86_64
1223−# define ELFCLASSW ELFCLASS64
1224−# define ElfW(type) Elf##64##_##type
1225−# define ELFW(type) ELF##64##_##type
1226−# define ElfW_Rel ElfW(Rela)
1227−# define SHT_RELX SHT_RELA
1228−# define REL_SECTION_FMT ".rela%s"
1229−/* XXX: DLL with PLT would only work with x86-64 for now */
1230−# define TCC_OUTPUT_DLL_WITH_PLT
1231−#else
1232−# define ELFCLASSW ELFCLASS32
1233−# define ElfW(type) Elf##32##_##type
1234−# define ELFW(type) ELF##32##_##type
1235−# define ElfW_Rel ElfW(Rel)
1236−# define SHT_RELX SHT_REL
1237−# define REL_SECTION_FMT ".rel%s"
1238−#endif
1239−
12401243 /* ------------ xxx-gen.c ------------ */
12411244
12421245 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); · 76 unmodified lines
13191322 #ifdef TCC_TARGET_PE
13201323 ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
13211324 ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
1322−ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, const void *value);
1325+ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
13231326 ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
13241327 /* tiny_impdef.c */
13251328 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); · 3 unmodified lines
13291332 #endif
13301333
13311334 /* ------------ tccrun.c ----------------- */
1335+#ifdef TCC_IS_NATIVE
13321336 #ifdef CONFIG_TCC_STATIC
13331337 #define RTLD_LAZY 0x001
13341338 #define RTLD_NOW 0x002
@@ -1339,7 +1343,7 @@ ST_FUNC void *dlopen(const char *filename, int flag); · 4 unmodified lines
13391343 ST_FUNC void dlclose(void *p);
13401344 //ST_FUNC const char *dlerror(void);
13411345 ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
1342−#elif !defined TCC_TARGET_PE || !defined _WIN32
1346+#elif !defined _WIN32
13431347 ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
13441348 #endif
13451349
@@ -1349,6 +1353,7 @@ ST_DATA const char **rt_bound_error_msg; · 3 unmodified lines
13491353 ST_DATA void *rt_prog_main;
13501354 PUB_FUNC void tcc_set_num_callers(int n);
13511355 #endif
1356+#endif
13521357
13531358 /********************************************************/
13541359 /* include the target specific definitions */
tcccoff.c+1−1
@@ -933,7 +933,7 @@ ST_FUNC int tcc_load_coff(TCCState * s1, int fd) · 932 unmodified lines
933933 if (name[0] == '_' && strcmp(name, "_main") != 0)
934934 name++;
935935
936− tcc_add_symbol(s1, name, (void*)(uplong)csym.n_value);
936+ tcc_add_symbol(s1, name, (void*)(uintptr_t)csym.n_value);
937937 }
938938 // skip any aux records
939939
tccelf.c+40−37
@@ -84,7 +84,7 @@ static void rebuild_hash(Section *s, unsigned int nb_buckets) · 83 unmodified lines
8484 }
8585
8686 /* return the symbol number */
87−ST_FUNC int put_elf_sym(Section *s, uplong value, unsigned long size,
87+ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size,
8888 int info, int other, int shndx, const char *name)
8989 {
9090 int name_offset, sym_index;
@@ -157,7 +157,7 @@ ST_FUNC int find_elf_sym(Section *s, const char *name) · 66 unmodified lines
157157 }
158158
159159 /* return elf symbol value, signal error if 'err' is nonzero */
160−static void *get_elf_sym_addr(TCCState *s, const char *name, int err)
160+ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err)
161161 {
162162 int sym_index;
163163 ElfW(Sym) *sym;
@@ -167,26 +167,28 @@ static void *get_elf_sym_addr(TCCState *s, const char *name, int err) · 3 unmodified lines
167167 if (!sym_index || sym->st_shndx == SHN_UNDEF) {
168168 if (err)
169169 tcc_error("%s not defined", name);
170− return NULL;
170+ return 0;
171171 }
172− return (void*)(uplong)sym->st_value;
172+ return sym->st_value;
173173 }
174174
175+#ifdef TCC_IS_NATIVE
175176 /* return elf symbol value */
176177 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name)
177178 {
178− return get_elf_sym_addr(s, name, 0);
179+ return (void*)get_elf_sym_addr(s, name, 0);
179180 }
180181
181182 /* return elf symbol value or error */
182−ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name)
183+ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name)
183184 {
184− return get_elf_sym_addr(s, name, 1);
185+ return (void*)get_elf_sym_addr(s, name, 1);
185186 }
187+#endif
186188
187189 /* add an elf symbol : check if it is already defined and patch
188190 it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
189−ST_FUNC int add_elf_sym(Section *s, uplong value, unsigned long size,
191+ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size,
190192 int info, int other, int sh_num, const char *name)
191193 {
192194 ElfW(Sym) *esym;
@@ -431,12 +433,12 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve) · 238 unmodified lines
431433 if (sh_num == SHN_UNDEF) {
432434 name = strtab_section->data + sym->st_name;
433435 if (do_resolve) {
434−#if !defined TCC_TARGET_PE || !defined _WIN32
436+#if defined TCC_IS_NATIVE && !defined _WIN32
435437 void *addr;
436438 name = symtab_section->link->data + sym->st_name;
437439 addr = resolve_sym(s1, name);
438440 if (addr) {
439− sym->st_value = (uplong)addr;
441+ sym->st_value = (addr_t)addr;
440442 goto found;
441443 }
442444 #endif
@@ -469,10 +471,10 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve) · 26 unmodified lines
469471 }
470472 }
471473
472−#ifndef TCC_TARGET_PE
474+#ifdef TCC_HAS_RUNTIME_PLTGOT
473475 #ifdef TCC_TARGET_X86_64
474476 #define JMP_TABLE_ENTRY_SIZE 14
475−static uplong add_jmp_table(TCCState *s1, uplong val)
477+static addr_t add_jmp_table(TCCState *s1, addr_t val)
476478 {
477479 char *p = s1->runtime_plt_and_got + s1->runtime_plt_and_got_offset;
478480 s1->runtime_plt_and_got_offset += JMP_TABLE_ENTRY_SIZE;
@@ -480,30 +482,30 @@ static uplong add_jmp_table(TCCState *s1, uplong val) · 1 unmodified line
480482 p[0] = 0xff;
481483 p[1] = 0x25;
482484 *(int *)(p + 2) = 0;
483− *(uplong *)(p + 6) = val;
484− return (uplong)p;
485+ *(addr_t *)(p + 6) = val;
486+ return (addr_t)p;
485487 }
486488
487−static uplong add_got_table(TCCState *s1, uplong val)
489+static addr_t add_got_table(TCCState *s1, addr_t val)
488490 {
489− uplong *p = (uplong *)(s1->runtime_plt_and_got + s1->runtime_plt_and_got_offset);
490− s1->runtime_plt_and_got_offset += sizeof(uplong);
491+ addr_t *p = (addr_t *)(s1->runtime_plt_and_got + s1->runtime_plt_and_got_offset);
492+ s1->runtime_plt_and_got_offset += sizeof(addr_t);
491493 *p = val;
492− return (uplong)p;
494+ return (addr_t)p;
493495 }
494496 #elif defined TCC_TARGET_ARM
495497 #define JMP_TABLE_ENTRY_SIZE 8
496−static uplong add_jmp_table(TCCState *s1, int val)
498+static addr_t add_jmp_table(TCCState *s1, int val)
497499 {
498500 uint32_t *p = (uint32_t *)(s1->runtime_plt_and_got + s1->runtime_plt_and_got_offset);
499501 s1->runtime_plt_and_got_offset += JMP_TABLE_ENTRY_SIZE;
500502 /* ldr pc, [pc, #-4] */
501503 p[0] = 0xE51FF004;
502504 p[1] = val;
503− return (uplong)p;
505+ return (addr_t)p;
504506 }
505507 #endif
506−#endif
508+#endif /* def TCC_HAS_RUNTIME_PLTGOT */
507509
508510 /* relocate a given section (CPU dependent) */
509511 ST_FUNC void relocate_section(TCCState *s1, Section *s)
@@ -513,7 +515,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 3 unmodified lines
513515 ElfW(Sym) *sym;
514516 int type, sym_index;
515517 unsigned char *ptr;
516− uplong val, addr;
518+ addr_t val, addr;
517519 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
518520 int esym_index;
519521 #endif
@@ -612,13 +614,14 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 92 unmodified lines
612614 is_call = (type == R_ARM_CALL);
613615 x += val - addr;
614616 h = x & 2;
615−#ifndef TCC_TARGET_PE
616− if ((x & 3) || x >= 0x2000000 || x < -0x2000000)
617− if (!(x & 3) || !blx_avail || !is_call)
618− if (s1->output_type == TCC_OUTPUT_MEMORY) {
617+#ifdef TCC_HAS_RUNTIME_PLTGOT
618+ if (s1->output_type == TCC_OUTPUT_MEMORY) {
619+ if ((x & 3) || x >= 0x2000000 || x < -0x2000000)
620+ if (!(x & 3) || !blx_avail || !is_call) {
619621 x += add_jmp_table(s1, val) - val; /* add veneer */
620622 is_thumb = 0; /* Veneer uses ARM instructions */
621623 }
624+ }
622625 #endif
623626 if ((x & 3) || x >= 0x2000000 || x < -0x2000000)
624627 if (!(x & 3) || !blx_avail || !is_call)
@@ -770,8 +773,8 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 145 unmodified lines
770773 *(int*)ptr ^= 0xE12FFF10 ^ 0xE1A0F000; /* BX Rm -> MOV PC, Rm */
771774 break;
772775 default:
773− fprintf(stderr,"FIXME: handle reloc type %x at %x [%.8x] to %x\n",
774− type, (unsigned)addr, (unsigned)(uplong)ptr, (unsigned)val);
776+ fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
777+ type, (unsigned)addr, ptr, (unsigned)val);
775778 break;
776779 #elif defined(TCC_TARGET_C67)
777780 case R_C60_32:
@@ -796,8 +799,8 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 18 unmodified lines
796799 case R_C60HI16:
797800 break;
798801 default:
799− fprintf(stderr,"FIXME: handle reloc type %x at %x [%.8x] to %x\n",
800− type, (unsigned)addr, (unsigned)(uplong)ptr, (unsigned)val);
802+ fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
803+ type, (unsigned)addr, ptr, (unsigned)val);
801804 break;
802805 #elif defined(TCC_TARGET_X86_64)
803806 case R_X86_64_64:
@@ -837,7 +840,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 33 unmodified lines
837840 long long diff;
838841 diff = (long long)val - addr;
839842 if (diff <= -2147483647 || diff > 2147483647) {
840−#ifndef TCC_TARGET_PE
843+#ifdef TCC_HAS_RUNTIME_PLTGOT
841844 /* XXX: naive support for over 32bit jump */
842845 if (s1->output_type == TCC_OUTPUT_MEMORY) {
843846 val = (add_jmp_table(s1, val - rel->r_addend) +
@@ -858,7 +861,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 14 unmodified lines
858861 *(int *)ptr = val - rel->r_addend;
859862 break;
860863 case R_X86_64_GOTPCREL:
861−#ifndef TCC_TARGET_PE
864+#ifdef TCC_HAS_RUNTIME_PLTGOT
862865 if (s1->output_type == TCC_OUTPUT_MEMORY) {
863866 val = add_got_table(s1, val - rel->r_addend) + rel->r_addend;
864867 *(int *)ptr += val - addr;
@@ -1275,7 +1278,7 @@ ST_FUNC Section *new_symtab(TCCState *s1, · 410 unmodified lines
12751278 }
12761279
12771280 /* put dynamic tag */
1278−static void put_dt(Section *dynamic, int dt, uplong val)
1281+static void put_dt(Section *dynamic, int dt, addr_t val)
12791282 {
12801283 ElfW(Dyn) *dyn;
12811284 dyn = section_ptr_add(dynamic, sizeof(ElfW(Dyn)));
@@ -1545,7 +1548,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 263 unmodified lines
15451548 int *section_order;
15461549 int shnum, i, phnum, file_offset, offset, size, j, sh_order_index, k;
15471550 long long tmp;
1548− uplong addr;
1551+ addr_t addr;
15491552 Section *strsec, *s;
15501553 ElfW(Shdr) shdr, *sh;
15511554 ElfW(Phdr) *phdr, *ph;
@@ -1553,9 +1556,9 @@ static int elf_output_file(TCCState *s1, const char *filename) · 1 unmodified line
15531556 unsigned long saved_dynamic_data_offset;
15541557 ElfW(Sym) *sym;
15551558 int type, file_type;
1556− uplong rel_addr, rel_size;
1559+ addr_t rel_addr, rel_size;
15571560 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1558− uplong bss_addr, bss_size;
1561+ addr_t bss_addr, bss_size;
15591562 #endif
15601563
15611564 file_type = s1->output_type;
@@ -2191,7 +2194,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 629 unmodified lines
21912194
21922195 /* get entry point address */
21932196 if (file_type == TCC_OUTPUT_EXE)
2194− ehdr.e_entry = (uplong)tcc_get_symbol_err(s1, "_start");
2197+ ehdr.e_entry = get_elf_sym_addr(s1, "_start", 1);
21952198 else
21962199 ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
21972200 }
tccpe.c+7−7
@@ -1,4 +1,4 @@
1− /*
1+/*
22 * TCCPE.C - PE file output for the Tiny C Compiler
33 *
44 * Copyright (c) 2005-2007 grischka
@@ -1480,11 +1480,11 @@ ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2) · 1475 unmodified lines
14801480 return v2;
14811481 }
14821482
1483−ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, const void *value)
1483+ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value)
14841484 {
14851485 return add_elf_sym(
14861486 s1->dynsymtab_section,
1487− (uplong)value,
1487+ value,
14881488 dllindex, /* st_size */
14891489 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE),
14901490 0,
@@ -1613,7 +1613,7 @@ static int pe_load_def(TCCState *s1, FILE *fp) · 122 unmodified lines
16131613 ++state;
16141614
16151615 default:
1616− pe_putimport(s1, dllindex, p, NULL);
1616+ pe_putimport(s1, dllindex, p, 0);
16171617 continue;
16181618 }
16191619 }
@@ -1635,7 +1635,7 @@ static int pe_load_dll(TCCState *s1, const char *dllname, FILE *fp) · 15 unmodified lines
16351635 return -1;
16361636 index = add_dllref(s1, dllname);
16371637 for (q = p; *q; q += 1 + strlen(q))
1638− pe_putimport(s1, index, q, NULL);
1638+ pe_putimport(s1, index, q, 0);
16391639 tcc_free(p);
16401640 return 0;
16411641 }
@@ -1729,7 +1729,7 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack) · 87 unmodified lines
17291729 static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe)
17301730 {
17311731 const char *start_symbol;
1732− unsigned long addr = 0;
1732+ ADDR3264 addr = 0;
17331733 int pe_type = 0;
17341734
17351735 if (find_elf_sym(symtab_section, PE_STDSYM("WinMain","@16")))
@@ -1781,7 +1781,7 @@ static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) · 45 unmodified lines
17811781 pe_type = PE_RUN;
17821782
17831783 if (start_symbol) {
1784− addr = (uplong)tcc_get_symbol_err(s1, start_symbol);
1784+ addr = get_elf_sym_addr(s1, start_symbol, 1);
17851785 if (PE_RUN == pe_type && addr)
17861786 /* for -run GUI's, put '_runwinmain' instead of 'main' */
17871787 add_elf_sym(symtab_section,
tccrun.c+22−24
@@ -35,7 +35,7 @@ ST_DATA void *rt_prog_main; · 34 unmodified lines
3535
3636 static void set_pages_executable(void *ptr, unsigned long length);
3737 static void set_exception_handler(void);
38−static int rt_get_caller_pc(uplong *paddr, ucontext_t *uc, int level);
38+static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level);
3939 static void rt_error(ucontext_t *uc, const char *fmt, ...);
4040 static int tcc_relocate_ex(TCCState *s1, void *ptr);
4141
@@ -127,7 +127,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 85 unmodified lines
127127 {
128128 Section *s;
129129 unsigned long offset, length;
130− uplong mem;
130+ addr_t mem;
131131 int i;
132132
133133 if (0 == s1->runtime_added) {
@@ -145,7 +145,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 11 unmodified lines
145145 return -1;
146146 }
147147
148− offset = 0, mem = (uplong)ptr;
148+ offset = 0, mem = (addr_t)ptr;
149149 for(i = 1; i < s1->nb_sections; i++) {
150150 s = s1->sections[i];
151151 if (0 == (s->sh_flags & SHF_ALLOC))
@@ -161,7 +161,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 9 unmodified lines
161161 if (s1->nb_errors)
162162 return -1;
163163
164−#if (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM) && !defined TCC_TARGET_PE
164+#ifdef TCC_HAS_RUNTIME_PLTGOT
165165 s1->runtime_plt_and_got_offset = 0;
166166 s1->runtime_plt_and_got = (char *)(mem + offset);
167167 /* double the size of the buffer for got and plt entries
@@ -185,7 +185,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 17 unmodified lines
185185 continue;
186186 length = s->data_offset;
187187 // printf("%-12s %08x %04x\n", s->name, s->sh_addr, length);
188− ptr = (void*)(uplong)s->sh_addr;
188+ ptr = (void*)s->sh_addr;
189189 if (NULL == s->data || s->sh_type == SHT_NOBITS)
190190 memset(ptr, 0, length);
191191 else
@@ -195,7 +195,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 3 unmodified lines
195195 set_pages_executable(ptr, length);
196196 }
197197
198−#if (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM) && !defined TCC_TARGET_PE
198+#ifdef TCC_HAS_RUNTIME_PLTGOT
199199 set_pages_executable(s1->runtime_plt_and_got,
200200 s1->runtime_plt_and_got_offset);
201201 #endif
@@ -215,17 +215,15 @@ static void set_pages_executable(void *ptr, unsigned long length) · 13 unmodified lines
215215 unsigned long old_protect;
216216 VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
217217 #else
218− unsigned long start, end;
219− start = (uplong)ptr & ~(PAGESIZE - 1);
220− end = (uplong)ptr + length;
218+ addr_t start, end;
219+ start = (addr_t)ptr & ~(PAGESIZE - 1);
220+ end = (addr_t)ptr + length;
221221 end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
222222 mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
223223 #endif
224224 }
225225
226226 /* ------------------------------------------------------------- */
227−#endif /* TCC_IS_NATIVE */
228−
229227 #ifdef CONFIG_TCC_BACKTRACE
230228
231229 PUB_FUNC void tcc_set_num_callers(int n)
@@ -235,10 +233,10 @@ PUB_FUNC void tcc_set_num_callers(int n) · 3 unmodified lines
235233
236234 /* print the position in the source file of PC value 'pc' by reading
237235 the stabs debug information */
238−static uplong rt_printline(uplong wanted_pc, const char *msg)
236+static addr_t rt_printline(addr_t wanted_pc, const char *msg)
239237 {
240238 char func_name[128], last_func_name[128];
241− uplong func_addr, last_pc, pc;
239+ addr_t func_addr, last_pc, pc;
242240 const char *incl_files[INCLUDE_STACK_SIZE];
243241 int incl_index, len, last_line_num, i;
244242 const char *str, *p;
@@ -257,7 +255,7 @@ static uplong rt_printline(uplong wanted_pc, const char *msg) · 12 unmodified lines
257255 func_addr = 0;
258256 incl_index = 0;
259257 last_func_name[0] = '\0';
260− last_pc = (uplong)-1;
258+ last_pc = (addr_t)-1;
261259 last_line_num = 1;
262260
263261 if (!stab_sym)
@@ -380,7 +378,7 @@ no_stabs: · 116 unmodified lines
380378 static void rt_error(ucontext_t *uc, const char *fmt, ...)
381379 {
382380 va_list ap;
383− uplong pc;
381+ addr_t pc;
384382 int i;
385383
386384 fprintf(stderr, "Runtime error: ");
@@ -393,7 +391,7 @@ static void rt_error(ucontext_t *uc, const char *fmt, ...) · 6 unmodified lines
393391 if (rt_get_caller_pc(&pc, uc, i) < 0)
394392 break;
395393 pc = rt_printline(pc, i ? "by" : "at");
396− if (pc == (uplong)rt_prog_main && pc)
394+ if (pc == (addr_t)rt_prog_main && pc)
397395 break;
398396 }
399397 }
@@ -464,7 +462,7 @@ static void set_exception_handler(void) · 64 unmodified lines
464462 #endif
465463
466464 /* return the PC at frame level 'level'. Return non zero if not found */
467−static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level)
465+static int rt_get_caller_pc(addr_t *paddr, ucontext_t *uc, int level)
468466 {
469467 unsigned long fp;
470468 int i;
@@ -634,17 +632,17 @@ static void set_exception_handler(void) · 163 unmodified lines
634632 static void win64_add_function_table(TCCState *s1)
635633 {
636634 RtlAddFunctionTable(
637− (RUNTIME_FUNCTION*)(uplong)s1->uw_pdata->sh_addr,
635+ (RUNTIME_FUNCTION*)s1->uw_pdata->sh_addr,
638636 s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
639− (uplong)text_section->sh_addr
637+ text_section->sh_addr
640638 );
641639 }
642640 #endif
643641
644642 /* return the PC at frame level 'level'. Return non zero if not found */
645−static int rt_get_caller_pc(uplong *paddr, CONTEXT *uc, int level)
643+static int rt_get_caller_pc(addr_t *paddr, CONTEXT *uc, int level)
646644 {
647− uplong fp, pc;
645+ addr_t fp, pc;
648646 int i;
649647 #ifdef _WIN64
650648 pc = uc->Rip;
@@ -658,9 +656,9 @@ static int rt_get_caller_pc(uplong *paddr, CONTEXT *uc, int level) · 7 unmodified lines
658656 /* XXX: check address validity with program info */
659657 if (fp <= 0x1000 || fp >= 0xc0000000)
660658 return -1;
661− fp = ((uplong*)fp)[0];
659+ fp = ((addr_t*)fp)[0];
662660 }
663− pc = ((uplong*)fp)[1];
661+ pc = ((addr_t*)fp)[1];
664662 }
665663 *paddr = pc;
666664 return 0;
@@ -730,5 +728,5 @@ ST_FUNC void *resolve_sym(TCCState *s1, const char *sym) · 63 unmodified lines
730728 }
731729
732730 #endif /* CONFIG_TCC_STATIC */
733−
731+#endif /* TCC_IS_NATIVE */
734732 /* ------------------------------------------------------------- */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t