modpost.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_Section
  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_Section
  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. #if KERNEL_ELFDATA != HOST_ELFDATA
  54. static inline void __endian(const void *src, void *dest, unsigned int size)
  55. {
  56. unsigned int i;
  57. for (i = 0; i < size; i++)
  58. ((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
  59. }
  60. #define TO_NATIVE(x) \
  61. ({ \
  62. typeof(x) __x; \
  63. __endian(&(x), &(__x), sizeof(__x)); \
  64. __x; \
  65. })
  66. #else /* endianness matches */
  67. #define TO_NATIVE(x) (x)
  68. #endif
  69. #define NOFAIL(ptr) do_nofail((ptr), #ptr)
  70. void *do_nofail(void *ptr, const char *expr);
  71. struct buffer {
  72. char *p;
  73. int pos;
  74. int size;
  75. };
  76. void __attribute__((format(printf, 2, 3)))
  77. buf_printf(struct buffer *buf, const char *fmt, ...);
  78. void
  79. buf_write(struct buffer *buf, const char *s, int len);
  80. struct module {
  81. struct module *next;
  82. const char *name;
  83. int gpl_compatible;
  84. struct symbol *unres;
  85. int seen;
  86. int skip;
  87. int has_init;
  88. int has_cleanup;
  89. struct buffer dev_table_buf;
  90. char srcversion[25];
  91. };
  92. struct elf_info {
  93. unsigned long size;
  94. Elf_Ehdr *hdr;
  95. Elf_Shdr *sechdrs;
  96. Elf_Sym *symtab_start;
  97. Elf_Sym *symtab_stop;
  98. Elf_Section export_sec;
  99. Elf_Section export_unused_sec;
  100. Elf_Section export_gpl_sec;
  101. Elf_Section export_unused_gpl_sec;
  102. Elf_Section export_gpl_future_sec;
  103. const char *strtab;
  104. char *modinfo;
  105. unsigned int modinfo_len;
  106. };
  107. /* file2alias.c */
  108. void handle_moddevtable(struct module *mod, struct elf_info *info,
  109. Elf_Sym *sym, const char *symname);
  110. void add_moddevtable(struct buffer *buf, struct module *mod);
  111. /* sumversion.c */
  112. void maybe_frob_rcs_version(const char *modfilename,
  113. char *version,
  114. void *modinfo,
  115. unsigned long modinfo_offset);
  116. void get_src_version(const char *modname, char sum[], unsigned sumlen);
  117. /* from modpost.c */
  118. void *grab_file(const char *filename, unsigned long *size);
  119. char* get_next_line(unsigned long *pos, void *file, unsigned long size);
  120. void release_file(void *file, unsigned long size);
  121. void fatal(const char *fmt, ...);
  122. void warn(const char *fmt, ...);