mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
Fix relocs of unwanted sections
relocation sections to sections we don't want to handle lead to segfaults, handle this situation (by ignoring the relocs as well).
This commit is contained in:
parent
749d19d70b
commit
fef838db2d
14
tccelf.c
14
tccelf.c
@ -2271,6 +2271,7 @@ static void *load_data(int fd, unsigned long file_offset, unsigned long size)
|
|||||||
typedef struct SectionMergeInfo {
|
typedef struct SectionMergeInfo {
|
||||||
Section *s; /* corresponding existing section */
|
Section *s; /* corresponding existing section */
|
||||||
unsigned long offset; /* offset of the new section in the existing section */
|
unsigned long offset; /* offset of the new section in the existing section */
|
||||||
|
unsigned long oldlen; /* size of existing section before adding this one */
|
||||||
uint8_t new_section; /* true if section 's' was added */
|
uint8_t new_section; /* true if section 's' was added */
|
||||||
uint8_t link_once; /* true if link once section */
|
uint8_t link_once; /* true if link once section */
|
||||||
} SectionMergeInfo;
|
} SectionMergeInfo;
|
||||||
@ -2421,6 +2422,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* align start of section */
|
/* align start of section */
|
||||||
|
sm_table[i].oldlen = s->data_offset;
|
||||||
offset = s->data_offset;
|
offset = s->data_offset;
|
||||||
|
|
||||||
if (0 == strcmp(sh_name, ".stab")) {
|
if (0 == strcmp(sh_name, ".stab")) {
|
||||||
@ -2478,9 +2480,15 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
|
|||||||
if (sh->sh_link > 0)
|
if (sh->sh_link > 0)
|
||||||
s->link = sm_table[sh->sh_link].s;
|
s->link = sm_table[sh->sh_link].s;
|
||||||
if (sh->sh_type == SHT_RELX) {
|
if (sh->sh_type == SHT_RELX) {
|
||||||
s->sh_info = sm_table[sh->sh_info].s->sh_num;
|
if (sm_table[sh->sh_info].s) {
|
||||||
/* update backward link */
|
s->sh_info = sm_table[sh->sh_info].s->sh_num;
|
||||||
s1->sections[s->sh_info]->reloc = s;
|
/* update backward link */
|
||||||
|
s1->sections[s->sh_info]->reloc = s;
|
||||||
|
} else {
|
||||||
|
/* we haven't read the target of relocs, so cancel them */
|
||||||
|
s->data_offset = sm_table[i].oldlen;
|
||||||
|
sm_table[i].s = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sm = sm_table;
|
sm = sm_table;
|
||||||
|
Loading…
Reference in New Issue
Block a user