History

win64: fix pointer <-> unsigned long typecast issues

grischka committed 17 years ago

Commit 035918e1 parent 45987576 files · +34 −19Browse files

Unified · Split

6 files
  1. libtcc.c +7 −6
  2. tcc.h +11 −1
  3. tccelf.c +6 −6
  4. tccgen.c +4 −4
  5. tccpe.c +1 −1
  6. tccpp.c +5 −1
libtcc.c+7−6
@@ -191,7 +191,7 @@ static int put_elf_str(Section *s, const char *sym); · 190 unmodified lines
191191 static int put_elf_sym(Section *s,
192192 unsigned long value, unsigned long size,
193193 int info, int other, int shndx, const char *name);
194−static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
194+static int add_elf_sym(Section *s, uplong value, unsigned long size,
195195 int info, int other, int sh_num, const char *name);
196196 static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
197197 int type, int symbol);
@@ -1183,7 +1183,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename) · 985 unmodified lines
11831183 fd = open(filename, O_RDONLY | O_BINARY);
11841184 if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
11851185 printf("%s %*s%s\n", fd < 0 ? "nf":"->",
1186− (s1->include_stack_ptr - s1->include_stack), "", filename);
1186+ (int)(s1->include_stack_ptr - s1->include_stack), "", filename);
11871187 if (fd < 0)
11881188 return NULL;
11891189 bf = tcc_malloc(sizeof(BufferedFile));
@@ -1656,7 +1656,8 @@ static void sig_error(int signum, siginfo_t *siginf, void *puc) · 466 unmodified lines
16561656 int tcc_relocate(TCCState *s1, void *ptr)
16571657 {
16581658 Section *s;
1659− unsigned long offset, length, mem;
1659+ unsigned long offset, length;
1660+ uplong mem;
16601661 int i;
16611662
16621663 if (0 == s1->runtime_added) {
@@ -1674,7 +1675,7 @@ int tcc_relocate(TCCState *s1, void *ptr) · 11 unmodified lines
16741675 return -1;
16751676 }
16761677
1677− offset = 0, mem = (unsigned long)ptr;
1678+ offset = 0, mem = (uplong)ptr;
16781679 for(i = 1; i < s1->nb_sections; i++) {
16791680 s = s1->sections[i];
16801681 if (0 == (s->sh_flags & SHF_ALLOC))
@@ -1715,7 +1716,7 @@ int tcc_relocate(TCCState *s1, void *ptr) · 34 unmodified lines
17151716 continue;
17161717 length = s->data_offset;
17171718 // printf("%-12s %08x %04x\n", s->name, s->sh_addr, length);
1718− ptr = (void*)s->sh_addr;
1719+ ptr = (void*)(uplong)s->sh_addr;
17191720 if (NULL == s->data || s->sh_type == SHT_NOBITS)
17201721 memset(ptr, 0, length);
17211722 else
@@ -2155,7 +2156,7 @@ int tcc_add_library(TCCState *s, const char *libraryname) · 433 unmodified lines
21552156
21562157 int tcc_add_symbol(TCCState *s, const char *name, void *val)
21572158 {
2158− add_elf_sym(symtab_section, (unsigned long)val, 0,
2159+ add_elf_sym(symtab_section, (uplong)val, 0,
21592160 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
21602161 SHN_ABS, name);
21612162 return 0;
tcc.h+11−1
@@ -47,6 +47,9 @@ · 46 unmodified lines
4747 #define inline __inline
4848 #define inp next_inp
4949 #define dlclose FreeLibrary
50+#ifdef _WIN64
51+#define uplong unsigned long long
52+#endif
5053 #endif
5154
5255 #ifndef _WIN32
@@ -58,6 +61,10 @@ · 5 unmodified lines
5861
5962 #endif /* !CONFIG_TCCBOOT */
6063
64+#ifndef uplong
65+#define uplong unsigned long
66+#endif
67+
6168 #ifndef PAGESIZE
6269 #define PAGESIZE 4096
6370 #endif
@@ -204,7 +211,10 @@ typedef struct Sym { · 140 unmodified lines
204211 int *d; /* define token stream */
205212 };
206213 CType type; /* associated type */
207− struct Sym *next; /* next related symbol */
214+ union {
215+ struct Sym *next; /* next related symbol */
216+ long jnext; /* next jump label */
217+ };
208218 struct Sym *prev; /* prev symbol in stack */
209219 struct Sym *prev_tok; /* previous symbol for this token */
210220 } Sym;
tccelf.c+6−6
@@ -177,7 +177,7 @@ void *tcc_get_symbol(TCCState *s, const char *name) · 176 unmodified lines
177177 if (!sym_index)
178178 return NULL;
179179 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
180− return (void*)(long)sym->st_value;
180+ return (void*)(uplong)sym->st_value;
181181 }
182182
183183 void *tcc_get_symbol_err(TCCState *s, const char *name)
@@ -191,7 +191,7 @@ void *tcc_get_symbol_err(TCCState *s, const char *name) · 7 unmodified lines
191191
192192 /* add an elf symbol : check if it is already defined and patch
193193 it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
194−static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
194+static int add_elf_sym(Section *s, uplong value, unsigned long size,
195195 int info, int other, int sh_num, const char *name)
196196 {
197197 ElfW(Sym) *esym;
@@ -442,11 +442,11 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 244 unmodified lines
442442 name = strtab_section->data + sym->st_name;
443443 if (do_resolve) {
444444 #ifndef _WIN32
445− unsigned long addr;
445+ void *addr;
446446 name = symtab_section->link->data + sym->st_name;
447− addr = (unsigned long)resolve_sym(s1, name);
447+ addr = resolve_sym(s1, name);
448448 if (addr) {
449− sym->st_value = addr;
449+ sym->st_value = (uplong)addr;
450450 goto found;
451451 }
452452 #endif
@@ -1884,7 +1884,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 1431 unmodified lines
18841884
18851885 /* get entry point address */
18861886 if (file_type == TCC_OUTPUT_EXE)
1887− ehdr.e_entry = (unsigned long)tcc_get_symbol_err(s1, "_start");
1887+ ehdr.e_entry = (uplong)tcc_get_symbol_err(s1, "_start");
18881888 else
18891889 ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
18901890 }
tccgen.c+4−4
@@ -4088,9 +4088,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4087 unmodified lines
40884088 }
40894089 /* label already defined */
40904090 if (s->r & LABEL_FORWARD)
4091− s->next = (void *)gjmp((long)s->next);
4091+ s->jnext = gjmp(s->jnext);
40924092 else
4093− gjmp_addr((long)s->next);
4093+ gjmp_addr(s->jnext);
40944094 next();
40954095 } else {
40964096 expect("label identifier");
@@ -4106,12 +4106,12 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 9 unmodified lines
41064106 if (s) {
41074107 if (s->r == LABEL_DEFINED)
41084108 error("duplicate label '%s'", get_tok_str(s->v, NULL));
4109− gsym((long)s->next);
4109+ gsym(s->jnext);
41104110 s->r = LABEL_DEFINED;
41114111 } else {
41124112 s = label_push(&global_label_stack, b, LABEL_DEFINED);
41134113 }
4114− s->next = (void *)ind;
4114+ s->jnext = ind;
41154115 /* we accept this, but it is a mistake */
41164116 block_after_label:
41174117 if (tok == '}') {
tccpe.c+1−1
@@ -1548,7 +1548,7 @@ ST_FN void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) · 1547 unmodified lines
15481548 }
15491549
15501550 if (start_symbol) {
1551− addr = (ADDR3264)tcc_get_symbol_err(s1, start_symbol);
1551+ addr = (uplong)tcc_get_symbol_err(s1, start_symbol);
15521552 if (s1->output_type == TCC_OUTPUT_MEMORY && addr)
15531553 /* for -run GUI's, put '_runwinmain' instead of 'main' */
15541554 add_elf_sym(symtab_section,
tccpp.c+5−1
@@ -129,7 +129,11 @@ char *get_tok_str(int v, CValue *cv) · 128 unmodified lines
129129 case TOK_CLLONG:
130130 case TOK_CULLONG:
131131 /* XXX: not quite exact, but only useful for testing */
132+#ifdef _WIN32
133+ sprintf(p, "%u", (unsigned)cv->ull);
134+#else
132135 sprintf(p, "%Lu", cv->ull);
136+#endif
133137 break;
134138 case TOK_LCHAR:
135139 cstr_ccat(&cstr_buf, 'L');
@@ -947,7 +951,7 @@ static void label_pop(Sym **ptop, Sym *slast) · 811 unmodified lines
947951 if (s->c) {
948952 /* define corresponding symbol. A size of
949953 1 is put. */
950− put_extern_sym(s, cur_text_section, (long)s->next, 1);
954+ put_extern_sym(s, cur_text_section, s->jnext, 1);
951955 }
952956 }
953957 /* remove label */

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