modpost.h 3.6 KB

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