from 43ae3503904d42a171305b2708f9fd1d37a352ea and a3578379fbd36b663032869a15a0c28c32be4cf6 Sorry, but this feature appears to be rather a personal experiment than generically interesting for other people. Also those "other people" always have some interest in TCC staying simple. One can still avoid the startup code from libtcc1.a simply by providing __start explicitly. While at it: Tidy tccpe.c:pe_add_runtime(), somewhat.
Unified · Split
| @@ -1318,12 +1318,11 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 1317 unmodified lines | |||
| 1318 | } | 1318 | } |
| 1319 | 1319 | ||
| 1320 | #ifndef TCC_TARGET_PE | 1320 | #ifndef TCC_TARGET_PE |
| 1321 | static int tcc_add_support(TCCState *s1, const char *filename) | 1321 | static void tcc_add_support(TCCState *s1, const char *filename) |
| 1322 | { | 1322 | { |
| 1323 | char buf[1024]; | 1323 | char buf[1024]; |
| 1324 | if (!filename || strlen(filename)==0) return 0; | ||
| 1325 | snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename); | 1324 | snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename); |
| 1326 | return tcc_add_file(s1, buf); | 1325 | tcc_add_file(s1, buf); |
| 1327 | } | 1326 | } |
| 1328 | #endif | 1327 | #endif |
| 1329 | 1328 | ||
| @@ -1855,48 +1855,41 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack) · 1854 unmodified lines | |||
| 1855 | 1855 | ||
| 1856 | static void tcc_add_support(TCCState *s1, const char *filename) | 1856 | static void tcc_add_support(TCCState *s1, const char *filename) |
| 1857 | { | 1857 | { |
| 1858 | if (!filename || strlen(filename)==0) return; | ||
| 1859 | if (tcc_add_dll(s1, filename, 0) < 0) | 1858 | if (tcc_add_dll(s1, filename, 0) < 0) |
| 1860 | tcc_error_noabort("%s not found", filename); | 1859 | tcc_error_noabort("%s not found", filename); |
| 1861 | } | 1860 | } |
| 1862 | 1861 | ||
| 1863 | static void pe_add_runtime(TCCState *s1, struct pe_info *pe) | 1862 | static void pe_add_runtime(TCCState *s1, struct pe_info *pe) |
| 1864 | { | 1863 | { |
| 1865 | const char *start_symbol = NULL; | 1864 | const char *start_symbol; |
| 1866 | int pe_type = 0; | 1865 | int pe_type; |
| 1867 | int unicode_entry = 0; | ||
| 1868 | 1866 | ||
| 1869 | if (find_elf_sym(symtab_section, PE_STDSYM("WinMain","@16"))) | ||
| 1870 | pe_type = PE_GUI; | ||
| 1871 | else | ||
| 1872 | if (find_elf_sym(symtab_section, PE_STDSYM("wWinMain","@16"))) { | ||
| 1873 | pe_type = PE_GUI; | ||
| 1874 | unicode_entry = PE_GUI; | ||
| 1875 | } | ||
| 1876 | else | ||
| 1877 | if (TCC_OUTPUT_DLL == s1->output_type) { | 1867 | if (TCC_OUTPUT_DLL == s1->output_type) { |
| 1878 | pe_type = PE_DLL; | 1868 | pe_type = PE_DLL; |
| 1879 | } | 1869 | start_symbol = PE_STDSYM("__dllstart","@12"); |
| 1880 | else { | 1870 | } else { |
| 1881 | pe_type = PE_EXE; | 1871 | const char *run_symbol; |
| 1882 | if (find_elf_sym(symtab_section, "wmain")) | 1872 | if (find_elf_sym(symtab_section, PE_STDSYM("WinMain","@16"))) { |
| 1883 | unicode_entry = PE_EXE; | 1873 | start_symbol = "__winstart"; |
| 1884 | else | 1874 | run_symbol = "__runwinmain"; |
| 1885 | /* use main() directly when TCC1 is "" */ | 1875 | pe_type = PE_GUI; |
| 1886 | if (strlen(TCC_LIBTCC1)==0){ | 1876 | } else if (find_elf_sym(symtab_section, PE_STDSYM("wWinMain","@16"))) { |
| 1887 | start_symbol = "_main"; | 1877 | start_symbol = "__wwinstart"; |
| 1888 | } | 1878 | run_symbol = "__runwwinmain"; |
| 1889 | } | 1879 | pe_type = PE_GUI; |
| 1880 | } else if (find_elf_sym(symtab_section, "wmain")) { | ||
| 1881 | start_symbol = "__wstart"; | ||
| 1882 | run_symbol = "__runwmain"; | ||
| 1883 | pe_type = PE_EXE; | ||
| 1884 | } else { | ||
| 1885 | start_symbol = "__start"; | ||
| 1886 | run_symbol = "__runmain"; | ||
| 1887 | pe_type = PE_EXE; | ||
| 1890 | 1888 | ||
| 1891 | if(!start_symbol) | 1889 | } |
| 1892 | start_symbol = | 1890 | if (TCC_OUTPUT_MEMORY == s1->output_type) |
| 1893 | TCC_OUTPUT_MEMORY == s1->output_type | 1891 | start_symbol = run_symbol; |
| 1894 | ? PE_GUI == pe_type ? (unicode_entry ? "__runwwinmain" : "__runwinmain") | 1892 | } |
| 1895 | : (unicode_entry ? "__runwmain" : "__runmain") | ||
| 1896 | : PE_DLL == pe_type ? PE_STDSYM("__dllstart","@12") | ||
| 1897 | : PE_GUI == pe_type ? (unicode_entry ? "__wwinstart": "__winstart") | ||
| 1898 | : (unicode_entry ? "__wstart" : "__start") | ||
| 1899 | ; | ||
| 1900 | 1893 | ||
| 1901 | pe->start_symbol = start_symbol + 1; | 1894 | pe->start_symbol = start_symbol + 1; |
| 1902 | if (!s1->leading_underscore || strchr(start_symbol, '@')) | 1895 | if (!s1->leading_underscore || strchr(start_symbol, '@')) |
| @@ -2053,5 +2046,4 @@ ST_FUNC int pe_output_file(TCCState *s1, const char *filename) · 150 unmodified lines | |||
| 2053 | } | 2046 | } |
| 2054 | 2047 | ||
| 2055 | /* ------------------------------------------------------------- */ | 2048 | /* ------------------------------------------------------------- */ |
| 2056 | /* vim: set expandtab ts=4 sw=4 sts=4 tw=80 :*/ | ||
| 2057 | 2049 | ||