diff options
| author | grischka <grischka> | 2017-02-18 09:51:23 +0100 |
|---|---|---|
| committer | grischka <grischka> | 2017-02-18 09:51:23 +0100 |
| commit | 096125d963400951e0f160ced86416ef8c9c98b0 (patch) | |
| tree | c0fb4737ba1cf421032e28925f9aef6c140d97aa /tccpe.c | |
| parent | 39b2afeb7c5c7de9a6c6457b5a4ec102d4e364b1 (diff) | |
| download | tinycc-096125d963400951e0f160ced86416ef8c9c98b0.tar.gz tinycc-096125d963400951e0f160ced86416ef8c9c98b0.tar.bz2 | |
win32: adjust new unicode support
- lib/Makefile: add (win)crt1_w.o
- crt1.c/_runtmain: return to tcc & only use for UNICODE
(because it might be not 100% reliable with for example
wildcards (tcc *.c -run ...)
- tccrun.c/tccpe.c: load -run startup_code only if called
from tcc_run(). Otherwise main may not be defined. See
libtcc_test.c
- tests2/Makefile: pass extra options in FLAGS to allow
overriding TCC
Also:
- tccpe.c: support weak attribute. (I first tried to solve
the problem above by using it but then didn't)
Diffstat (limited to 'tccpe.c')
| -rw-r--r-- | tccpe.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -358,6 +358,7 @@ struct pe_info { int type; DWORD sizeofheaders; ADDR3264 imagebase; + const char *start_symbol; DWORD start_addr; DWORD imp_offs; DWORD imp_size; @@ -638,7 +639,6 @@ static int pe_write(struct pe_info *pe) switch (si->cls) { case sec_text: pe_header.opthdr.BaseOfCode = addr; - pe_header.opthdr.AddressOfEntryPoint = addr + pe->start_addr; break; case sec_data: @@ -700,6 +700,7 @@ static int pe_write(struct pe_info *pe) //pe_header.filehdr.TimeDateStamp = time(NULL); pe_header.filehdr.NumberOfSections = pe->sec_count; + pe_header.opthdr.AddressOfEntryPoint = pe->start_addr; pe_header.opthdr.SizeOfHeaders = pe->sizeofheaders; pe_header.opthdr.ImageBase = pe->imagebase; pe_header.opthdr.Subsystem = pe->subsystem; @@ -1309,6 +1310,9 @@ static int pe_check_symbols(struct pe_info *pe) } not_found: + if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK) + /* STB_WEAK undefined symbols are accepted */ + continue; tcc_error_noabort("undefined symbol '%s'", name); ret = -1; @@ -1793,8 +1797,9 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) ++start_symbol; /* grab the startup code from libtcc1 */ - /* only (PE_Dll == pe_type) doesn't need it, - (TCC_OUTPUT_MEMORY == s1->output_type && PE_Dll == pe_type) is illegal */ +#ifdef TCC_IS_NATIVE + if (TCC_OUTPUT_MEMORY != s1->output_type || s1->runtime_main) +#endif set_elf_sym(symtab_section, 0, 0, ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, @@ -1817,16 +1822,10 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) } } - if (TCC_OUTPUT_MEMORY == s1->output_type) { + if (TCC_OUTPUT_MEMORY == s1->output_type) pe_type = PE_RUN; -#ifdef TCC_IS_NATIVE - s1->runtime_main = start_symbol; -#endif - } else { - pe->start_addr = (DWORD)(uintptr_t)tcc_get_symbol_err(s1, start_symbol); - } - pe->type = pe_type; + pe->start_symbol = start_symbol; } static void pe_set_options(TCCState * s1, struct pe_info *pe) @@ -1905,6 +1904,9 @@ ST_FUNC int pe_output_file(TCCState *s1, const char *filename) pe_relocate_rva(&pe, s); } } + pe.start_addr = (DWORD) + ((uintptr_t)tcc_get_symbol_err(s1, pe.start_symbol) + - pe.imagebase); if (s1->nb_errors) ret = -1; else @@ -1914,6 +1916,7 @@ ST_FUNC int pe_output_file(TCCState *s1, const char *filename) #ifdef TCC_IS_NATIVE pe.thunk = data_section; pe_build_imports(&pe); + s1->runtime_main = pe.start_symbol; #endif } |
