Advertisement
programjm

elf.c

Aug 14th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include<stdlib.h>
  2.  
  3. #undef FALSE
  4. #undef TRUE
  5. #define FALSE 0
  6. #define TRUE 1
  7. #define BFD_HOST_U_64_BIT unsigned long
  8.  
  9.  
  10. typedef BFD_HOST_U_64_BIT bfd_vma;
  11. typedef int bfd_boolean;
  12. typedef unsigned int flagword; /* 32 bits of flags */
  13.  
  14. struct bfd {};
  15.  
  16. typedef struct bfd bfd;
  17.  
  18. struct elf_internal_sym {
  19. unsigned int st_shndx; /* Associated section index */
  20. };
  21.  
  22. typedef struct elf_internal_sym Elf_Internal_Sym;
  23.  
  24. typedef struct
  25. {
  26. /* ELF symbol information. */
  27. Elf_Internal_Sym internal_elf_sym;
  28. } elf_symbol_type;
  29.  
  30. typedef struct bfd_section
  31. {
  32. /* If this section is going to be output, then this value is the
  33. offset in *bytes* into the output section of the first byte in the
  34. input section (byte ==> smallest addressable unit on the
  35. target). In most cases, if this was going to start at the
  36. 100th octet (8-bit quantity) in the output section, this value
  37. would be 100. However, if the target byte size is 16 bits
  38. (bfd_octets_per_byte is "2"), this value would be 50. */
  39. bfd_vma output_offset;
  40. /* The output section through which to map on output. */
  41. struct bfd_section *output_section;
  42. /* The BFD which owns the section. */
  43. bfd *owner;
  44. } asection;
  45.  
  46. typedef struct bfd_symbol
  47. {
  48. /* This symbol was created to point to a section, e.g. ELF's
  49. STT_SECTION symbols. */
  50. #define BSF_SECTION_SYM (1 << 8)
  51. struct bfd_section *section;
  52. flagword flags;
  53. }
  54. asymbol;
  55.  
  56. extern asection _bfd_std_section[4];
  57. #define bfd_abs_section_ptr (&_bfd_std_section[2])
  58.  
  59. static inline bfd_boolean
  60. bfd_is_abs_section (const asection *sec)
  61. {
  62. return sec == bfd_abs_section_ptr;
  63. }
  64.  
  65. static bfd_boolean
  66. ignore_section_sym (bfd *abfd, asymbol *sym)
  67. {
  68. elf_symbol_type *type_ptr;
  69.  
  70. // this is part of fix
  71. if (sym == NULL)
  72. return FALSE;
  73.  
  74. if ((sym->flags & BSF_SECTION_SYM) == 0)
  75. return FALSE;
  76.  
  77. // this is part of fix
  78. if (sym->section == NULL)
  79. return TRUE;
  80.  
  81. // replace actual function call with malloc for testing purpose
  82. type_ptr = malloc(sizeof(elf_symbol_type));
  83. return ((type_ptr != NULL
  84. && type_ptr->internal_elf_sym.st_shndx != 0
  85. && bfd_is_abs_section (sym->section))
  86. || !(sym->section->owner == abfd
  87. // this is part of fix
  88. || (sym->section->output_section != NULL
  89. && sym->section->output_section->owner == abfd
  90. && sym->section->output_offset == 0)
  91. || bfd_is_abs_section (sym->section)));
  92. }
  93.  
  94. int main(){}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement