buildroot/package/elf2flt/0004-elf2flt-create-a-commo...

77 lines
2.6 KiB
Diff

From 4f28e4329897b7f23d828b375fb365d0e30c9cb5 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 c2816b6..8cd48d9 100644
--- a/elf2flt.c
+++ b/elf2flt.c
@@ -346,6 +346,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,
@@ -437,8 +444,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);
@@ -1902,8 +1908,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) {
@@ -1941,8 +1946,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,
elf2flt_bfd_section_size(s)))
@@ -1971,8 +1975,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,
elf2flt_bfd_section_size(s)))
--
2.41.0