Unified · Split
| @@ -1367,12 +1367,25 @@ int tcc_output_file(TCCState *s1, const char *filename) · 1366 unmodified lines | ||
| 1367 | 1367 | for(i = 1; i < s1->nb_sections; i++) { |
| 1368 | 1368 | s = s1->sections[i]; |
| 1369 | 1369 | s->sh_name = put_elf_str(strsec, s->name); |
| 1370 | +#if 0 //gr | |
| 1371 | + printf("section: f=%08x t=%08x i=%08x %s %s\n", | |
| 1372 | + s->sh_flags, | |
| 1373 | + s->sh_type, | |
| 1374 | + s->sh_info, | |
| 1375 | + s->name, | |
| 1376 | + s->reloc ? s->reloc->name : "n" | |
| 1377 | + ); | |
| 1378 | +#endif | |
| 1370 | 1379 | /* when generating a DLL, we include relocations but we may |
| 1371 | 1380 | patch them */ |
| 1372 | 1381 | if (file_type == TCC_OUTPUT_DLL && |
| 1373 | 1382 | s->sh_type == SHT_REL && |
| 1374 | 1383 | !(s->sh_flags & SHF_ALLOC)) { |
| 1375 | − prepare_dynamic_rel(s1, s); | |
| 1384 | + /* //gr: avoid bogus relocs for empty (debug) sections */ | |
| 1385 | + if (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC) | |
| 1386 | + prepare_dynamic_rel(s1, s); | |
| 1387 | + else if (do_debug) | |
| 1388 | + s->sh_size = s->data_offset; | |
| 1376 | 1389 | } else if (do_debug || |
| 1377 | 1390 | file_type == TCC_OUTPUT_OBJ || |
| 1378 | 1391 | (s->sh_flags & SHF_ALLOC) || |
| @@ -1595,6 +1608,8 @@ int tcc_output_file(TCCState *s1, const char *filename) · 216 unmodified lines | ||
| 1595 | 1608 | put_dt(dynamic, DT_REL, rel_addr); |
| 1596 | 1609 | put_dt(dynamic, DT_RELSZ, rel_size); |
| 1597 | 1610 | put_dt(dynamic, DT_RELENT, sizeof(Elf32_Rel)); |
| 1611 | + if (do_debug) | |
| 1612 | + put_dt(dynamic, DT_DEBUG, 0); | |
| 1598 | 1613 | put_dt(dynamic, DT_NULL, 0); |
| 1599 | 1614 | } |
| 1600 | 1615 | |
| @@ -1632,7 +1647,7 @@ int tcc_output_file(TCCState *s1, const char *filename) · 31 unmodified lines | ||
| 1632 | 1647 | /* XXX: ignore sections with allocated relocations ? */ |
| 1633 | 1648 | for(i = 1; i < s1->nb_sections; i++) { |
| 1634 | 1649 | s = s1->sections[i]; |
| 1635 | − if (s->reloc && s != s1->got) | |
| 1650 | + if (s->reloc && s != s1->got && (s->sh_flags & SHF_ALLOC)) //gr | |
| 1636 | 1651 | relocate_section(s1, s); |
| 1637 | 1652 | } |
| 1638 | 1653 | |