History

fix bogus relocations with TCC_OUTPUT_DLL

grischka committed 18 years ago

Commit 0d598ac1 parent 23594b61 file · +17 −2Browse files

Unified · Split

tccelf.c+17−2
@@ -1367,12 +1367,25 @@ int tcc_output_file(TCCState *s1, const char *filename) · 1366 unmodified lines
13671367 for(i = 1; i < s1->nb_sections; i++) {
13681368 s = s1->sections[i];
13691369 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
13701379 /* when generating a DLL, we include relocations but we may
13711380 patch them */
13721381 if (file_type == TCC_OUTPUT_DLL &&
13731382 s->sh_type == SHT_REL &&
13741383 !(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;
13761389 } else if (do_debug ||
13771390 file_type == TCC_OUTPUT_OBJ ||
13781391 (s->sh_flags & SHF_ALLOC) ||
@@ -1595,6 +1608,8 @@ int tcc_output_file(TCCState *s1, const char *filename) · 216 unmodified lines
15951608 put_dt(dynamic, DT_REL, rel_addr);
15961609 put_dt(dynamic, DT_RELSZ, rel_size);
15971610 put_dt(dynamic, DT_RELENT, sizeof(Elf32_Rel));
1611+ if (do_debug)
1612+ put_dt(dynamic, DT_DEBUG, 0);
15981613 put_dt(dynamic, DT_NULL, 0);
15991614 }
16001615
@@ -1632,7 +1647,7 @@ int tcc_output_file(TCCState *s1, const char *filename) · 31 unmodified lines
16321647 /* XXX: ignore sections with allocated relocations ? */
16331648 for(i = 1; i < s1->nb_sections; i++) {
16341649 s = s1->sections[i];
1635− if (s->reloc && s != s1->got)
1650+ if (s->reloc && s != s1->got && (s->sh_flags & SHF_ALLOC)) //gr
16361651 relocate_section(s1, s);
16371652 }
16381653

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t