relocation sections to sections we don't want to handle lead to segfaults, handle this situation (by ignoring the relocs as well).
Unified · Split
| @@ -2271,6 +2271,7 @@ static void *load_data(int fd, unsigned long file_offset, unsigned long size) · 2270 unmodified lines | |||
| 2271 | typedef struct SectionMergeInfo { | 2271 | typedef struct SectionMergeInfo { |
| 2272 | Section *s; /* corresponding existing section */ | 2272 | Section *s; /* corresponding existing section */ |
| 2273 | unsigned long offset; /* offset of the new section in the existing section */ | 2273 | unsigned long offset; /* offset of the new section in the existing section */ |
| 2274 | unsigned long oldlen; /* size of existing section before adding this one */ | ||
| 2274 | uint8_t new_section; /* true if section 's' was added */ | 2275 | uint8_t new_section; /* true if section 's' was added */ |
| 2275 | uint8_t link_once; /* true if link once section */ | 2276 | uint8_t link_once; /* true if link once section */ |
| 2276 | } SectionMergeInfo; | 2277 | } SectionMergeInfo; |
| @@ -2421,6 +2422,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 144 unmodified lines | |||
| 2421 | } | 2422 | } |
| 2422 | 2423 | ||
| 2423 | /* align start of section */ | 2424 | /* align start of section */ |
| 2425 | sm_table[i].oldlen = s->data_offset; | ||
| 2424 | offset = s->data_offset; | 2426 | offset = s->data_offset; |
| 2425 | 2427 | ||
| 2426 | if (0 == strcmp(sh_name, ".stab")) { | 2428 | if (0 == strcmp(sh_name, ".stab")) { |
| @@ -2478,9 +2480,15 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 51 unmodified lines | |||
| 2478 | if (sh->sh_link > 0) | 2480 | if (sh->sh_link > 0) |
| 2479 | s->link = sm_table[sh->sh_link].s; | 2481 | s->link = sm_table[sh->sh_link].s; |
| 2480 | if (sh->sh_type == SHT_RELX) { | 2482 | if (sh->sh_type == SHT_RELX) { |
| 2481 | s->sh_info = sm_table[sh->sh_info].s->sh_num; | 2483 | if (sm_table[sh->sh_info].s) { |
| 2482 | /* update backward link */ | 2484 | s->sh_info = sm_table[sh->sh_info].s->sh_num; |
| 2483 | s1->sections[s->sh_info]->reloc = s; | 2485 | /* update backward link */ |
| 2486 | s1->sections[s->sh_info]->reloc = s; | ||
| 2487 | } else { | ||
| 2488 | /* we haven't read the target of relocs, so cancel them */ | ||
| 2489 | s->data_offset = sm_table[i].oldlen; | ||
| 2490 | sm_table[i].s = NULL; | ||
| 2491 | } | ||
| 2484 | } | 2492 | } |
| 2485 | } | 2493 | } |
| 2486 | sm = sm_table; | 2494 | sm = sm_table; |