int pe_output_file(TCCState *s1, const char *filename) { int ret; struct pe_info pe; int i; memset(&pe, 0, sizeof pe); pe.filename = filename; pe.s1 = s1; // Generate relocation information by default for Sanos. if (s1->imagebase == 0xFFFFFFFF) { pe.reloc = new_section(s1, ".reloc", SHT_PROGBITS, 0); pe.imagebase = pe.type == PE_DLL ? 0x10000000 : 0x00400000; } else { pe.imagebase = s1->imagebase; } pe_add_runtime_ex(s1, &pe); relocate_common_syms(); // Assign bss adresses tcc_add_linker_symbols(s1); if (!s1->nofll) pe_eliminate_unused_sections(&pe); ret = pe_check_symbols(&pe); if (ret != 0) return ret; pe_assign_addresses(&pe); relocate_syms(s1, 0); for (i = 1; i < s1->nb_sections; ++i) { Section *s = s1->sections[i]; if (s->reloc) { relocate_section(s1, s); pe_relocate_rva(&pe, s); } } if (s1->nb_errors) { ret = 1; } else { ret = pe_write(&pe); } if (s1->mapfile) pe_print_sections(s1, s1->mapfile); tcc_free(pe.sec_info); return ret; }
PUB_FN int pe_output_file(TCCState * s1, const char *filename) { int ret; struct pe_info pe; int i; memset(&pe, 0, sizeof pe); pe.filename = filename; pe.s1 = s1; pe_add_runtime_ex(s1, &pe); relocate_common_syms(); /* assign bss adresses */ tcc_add_linker_symbols(s1); ret = pe_check_symbols(&pe); if (0 == ret) { if (PE_DLL == pe.type) { pe.reloc = new_section(pe.s1, ".reloc", SHT_PROGBITS, 0); pe.imagebase = 0x10000000; } else { pe.imagebase = 0x00400000; } pe_assign_addresses(&pe); relocate_syms(s1, 0); for (i = 1; i < s1->nb_sections; ++i) { Section *s = s1->sections[i]; if (s->reloc) { relocate_section(s1, s); pe_relocate_rva(&pe, s); } } if (s1->nb_errors) ret = 1; else ret = pe_write(&pe); tcc_free(pe.sec_info); } #ifdef PE_PRINT_SECTIONS pe_print_sections(s1, "tcc.log"); #endif return ret; }