mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-28 08:10:25 +08:00
Use _WIN32 for a windows hosted tcc and define it for the PE target.
This commit is contained in:
parent
b0d40c12da
commit
34140dd627
@ -1,9 +1,9 @@
|
||||
/* ---------------------------------------------- */
|
||||
/* alloca86b.S */
|
||||
|
||||
.globl __bound___alloca
|
||||
.globl __bound__alloca
|
||||
|
||||
__bound___alloca:
|
||||
__bound__alloca:
|
||||
pop %edx
|
||||
pop %eax
|
||||
mov %eax, %ecx
|
||||
|
2
elf.h
2
elf.h
@ -21,7 +21,7 @@
|
||||
#ifndef _ELF_H
|
||||
#define _ELF_H 1
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#ifndef __int8_t_defined
|
||||
|
64
tcc.c
64
tcc.c
@ -38,11 +38,11 @@
|
||||
#include <fcntl.h>
|
||||
#include <setjmp.h>
|
||||
#include <time.h>
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <sys/timeb.h>
|
||||
// #include <windows.h>
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
#include <sys/time.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <sys/mman.h>
|
||||
@ -86,12 +86,12 @@
|
||||
#define TCC_TARGET_I386
|
||||
#endif
|
||||
|
||||
#if !defined(WIN32) && !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
|
||||
#if !defined(_WIN32) && !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
|
||||
!defined(TCC_TARGET_C67)
|
||||
#define CONFIG_TCC_BCHECK /* enable bound checking code */
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(TCC_TARGET_PE)
|
||||
#if defined(_WIN32) && !defined(TCC_TARGET_PE)
|
||||
#define CONFIG_TCC_STATIC
|
||||
#endif
|
||||
|
||||
@ -722,7 +722,7 @@ static const char tcc_keywords[] =
|
||||
|
||||
#define TOK_UIDENT TOK_DEFINE
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
int __stdcall GetModuleFileNameA(void *, char *, int);
|
||||
void *__stdcall GetProcAddress(void *, const char *);
|
||||
void *__stdcall GetModuleHandleA(const char *);
|
||||
@ -967,7 +967,7 @@ void *resolve_sym(TCCState *s1, const char *symbol, int type)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#elif !defined(WIN32)
|
||||
#elif !defined(_WIN32)
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
@ -1035,7 +1035,7 @@ static int strstart(const char *str, const char *val, const char **ptr)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
char *normalize_slashes(char *path)
|
||||
{
|
||||
char *p;
|
||||
@ -1061,6 +1061,20 @@ char *w32_tcc_lib_path(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_pages_executable(void *ptr, unsigned long length)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
unsigned long old_protect;
|
||||
VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
#else
|
||||
unsigned long start, end;
|
||||
start = (unsigned long)ptr & ~(PAGESIZE - 1);
|
||||
end = (unsigned long)ptr + length;
|
||||
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
|
||||
mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* memory management */
|
||||
#ifdef MEM_DEBUG
|
||||
int mem_cur_size;
|
||||
@ -1887,7 +1901,9 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename)
|
||||
bf->buf_end = bf->buffer;
|
||||
bf->buffer[0] = CH_EOB; /* put eob symbol */
|
||||
pstrcpy(bf->filename, sizeof(bf->filename), filename);
|
||||
#ifdef _WIN32
|
||||
normalize_slashes(bf->filename);
|
||||
#endif
|
||||
bf->line_num = 1;
|
||||
bf->ifndef_macro = 0;
|
||||
bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
|
||||
@ -9388,6 +9404,9 @@ static int tcc_compile(TCCState *s1)
|
||||
ELF32_ST_INFO(STB_LOCAL, STT_SECTION), 0,
|
||||
text_section->sh_num, NULL);
|
||||
getcwd(buf, sizeof(buf));
|
||||
#ifdef _WIN32
|
||||
normalize_slashes(buf);
|
||||
#endif
|
||||
pstrcat(buf, sizeof(buf), "/");
|
||||
put_stabs_r(buf, N_SO, 0, 0,
|
||||
text_section->data_offset, text_section, section_sym);
|
||||
@ -9724,7 +9743,7 @@ static void rt_printline(unsigned long wanted_pc)
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#if !defined(WIN32) && !defined(CONFIG_TCCBOOT)
|
||||
#if !defined(_WIN32) && !defined(CONFIG_TCCBOOT)
|
||||
|
||||
#ifdef __i386__
|
||||
|
||||
@ -9888,24 +9907,8 @@ int tcc_relocate(TCCState *s1)
|
||||
for(i = 1; i < s1->nb_sections; i++) {
|
||||
s = s1->sections[i];
|
||||
if ((s->sh_flags & (SHF_ALLOC | SHF_EXECINSTR)) ==
|
||||
(SHF_ALLOC | SHF_EXECINSTR)) {
|
||||
#ifdef WIN32
|
||||
{
|
||||
unsigned long old_protect;
|
||||
VirtualProtect(s->data, s->data_offset,
|
||||
PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
}
|
||||
#else
|
||||
{
|
||||
unsigned long start, end;
|
||||
start = (unsigned long)(s->data) & ~(PAGESIZE - 1);
|
||||
end = (unsigned long)(s->data + s->data_offset);
|
||||
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
|
||||
mprotect((void *)start, end - start,
|
||||
PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
(SHF_ALLOC | SHF_EXECINSTR))
|
||||
set_pages_executable(s->data, s->data_offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -9921,7 +9924,7 @@ int tcc_run(TCCState *s1, int argc, char **argv)
|
||||
prog_main = tcc_get_symbol_err(s1, "main");
|
||||
|
||||
if (do_debug) {
|
||||
#if defined(WIN32) || defined(CONFIG_TCCBOOT)
|
||||
#if defined(_WIN32) || defined(CONFIG_TCCBOOT)
|
||||
error("debug mode currently not available for Windows");
|
||||
#else
|
||||
struct sigaction sigact;
|
||||
@ -10022,6 +10025,7 @@ TCCState *tcc_new(void)
|
||||
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int");
|
||||
#ifdef TCC_TARGET_PE
|
||||
tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short");
|
||||
tcc_define_symbol(s, "_WIN32", NULL);
|
||||
#else
|
||||
tcc_define_symbol(s, "__WCHAR_TYPE__", "int");
|
||||
#endif
|
||||
@ -10461,7 +10465,7 @@ static char *tcc_basename(const char *name)
|
||||
char *p = strchr(name, 0);
|
||||
while (p > name
|
||||
&& p[-1] != '/'
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
&& p[-1] != '\\'
|
||||
#endif
|
||||
)
|
||||
@ -10473,7 +10477,7 @@ static char *tcc_basename(const char *name)
|
||||
|
||||
static int64_t getclock_us(void)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
struct _timeb tb;
|
||||
_ftime(&tb);
|
||||
return (tb.time * 1000LL + tb.millitm) * 1000LL;
|
||||
@ -10849,7 +10853,7 @@ int main(int argc, char **argv)
|
||||
char objfilename[1024];
|
||||
int64_t start_time = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
tcc_lib_path = w32_tcc_lib_path();
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user