Unified · Split
| @@ -1081,8 +1081,11 @@ int tcc_output_file(TCCState *s1, const char *filename) · 1080 unmodified lines | |||
| 1081 | file_type = s1->output_type; | 1081 | file_type = s1->output_type; |
| 1082 | s1->nb_errors = 0; | 1082 | s1->nb_errors = 0; |
| 1083 | 1083 | ||
| 1084 | if (file_type != TCC_OUTPUT_OBJ) | 1084 | if (file_type != TCC_OUTPUT_OBJ) { |
| 1085 | relocate_common_syms(); | ||
| 1086 | |||
| 1085 | tcc_add_runtime(s1); | 1087 | tcc_add_runtime(s1); |
| 1088 | } | ||
| 1086 | 1089 | ||
| 1087 | phdr = NULL; | 1090 | phdr = NULL; |
| 1088 | section_order = NULL; | 1091 | section_order = NULL; |
| @@ -1093,8 +1096,6 @@ int tcc_output_file(TCCState *s1, const char *filename) · 4 unmodified lines | |||
| 1093 | 1096 | ||
| 1094 | if (file_type != TCC_OUTPUT_OBJ) { | 1097 | if (file_type != TCC_OUTPUT_OBJ) { |
| 1095 | 1098 | ||
| 1096 | relocate_common_syms(); | ||
| 1097 | |||
| 1098 | if (!s1->static_link) { | 1099 | if (!s1->static_link) { |
| 1099 | const char *name; | 1100 | const char *name; |
| 1100 | int sym_index, index; | 1101 | int sym_index, index; |
| @@ -1312,18 +1313,29 @@ int tcc_output_file(TCCState *s1, const char *filename) · 211 unmodified lines | |||
| 1312 | file_offset = sizeof(Elf32_Ehdr) + phnum * sizeof(Elf32_Phdr); | 1313 | file_offset = sizeof(Elf32_Ehdr) + phnum * sizeof(Elf32_Phdr); |
| 1313 | if (phnum > 0) { | 1314 | if (phnum > 0) { |
| 1314 | /* compute section to program header mapping */ | 1315 | /* compute section to program header mapping */ |
| 1315 | if (file_type == TCC_OUTPUT_DLL) | 1316 | if (s1->has_text_addr) { |
| 1316 | addr = 0; | 1317 | int a_offset, p_offset; |
| 1317 | else | 1318 | addr = s1->text_addr; |
| 1318 | addr = ELF_START_ADDR; | 1319 | /* we ensure that (addr % ELF_PAGE_SIZE) == file_offset % |
| 1319 | 1320 | ELF_PAGE_SIZE */ | |
| 1321 | a_offset = addr & (ELF_PAGE_SIZE - 1); | ||
| 1322 | p_offset = file_offset & (ELF_PAGE_SIZE - 1); | ||
| 1323 | if (a_offset < p_offset) | ||
| 1324 | a_offset += ELF_PAGE_SIZE; | ||
| 1325 | file_offset += (a_offset - p_offset); | ||
| 1326 | } else { | ||
| 1327 | if (file_type == TCC_OUTPUT_DLL) | ||
| 1328 | addr = 0; | ||
| 1329 | else | ||
| 1330 | addr = ELF_START_ADDR; | ||
| 1331 | /* compute address after headers */ | ||
| 1332 | addr += (file_offset & (ELF_PAGE_SIZE - 1)); | ||
| 1333 | } | ||
| 1334 | |||
| 1320 | /* dynamic relocation table information, for .dynamic section */ | 1335 | /* dynamic relocation table information, for .dynamic section */ |
| 1321 | rel_size = 0; | 1336 | rel_size = 0; |
| 1322 | rel_addr = 0; | 1337 | rel_addr = 0; |
| 1323 | 1338 | ||
| 1324 | /* compute address after headers */ | ||
| 1325 | addr += (file_offset & (ELF_PAGE_SIZE - 1)); | ||
| 1326 | |||
| 1327 | /* leave one program header for the program interpreter */ | 1339 | /* leave one program header for the program interpreter */ |
| 1328 | ph = &phdr[0]; | 1340 | ph = &phdr[0]; |
| 1329 | if (interp) | 1341 | if (interp) |
| @@ -1374,11 +1386,11 @@ int tcc_output_file(TCCState *s1, const char *filename) · 44 unmodified lines | |||
| 1374 | section_order[sh_order_index++] = i; | 1386 | section_order[sh_order_index++] = i; |
| 1375 | 1387 | ||
| 1376 | /* section matches: we align it and add its size */ | 1388 | /* section matches: we align it and add its size */ |
| 1377 | tmp = file_offset; | 1389 | tmp = addr; |
| 1378 | file_offset = (file_offset + s->sh_addralign - 1) & | 1390 | addr = (addr + s->sh_addralign - 1) & |
| 1379 | ~(s->sh_addralign - 1); | 1391 | ~(s->sh_addralign - 1); |
| 1392 | file_offset += addr - tmp; | ||
| 1380 | s->sh_offset = file_offset; | 1393 | s->sh_offset = file_offset; |
| 1381 | addr += file_offset - tmp; | ||
| 1382 | s->sh_addr = addr; | 1394 | s->sh_addr = addr; |
| 1383 | 1395 | ||
| 1384 | /* update program header infos */ | 1396 | /* update program header infos */ |