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
191static int put_elf_sym(Section *s, 191static int put_elf_sym(Section *s,
192 unsigned long value, unsigned long size,192 unsigned long value, unsigned long size,
193 int info, int other, int shndx, const char *name);193 int info, int other, int shndx, const char *name);
194static int add_elf_sym(Section *s, unsigned long value, unsigned long size,194static int add_elf_sym(Section *s, uplong value, unsigned long size,
195 int info, int other, int sh_num, const char *name);195 int info, int other, int sh_num, const char *name);
196static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,196static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
197 int type, int symbol);197 int type, int symbol);
@@ -1183,7 +1183,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename) · 985 unmodified lines
1183 fd = open(filename, O_RDONLY | O_BINARY);1183 fd = open(filename, O_RDONLY | O_BINARY);
1184 if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)1184 if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
1185 printf("%s %*s%s\n", fd < 0 ? "nf":"->",1185 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);
1187 if (fd < 0)1187 if (fd < 0)
1188 return NULL;1188 return NULL;
1189 bf = tcc_malloc(sizeof(BufferedFile));1189 bf = tcc_malloc(sizeof(BufferedFile));
@@ -1656,7 +1656,8 @@ static void sig_error(int signum, siginfo_t *siginf, void *puc) · 466 unmodified lines
1656int tcc_relocate(TCCState *s1, void *ptr)1656int tcc_relocate(TCCState *s1, void *ptr)
1657{1657{
1658 Section *s;1658 Section *s;
1659 unsigned long offset, length, mem;1659 unsigned long offset, length;
1660 uplong mem;
1660 int i;1661 int i;
1661 1662
1662 if (0 == s1->runtime_added) {1663 if (0 == s1->runtime_added) {
@@ -1674,7 +1675,7 @@ int tcc_relocate(TCCState *s1, void *ptr) · 11 unmodified lines
1674 return -1;1675 return -1;
1675 }1676 }
1676 1677
1677 offset = 0, mem = (unsigned long)ptr;1678 offset = 0, mem = (uplong)ptr;
1678 for(i = 1; i < s1->nb_sections; i++) {1679 for(i = 1; i < s1->nb_sections; i++) {
1679 s = s1->sections[i];1680 s = s1->sections[i];
1680 if (0 == (s->sh_flags & SHF_ALLOC))1681 if (0 == (s->sh_flags & SHF_ALLOC))
@@ -1715,7 +1716,7 @@ int tcc_relocate(TCCState *s1, void *ptr) · 34 unmodified lines
1715 continue;1716 continue;
1716 length = s->data_offset;1717 length = s->data_offset;
1717 // printf("%-12s %08x %04x\n", s->name, s->sh_addr, length);1718 // printf("%-12s %08x %04x\n", s->name, s->sh_addr, length);
1718 ptr = (void*)s->sh_addr;1719 ptr = (void*)(uplong)s->sh_addr;
1719 if (NULL == s->data || s->sh_type == SHT_NOBITS)1720 if (NULL == s->data || s->sh_type == SHT_NOBITS)
1720 memset(ptr, 0, length);1721 memset(ptr, 0, length);
1721 else1722 else
@@ -2155,7 +2156,7 @@ int tcc_add_library(TCCState *s, const char *libraryname) · 433 unmodified lines
2155 2156
2156int tcc_add_symbol(TCCState *s, const char *name, void *val)2157int tcc_add_symbol(TCCState *s, const char *name, void *val)
2157{2158{
2158 add_elf_sym(symtab_section, (unsigned long)val, 0, 2159 add_elf_sym(symtab_section, (uplong)val, 0,
2159 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,2160 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
2160 SHN_ABS, name);2161 SHN_ABS, name);
2161 return 0;2162 return 0;
tcc.h+11−1
@@ -47,6 +47,9 @@ · 46 unmodified lines
47#define inline __inline47#define inline __inline
48#define inp next_inp48#define inp next_inp
49#define dlclose FreeLibrary49#define dlclose FreeLibrary
50#ifdef _WIN64
51#define uplong unsigned long long
52#endif
50#endif53#endif
51 54
52#ifndef _WIN3255#ifndef _WIN32
@@ -58,6 +61,10 @@ · 5 unmodified lines
58 61
59#endif /* !CONFIG_TCCBOOT */62#endif /* !CONFIG_TCCBOOT */
60 63
64#ifndef uplong
65#define uplong unsigned long
66#endif
67
61#ifndef PAGESIZE68#ifndef PAGESIZE
62#define PAGESIZE 409669#define PAGESIZE 4096
63#endif70#endif
@@ -204,7 +211,10 @@ typedef struct Sym { · 140 unmodified lines
204 int *d; /* define token stream */211 int *d; /* define token stream */
205 };212 };
206 CType type; /* associated type */213 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 };
208 struct Sym *prev; /* prev symbol in stack */218 struct Sym *prev; /* prev symbol in stack */
209 struct Sym *prev_tok; /* previous symbol for this token */219 struct Sym *prev_tok; /* previous symbol for this token */
210} Sym;220} Sym;
tccelf.c+6−6
@@ -177,7 +177,7 @@ void *tcc_get_symbol(TCCState *s, const char *name) · 176 unmodified lines
177 if (!sym_index)177 if (!sym_index)
178 return NULL;178 return NULL;
179 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];179 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
180 return (void*)(long)sym->st_value;180 return (void*)(uplong)sym->st_value;
181}181}
182 182
183void *tcc_get_symbol_err(TCCState *s, const char *name)183void *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
191 191
192/* add an elf symbol : check if it is already defined and patch192/* add an elf symbol : check if it is already defined and patch
193 it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */193 it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
194static int add_elf_sym(Section *s, unsigned long value, unsigned long size,194static int add_elf_sym(Section *s, uplong value, unsigned long size,
195 int info, int other, int sh_num, const char *name)195 int info, int other, int sh_num, const char *name)
196{196{
197 ElfW(Sym) *esym;197 ElfW(Sym) *esym;
@@ -442,11 +442,11 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 244 unmodified lines
442 name = strtab_section->data + sym->st_name;442 name = strtab_section->data + sym->st_name;
443 if (do_resolve) {443 if (do_resolve) {
444#ifndef _WIN32444#ifndef _WIN32
445 unsigned long addr;445 void *addr;
446 name = symtab_section->link->data + sym->st_name;446 name = symtab_section->link->data + sym->st_name;
447 addr = (unsigned long)resolve_sym(s1, name);447 addr = resolve_sym(s1, name);
448 if (addr) {448 if (addr) {
449 sym->st_value = addr;449 sym->st_value = (uplong)addr;
450 goto found;450 goto found;
451 }451 }
452#endif452#endif
@@ -1884,7 +1884,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 1431 unmodified lines
1884 1884
1885 /* get entry point address */1885 /* get entry point address */
1886 if (file_type == TCC_OUTPUT_EXE)1886 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");
1888 else1888 else
1889 ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */1889 ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
1890 }1890 }
tccgen.c+4−4
@@ -4088,9 +4088,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4087 unmodified lines
4088 }4088 }
4089 /* label already defined */4089 /* label already defined */
4090 if (s->r & LABEL_FORWARD) 4090 if (s->r & LABEL_FORWARD)
4091 s->next = (void *)gjmp((long)s->next);4091 s->jnext = gjmp(s->jnext);
4092 else4092 else
4093 gjmp_addr((long)s->next);4093 gjmp_addr(s->jnext);
4094 next();4094 next();
4095 } else {4095 } else {
4096 expect("label identifier");4096 expect("label identifier");
@@ -4106,12 +4106,12 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 9 unmodified lines
4106 if (s) {4106 if (s) {
4107 if (s->r == LABEL_DEFINED)4107 if (s->r == LABEL_DEFINED)
4108 error("duplicate label '%s'", get_tok_str(s->v, NULL));4108 error("duplicate label '%s'", get_tok_str(s->v, NULL));
4109 gsym((long)s->next);4109 gsym(s->jnext);
4110 s->r = LABEL_DEFINED;4110 s->r = LABEL_DEFINED;
4111 } else {4111 } else {
4112 s = label_push(&global_label_stack, b, LABEL_DEFINED);4112 s = label_push(&global_label_stack, b, LABEL_DEFINED);
4113 }4113 }
4114 s->next = (void *)ind;4114 s->jnext = ind;
4115 /* we accept this, but it is a mistake */4115 /* we accept this, but it is a mistake */
4116 block_after_label:4116 block_after_label:
4117 if (tok == '}') {4117 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
1548 }1548 }
1549 1549
1550 if (start_symbol) {1550 if (start_symbol) {
1551 addr = (ADDR3264)tcc_get_symbol_err(s1, start_symbol);1551 addr = (uplong)tcc_get_symbol_err(s1, start_symbol);
1552 if (s1->output_type == TCC_OUTPUT_MEMORY && addr)1552 if (s1->output_type == TCC_OUTPUT_MEMORY && addr)
1553 /* for -run GUI's, put '_runwinmain' instead of 'main' */1553 /* for -run GUI's, put '_runwinmain' instead of 'main' */
1554 add_elf_sym(symtab_section,1554 add_elf_sym(symtab_section,
tccpp.c+5−1
@@ -129,7 +129,11 @@ char *get_tok_str(int v, CValue *cv) · 128 unmodified lines
129 case TOK_CLLONG:129 case TOK_CLLONG:
130 case TOK_CULLONG:130 case TOK_CULLONG:
131 /* XXX: not quite exact, but only useful for testing */131 /* XXX: not quite exact, but only useful for testing */
132#ifdef _WIN32
133 sprintf(p, "%u", (unsigned)cv->ull);
134#else
132 sprintf(p, "%Lu", cv->ull);135 sprintf(p, "%Lu", cv->ull);
136#endif
133 break;137 break;
134 case TOK_LCHAR:138 case TOK_LCHAR:
135 cstr_ccat(&cstr_buf, 'L');139 cstr_ccat(&cstr_buf, 'L');
@@ -947,7 +951,7 @@ static void label_pop(Sym **ptop, Sym *slast) · 811 unmodified lines
947 if (s->c) {951 if (s->c) {
948 /* define corresponding symbol. A size of952 /* define corresponding symbol. A size of
949 1 is put. */953 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);
951 }955 }
952 }956 }
953 /* remove label */957 /* 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