kumquat-buildroot/package/elf2flt/0004-elf2flt-create-a-common-helper-function.patch
Niklas Cassel 9dd179d43f package/elf2flt: fix fatal error regression on m68k, xtensa, riscv64
This series fixes a fatal error at link time on m68k, xtensa,
and riscv64, caused by a bad upstream elf2flt commit.

Without this patch, m68k, xtensa, and riscv64 would result in
a fatal error:
ERROR: text=0x3bab8 overlaps data=0x33f60 ?

With this patch, qemu_m68k_mcf5208_defconfig,
qemu_riscv64_nommu_virt_defconfig, and
qemu_xtensa_lx60_nommu_defconfig builds properly.

riscv64 and m68k boots to login prompt.
xtensa crashes when loading init, the same behavior as when
reverting the bad upstream elf2flt commit completely.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-08-11 22:27:26 +02:00

77 lines
2.6 KiB
Diff

From 37e1e0ace8ccebf54ec2f5522bfc1f9db86946ad Mon Sep 17 00:00:00 2001
From: Niklas Cassel <niklas.cassel@wdc.com>
Date: Tue, 9 Aug 2022 12:13:50 +0200
Subject: [PATCH] elf2flt: create a common helper function
In order to make the code more maintainable,
move duplicated code to a common helper function.
No functional change intended.
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
---
elf2flt.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/elf2flt.c b/elf2flt.c
index 669591e..9c32f9a 100644
--- a/elf2flt.c
+++ b/elf2flt.c
@@ -337,6 +337,13 @@ compare_relocs (const void *pa, const void *pb)
}
#endif
+static bool
+ro_reloc_data_section_should_be_in_text(asection *s)
+{
+ return (s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
+ (SEC_DATA | SEC_READONLY | SEC_RELOC);
+}
+
static uint32_t *
output_relocs (
bfd *abs_bfd,
@@ -428,8 +435,7 @@ output_relocs (
*/
if ((!pic_with_got || ALWAYS_RELOC_TEXT) &&
((a->flags & SEC_CODE) ||
- ((a->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
- (SEC_DATA | SEC_READONLY | SEC_RELOC))))
+ ro_reloc_data_section_should_be_in_text(a)))
sectionp = text + (a->vma - text_vma);
else if (a->flags & SEC_DATA)
sectionp = data + (a->vma - data_vma);
@@ -1893,8 +1899,7 @@ int main(int argc, char *argv[])
bfd_vma sec_vma;
if ((s->flags & SEC_CODE) ||
- ((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
- (SEC_DATA | SEC_READONLY | SEC_RELOC))) {
+ ro_reloc_data_section_should_be_in_text(s)) {
vma = &text_vma;
len = &text_len;
} else if (s->flags & SEC_DATA) {
@@ -1932,8 +1937,7 @@ int main(int argc, char *argv[])
* data sections.*/
for (s = abs_bfd->sections; s != NULL; s = s->next)
if ((s->flags & SEC_CODE) ||
- ((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
- (SEC_DATA | SEC_READONLY | SEC_RELOC)))
+ ro_reloc_data_section_should_be_in_text(s))
if (!bfd_get_section_contents(abs_bfd, s,
text + (s->vma - text_vma), 0,
bfd_section_size(abs_bfd, s)))
@@ -1962,8 +1966,7 @@ int main(int argc, char *argv[])
* data sections already included in the text output section.*/
for (s = abs_bfd->sections; s != NULL; s = s->next)
if ((s->flags & SEC_DATA) &&
- ((s->flags & (SEC_READONLY | SEC_RELOC)) !=
- (SEC_READONLY | SEC_RELOC)))
+ !ro_reloc_data_section_should_be_in_text(s))
if (!bfd_get_section_contents(abs_bfd, s,
data + (s->vma - data_vma), 0,
bfd_section_size(abs_bfd, s)))
--
2.37.1