mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-27 06:10:06 +08:00
win64: fix pointer <-> unsigned long typecast issues
This commit is contained in:
parent
459875796b
commit
035918ef2f
13
libtcc.c
13
libtcc.c
@ -191,7 +191,7 @@ static int put_elf_str(Section *s, const char *sym);
|
||||
static int put_elf_sym(Section *s,
|
||||
unsigned long value, unsigned long size,
|
||||
int info, int other, int shndx, const char *name);
|
||||
static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
|
||||
static int add_elf_sym(Section *s, uplong value, unsigned long size,
|
||||
int info, int other, int sh_num, const char *name);
|
||||
static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
|
||||
int type, int symbol);
|
||||
@ -1183,7 +1183,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename)
|
||||
fd = open(filename, O_RDONLY | O_BINARY);
|
||||
if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
|
||||
printf("%s %*s%s\n", fd < 0 ? "nf":"->",
|
||||
(s1->include_stack_ptr - s1->include_stack), "", filename);
|
||||
(int)(s1->include_stack_ptr - s1->include_stack), "", filename);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
bf = tcc_malloc(sizeof(BufferedFile));
|
||||
@ -1656,7 +1656,8 @@ static void sig_error(int signum, siginfo_t *siginf, void *puc)
|
||||
int tcc_relocate(TCCState *s1, void *ptr)
|
||||
{
|
||||
Section *s;
|
||||
unsigned long offset, length, mem;
|
||||
unsigned long offset, length;
|
||||
uplong mem;
|
||||
int i;
|
||||
|
||||
if (0 == s1->runtime_added) {
|
||||
@ -1674,7 +1675,7 @@ int tcc_relocate(TCCState *s1, void *ptr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
offset = 0, mem = (unsigned long)ptr;
|
||||
offset = 0, mem = (uplong)ptr;
|
||||
for(i = 1; i < s1->nb_sections; i++) {
|
||||
s = s1->sections[i];
|
||||
if (0 == (s->sh_flags & SHF_ALLOC))
|
||||
@ -1715,7 +1716,7 @@ int tcc_relocate(TCCState *s1, void *ptr)
|
||||
continue;
|
||||
length = s->data_offset;
|
||||
// printf("%-12s %08x %04x\n", s->name, s->sh_addr, length);
|
||||
ptr = (void*)s->sh_addr;
|
||||
ptr = (void*)(uplong)s->sh_addr;
|
||||
if (NULL == s->data || s->sh_type == SHT_NOBITS)
|
||||
memset(ptr, 0, length);
|
||||
else
|
||||
@ -2155,7 +2156,7 @@ int tcc_add_library(TCCState *s, const char *libraryname)
|
||||
|
||||
int tcc_add_symbol(TCCState *s, const char *name, void *val)
|
||||
{
|
||||
add_elf_sym(symtab_section, (unsigned long)val, 0,
|
||||
add_elf_sym(symtab_section, (uplong)val, 0,
|
||||
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
|
||||
SHN_ABS, name);
|
||||
return 0;
|
||||
|
12
tcc.h
12
tcc.h
@ -47,6 +47,9 @@
|
||||
#define inline __inline
|
||||
#define inp next_inp
|
||||
#define dlclose FreeLibrary
|
||||
#ifdef _WIN64
|
||||
#define uplong unsigned long long
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
@ -58,6 +61,10 @@
|
||||
|
||||
#endif /* !CONFIG_TCCBOOT */
|
||||
|
||||
#ifndef uplong
|
||||
#define uplong unsigned long
|
||||
#endif
|
||||
|
||||
#ifndef PAGESIZE
|
||||
#define PAGESIZE 4096
|
||||
#endif
|
||||
@ -204,7 +211,10 @@ typedef struct Sym {
|
||||
int *d; /* define token stream */
|
||||
};
|
||||
CType type; /* associated type */
|
||||
struct Sym *next; /* next related symbol */
|
||||
union {
|
||||
struct Sym *next; /* next related symbol */
|
||||
long jnext; /* next jump label */
|
||||
};
|
||||
struct Sym *prev; /* prev symbol in stack */
|
||||
struct Sym *prev_tok; /* previous symbol for this token */
|
||||
} Sym;
|
||||
|
12
tccelf.c
12
tccelf.c
@ -177,7 +177,7 @@ void *tcc_get_symbol(TCCState *s, const char *name)
|
||||
if (!sym_index)
|
||||
return NULL;
|
||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
||||
return (void*)(long)sym->st_value;
|
||||
return (void*)(uplong)sym->st_value;
|
||||
}
|
||||
|
||||
void *tcc_get_symbol_err(TCCState *s, const char *name)
|
||||
@ -191,7 +191,7 @@ void *tcc_get_symbol_err(TCCState *s, const char *name)
|
||||
|
||||
/* add an elf symbol : check if it is already defined and patch
|
||||
it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
|
||||
static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
|
||||
static int add_elf_sym(Section *s, uplong value, unsigned long size,
|
||||
int info, int other, int sh_num, const char *name)
|
||||
{
|
||||
ElfW(Sym) *esym;
|
||||
@ -442,11 +442,11 @@ static void relocate_syms(TCCState *s1, int do_resolve)
|
||||
name = strtab_section->data + sym->st_name;
|
||||
if (do_resolve) {
|
||||
#ifndef _WIN32
|
||||
unsigned long addr;
|
||||
void *addr;
|
||||
name = symtab_section->link->data + sym->st_name;
|
||||
addr = (unsigned long)resolve_sym(s1, name);
|
||||
addr = resolve_sym(s1, name);
|
||||
if (addr) {
|
||||
sym->st_value = addr;
|
||||
sym->st_value = (uplong)addr;
|
||||
goto found;
|
||||
}
|
||||
#endif
|
||||
@ -1884,7 +1884,7 @@ int elf_output_file(TCCState *s1, const char *filename)
|
||||
|
||||
/* get entry point address */
|
||||
if (file_type == TCC_OUTPUT_EXE)
|
||||
ehdr.e_entry = (unsigned long)tcc_get_symbol_err(s1, "_start");
|
||||
ehdr.e_entry = (uplong)tcc_get_symbol_err(s1, "_start");
|
||||
else
|
||||
ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
|
||||
}
|
||||
|
8
tccgen.c
8
tccgen.c
@ -4088,9 +4088,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
|
||||
}
|
||||
/* label already defined */
|
||||
if (s->r & LABEL_FORWARD)
|
||||
s->next = (void *)gjmp((long)s->next);
|
||||
s->jnext = gjmp(s->jnext);
|
||||
else
|
||||
gjmp_addr((long)s->next);
|
||||
gjmp_addr(s->jnext);
|
||||
next();
|
||||
} else {
|
||||
expect("label identifier");
|
||||
@ -4106,12 +4106,12 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
|
||||
if (s) {
|
||||
if (s->r == LABEL_DEFINED)
|
||||
error("duplicate label '%s'", get_tok_str(s->v, NULL));
|
||||
gsym((long)s->next);
|
||||
gsym(s->jnext);
|
||||
s->r = LABEL_DEFINED;
|
||||
} else {
|
||||
s = label_push(&global_label_stack, b, LABEL_DEFINED);
|
||||
}
|
||||
s->next = (void *)ind;
|
||||
s->jnext = ind;
|
||||
/* we accept this, but it is a mistake */
|
||||
block_after_label:
|
||||
if (tok == '}') {
|
||||
|
2
tccpe.c
2
tccpe.c
@ -1548,7 +1548,7 @@ ST_FN void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe)
|
||||
}
|
||||
|
||||
if (start_symbol) {
|
||||
addr = (ADDR3264)tcc_get_symbol_err(s1, start_symbol);
|
||||
addr = (uplong)tcc_get_symbol_err(s1, start_symbol);
|
||||
if (s1->output_type == TCC_OUTPUT_MEMORY && addr)
|
||||
/* for -run GUI's, put '_runwinmain' instead of 'main' */
|
||||
add_elf_sym(symtab_section,
|
||||
|
6
tccpp.c
6
tccpp.c
@ -129,7 +129,11 @@ char *get_tok_str(int v, CValue *cv)
|
||||
case TOK_CLLONG:
|
||||
case TOK_CULLONG:
|
||||
/* XXX: not quite exact, but only useful for testing */
|
||||
#ifdef _WIN32
|
||||
sprintf(p, "%u", (unsigned)cv->ull);
|
||||
#else
|
||||
sprintf(p, "%Lu", cv->ull);
|
||||
#endif
|
||||
break;
|
||||
case TOK_LCHAR:
|
||||
cstr_ccat(&cstr_buf, 'L');
|
||||
@ -947,7 +951,7 @@ static void label_pop(Sym **ptop, Sym *slast)
|
||||
if (s->c) {
|
||||
/* define corresponding symbol. A size of
|
||||
1 is put. */
|
||||
put_extern_sym(s, cur_text_section, (long)s->next, 1);
|
||||
put_extern_sym(s, cur_text_section, s->jnext, 1);
|
||||
}
|
||||
}
|
||||
/* remove label */
|
||||
|
Loading…
Reference in New Issue
Block a user