ST_FN void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) { const char *start_symbol; unsigned long addr = 0; int pe_type = 0; if (find_elf_sym(symtab_section, "_WinMain@16")) pe_type = PE_GUI; else if (TCC_OUTPUT_DLL == s1->output_type) { pe_type = PE_DLL; /* need this for 'tccelf.c:relocate_section()' */ s1->output_type = TCC_OUTPUT_EXE; } start_symbol = TCC_OUTPUT_MEMORY == s1->output_type ? PE_GUI == pe_type ? "_runwinmain" : NULL : PE_DLL == pe_type ? "__dllstart@12" : PE_GUI == pe_type ? "_winstart" : "_start" ; /* grab the startup code from libtcc1 */ if (start_symbol) add_elf_sym(symtab_section, 0, 0, ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, SHN_UNDEF, start_symbol); if (0 == s1->nostdlib) { tcc_add_library(s1, "tcc1"); #ifdef __CYGWIN__ tcc_add_library(s1, "cygwin1"); #else tcc_add_library(s1, "msvcrt"); #endif tcc_add_library(s1, "kernel32"); if (PE_DLL == pe_type || PE_GUI == pe_type) { tcc_add_library(s1, "user32"); tcc_add_library(s1, "gdi32"); } } if (start_symbol) { addr = (unsigned long)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, addr, 0, ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, text_section->sh_num, "main"); } if (pe) { pe->type = pe_type; pe->start_addr = addr; } }
static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) { const char *start_symbol; unsigned long addr = 0; int pe_type = 0; int start_sym_index; if (find_elf_sym(symtab_section, "_WinMain@16")) { pe_type = PE_GUI; } else if (s1->output_type == TCC_OUTPUT_DLL) { pe_type = PE_DLL; // Need this for 'tccelf.c:relocate_section()' s1->output_type = TCC_OUTPUT_EXE; } else { pe_type = PE_EXE; } start_symbol = s1->start_symbol; if (!start_symbol) { start_symbol = pe_type == PE_DLL ? "_DllMain@12" : "mainCRTStartup"; } start_sym_index = add_elf_sym(symtab_section, 0, 0, ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, SHN_UNDEF, start_symbol); tcc_get_symbol_err(s1, start_symbol); if (s1->nostdlib == 0) { tcc_add_library(s1, "c"); tcc_add_library(s1, "os"); } if (pe) { pe->type = pe_type; pe->start_sym_index = start_sym_index; pe->stub = s1->stub; pe->def = s1->def_file; pe->filealign = s1->filealign; } }