modpost.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <sys/mman.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <elf.h>
  11. #include "elfconfig.h"
  12. #if KERNEL_ELFCLASS == ELFCLASS32
  13. #define Elf_Ehdr Elf32_Ehdr
  14. #define Elf_Shdr Elf32_Shdr
  15. #define Elf_Sym Elf32_Sym
  16. #define Elf_Addr Elf32_Addr
  17. #define Elf_Sword Elf64_Sword
  18. #define Elf_Section Elf32_Half
  19. #define ELF_ST_BIND ELF32_ST_BIND
  20. #define ELF_ST_TYPE ELF32_ST_TYPE
  21. #define Elf_Rel Elf32_Rel
  22. #define Elf_Rela Elf32_Rela
  23. #define ELF_R_SYM ELF32_R_SYM
  24. #define ELF_R_TYPE ELF32_R_TYPE
  25. #else
  26. #define Elf_Ehdr Elf64_Ehdr
  27. #define Elf_Shdr Elf64_Shdr
  28. #define Elf_Sym Elf64_Sym
  29. #define Elf_Addr Elf64_Addr
  30. #define Elf_Sword Elf64_Sxword
  31. #define Elf_Section Elf64_Half
  32. #define ELF_ST_BIND ELF64_ST_BIND
  33. #define ELF_ST_TYPE ELF64_ST_TYPE
  34. #define Elf_Rel Elf64_Rel
  35. #define Elf_Rela Elf64_Rela
  36. #define ELF_R_SYM ELF64_R_SYM
  37. #define ELF_R_TYPE ELF64_R_TYPE
  38. #endif
  39. /* The 64-bit MIPS ELF ABI uses an unusual reloc format. */
  40. typedef struct
  41. {
  42. Elf32_Word r_sym; /* Symbol index */
  43. unsigned char r_ssym; /* Special symbol for 2nd relocation */
  44. unsigned char r_type3; /* 3rd relocation type */
  45. unsigned char r_type2; /* 2nd relocation type */
  46. unsigned char r_type1; /* 1st relocation type */
  47. } _Elf64_Mips_R_Info;
  48. typedef union
  49. {
  50. Elf64_Xword r_info_number;
  51. _Elf64_Mips_R_Info r_info_fields;
  52. } _Elf64_Mips_R_Info_union;
  53. #define ELF64_MIPS_R_SYM(i) \
  54. ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_sym)
  55. #define ELF64_MIPS_R_TYPE(i) \
  56. ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1)
  57. #if KERNEL_ELFDATA != HOST_ELFDATA
  58. static inline void __endian(const void *src, void *dest, unsigned int size)
  59. {
  60. unsigned int i;
  61. for (i = 0; i < size; i++)
  62. ((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
  63. }
  64. #define TO_NATIVE(x) \
  65. ({ \
  66. typeof(x) __x; \
  67. __endian(&(x), &(__x), sizeof(__x)); \
  68. __x; \
  69. })
  70. #else /* endianness matches */
  71. #define TO_NATIVE(x) (x)
  72. #endif
  73. #define NOFAIL(ptr) do_nofail((ptr), #ptr)
  74. void *do_nofail(void *ptr, const char *expr);
  75. struct buffer {
  76. char *p;
  77. int pos;
  78. int size;
  79. };
  80. void __attribute__((format(printf, 2, 3)))
  81. buf_printf(struct buffer *buf, const char *fmt, ...);
  82. void
  83. buf_write(struct buffer *buf, const char *s, int len);
  84. struct module {
  85. struct module *next;
  86. const char *name;
  87. int gpl_compatible;
  88. struct symbol *unres;
  89. int seen;
  90. int skip;
  91. int has_init;
  92. int has_cleanup;
  93. struct buffer dev_table_buf;
  94. char **markers;
  95. size_t nmarkers;
  96. char srcversion[25];
  97. };
  98. struct elf_info {
  99. unsigned long size;
  100. Elf_Ehdr *hdr;
  101. Elf_Shdr *sechdrs;
  102. Elf_Sym *symtab_start;
  103. Elf_Sym *symtab_stop;
  104. Elf_Section export_sec;
  105. Elf_Section export_unused_sec;
  106. Elf_Section export_gpl_sec;
  107. Elf_Section export_unused_gpl_sec;
  108. Elf_Section export_gpl_future_sec;
  109. Elf_Section markers_strings_sec;
  110. const char *strtab;
  111. char *modinfo;
  112. unsigned int modinfo_len;
  113. };
  114. /* file2alias.c */
  115. extern unsigned int cross_build;
  116. void handle_moddevtable(struct module *mod, struct elf_info *info,
  117. Elf_Sym *sym, const char *symname);
  118. void add_moddevtable(struct buffer *buf, struct module *mod);
  119. /* sumversion.c */
  120. void maybe_frob_rcs_version(const char *modfilename,
  121. char *version,
  122. void *modinfo,
  123. unsigned long modinfo_offset);
  124. void get_src_version(const char *modname, char sum[], unsigned sumlen);
  125. /* from modpost.c */
  126. void *grab_file(const char *filename, unsigned long *size);
  127. char* get_next_line(unsigned long *pos, void *file, unsigned long size);
  128. void release_file(void *file, unsigned long size);
  129. void fatal(const char *fmt, ...);
  130. void warn(const char *fmt, ...);
  131. void merror(const char *fmt, ...);