0004-elf2flt-create-a-common-helper-function.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From 37e1e0ace8ccebf54ec2f5522bfc1f9db86946ad Mon Sep 17 00:00:00 2001
  2. From: Niklas Cassel <niklas.cassel@wdc.com>
  3. Date: Tue, 9 Aug 2022 12:13:50 +0200
  4. Subject: [PATCH] elf2flt: create a common helper function
  5. In order to make the code more maintainable,
  6. move duplicated code to a common helper function.
  7. No functional change intended.
  8. Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
  9. ---
  10. elf2flt.c | 19 +++++++++++--------
  11. 1 file changed, 11 insertions(+), 8 deletions(-)
  12. diff --git a/elf2flt.c b/elf2flt.c
  13. index 669591e..9c32f9a 100644
  14. --- a/elf2flt.c
  15. +++ b/elf2flt.c
  16. @@ -337,6 +337,13 @@ compare_relocs (const void *pa, const void *pb)
  17. }
  18. #endif
  19. +static bool
  20. +ro_reloc_data_section_should_be_in_text(asection *s)
  21. +{
  22. + return (s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
  23. + (SEC_DATA | SEC_READONLY | SEC_RELOC);
  24. +}
  25. +
  26. static uint32_t *
  27. output_relocs (
  28. bfd *abs_bfd,
  29. @@ -428,8 +435,7 @@ output_relocs (
  30. */
  31. if ((!pic_with_got || ALWAYS_RELOC_TEXT) &&
  32. ((a->flags & SEC_CODE) ||
  33. - ((a->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
  34. - (SEC_DATA | SEC_READONLY | SEC_RELOC))))
  35. + ro_reloc_data_section_should_be_in_text(a)))
  36. sectionp = text + (a->vma - text_vma);
  37. else if (a->flags & SEC_DATA)
  38. sectionp = data + (a->vma - data_vma);
  39. @@ -1893,8 +1899,7 @@ int main(int argc, char *argv[])
  40. bfd_vma sec_vma;
  41. if ((s->flags & SEC_CODE) ||
  42. - ((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
  43. - (SEC_DATA | SEC_READONLY | SEC_RELOC))) {
  44. + ro_reloc_data_section_should_be_in_text(s)) {
  45. vma = &text_vma;
  46. len = &text_len;
  47. } else if (s->flags & SEC_DATA) {
  48. @@ -1932,8 +1937,7 @@ int main(int argc, char *argv[])
  49. * data sections.*/
  50. for (s = abs_bfd->sections; s != NULL; s = s->next)
  51. if ((s->flags & SEC_CODE) ||
  52. - ((s->flags & (SEC_DATA | SEC_READONLY | SEC_RELOC)) ==
  53. - (SEC_DATA | SEC_READONLY | SEC_RELOC)))
  54. + ro_reloc_data_section_should_be_in_text(s))
  55. if (!bfd_get_section_contents(abs_bfd, s,
  56. text + (s->vma - text_vma), 0,
  57. bfd_section_size(abs_bfd, s)))
  58. @@ -1962,8 +1966,7 @@ int main(int argc, char *argv[])
  59. * data sections already included in the text output section.*/
  60. for (s = abs_bfd->sections; s != NULL; s = s->next)
  61. if ((s->flags & SEC_DATA) &&
  62. - ((s->flags & (SEC_READONLY | SEC_RELOC)) !=
  63. - (SEC_READONLY | SEC_RELOC)))
  64. + !ro_reloc_data_section_should_be_in_text(s))
  65. if (!bfd_get_section_contents(abs_bfd, s,
  66. data + (s->vma - data_vma), 0,
  67. bfd_section_size(abs_bfd, s)))
  68. --
  69. 2.37.1