Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elf2flt: fix for segfault on some ARM ELFs #20

Merged
merged 1 commit into from Aug 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions elf2flt.c
Expand Up @@ -363,7 +363,7 @@ output_relocs (
#endif

#if 0
printf("%s(%d): output_relocs(abs_bfd=%d,synbols=0x%x,number_of_symbols=%d"
printf("%s(%d): output_relocs(abs_bfd=%d,symbols=0x%x,number_of_symbols=%d,"
"n_relocs=0x%x,text=0x%x,text_len=%d,data=0x%x,data_len=%d)\n",
__FILE__, __LINE__, abs_bfd, symbols, number_of_symbols, n_relocs,
text, text_len, data, data_len);
Expand Down Expand Up @@ -424,7 +424,8 @@ output_relocs (
*/
if ((!pic_with_got || ALWAYS_RELOC_TEXT) &&
((a->flags & SEC_CODE) ||
((a->flags & (SEC_DATA | SEC_READONLY)) == (SEC_DATA | SEC_READONLY))))
((a->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
(SEC_DATA | SEC_READONLY | SEC_RELOC))))
sectionp = text + (a->vma - text_vma);
else if (a->flags & SEC_DATA)
sectionp = data + (a->vma - data_vma);
Expand Down Expand Up @@ -1875,7 +1876,9 @@ int main(int argc, char *argv[])
bfd_size_type sec_size;
bfd_vma sec_vma;

if (s->flags & SEC_CODE) {
if ((s->flags & SEC_CODE) ||
((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
(SEC_DATA | SEC_READONLY | SEC_RELOC))) {
vma = &text_vma;
len = &text_len;
} else if (s->flags & SEC_DATA) {
Expand Down Expand Up @@ -1908,9 +1911,13 @@ int main(int argc, char *argv[])
if (verbose)
printf("TEXT -> vma=0x%x len=0x%x\n", text_vma, text_len);

/* Read in all text sections. */
/* Read input sections destined for the text output segment.
* Includes code sections, but also includes read-only relocation
* data sections.*/
for (s = abs_bfd->sections; s != NULL; s = s->next)
if (s->flags & SEC_CODE)
if ((s->flags & SEC_CODE) ||
((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
(SEC_DATA | SEC_READONLY | SEC_RELOC)))
if (!bfd_get_section_contents(abs_bfd, s,
text + (s->vma - text_vma), 0,
bfd_section_size(abs_bfd, s)))
Expand All @@ -1934,9 +1941,13 @@ int main(int argc, char *argv[])
text_len = data_vma - text_vma;
}

/* Read in all data sections. */
/* Read input sections destined for the data output segment.
* Includes data sections, but not those read-only relocation
* data sections already included in the text output section.*/
for (s = abs_bfd->sections; s != NULL; s = s->next)
if (s->flags & SEC_DATA)
if ((s->flags & SEC_DATA) &&
((s->flags & (SEC_READONLY | SEC_RELOC)) !=
vapier marked this conversation as resolved.
Show resolved Hide resolved
(SEC_READONLY | SEC_RELOC)))
if (!bfd_get_section_contents(abs_bfd, s,
data + (s->vma - data_vma), 0,
bfd_section_size(abs_bfd, s)))
Expand Down