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