From 37e1e0ace8ccebf54ec2f5522bfc1f9db86946ad Mon Sep 17 00:00:00 2001 From: Niklas Cassel 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 --- 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