xref: /linux/scripts/mod/modpost.h (revision de2fe5e07d58424bc286fff3fd3c1b0bf933cd58)
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 
12 #include "elfconfig.h"
13 
14 #if KERNEL_ELFCLASS == ELFCLASS32
15 
16 #define Elf_Ehdr    Elf32_Ehdr
17 #define Elf_Shdr    Elf32_Shdr
18 #define Elf_Sym     Elf32_Sym
19 #define Elf_Addr    Elf32_Addr
20 #define Elf_Section Elf32_Section
21 #define ELF_ST_BIND ELF32_ST_BIND
22 #define ELF_ST_TYPE ELF32_ST_TYPE
23 
24 #define Elf_Rela    Elf32_Rela
25 #define ELF_R_SYM   ELF32_R_SYM
26 #define ELF_R_TYPE  ELF32_R_TYPE
27 #else
28 
29 #define Elf_Ehdr    Elf64_Ehdr
30 #define Elf_Shdr    Elf64_Shdr
31 #define Elf_Sym     Elf64_Sym
32 #define Elf_Addr    Elf64_Addr
33 #define Elf_Section Elf64_Section
34 #define ELF_ST_BIND ELF64_ST_BIND
35 #define ELF_ST_TYPE ELF64_ST_TYPE
36 
37 #define Elf_Rela    Elf64_Rela
38 #define ELF_R_SYM   ELF64_R_SYM
39 #define ELF_R_TYPE  ELF64_R_TYPE
40 #endif
41 
42 #if KERNEL_ELFDATA != HOST_ELFDATA
43 
44 static inline void __endian(const void *src, void *dest, unsigned int size)
45 {
46 	unsigned int i;
47 	for (i = 0; i < size; i++)
48 		((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
49 }
50 
51 
52 
53 #define TO_NATIVE(x)						\
54 ({								\
55 	typeof(x) __x;						\
56 	__endian(&(x), &(__x), sizeof(__x));			\
57 	__x;							\
58 })
59 
60 #else /* endianness matches */
61 
62 #define TO_NATIVE(x) (x)
63 
64 #endif
65 
66 #define NOFAIL(ptr)   do_nofail((ptr), #ptr)
67 void *do_nofail(void *ptr, const char *expr);
68 
69 struct buffer {
70 	char *p;
71 	int pos;
72 	int size;
73 };
74 
75 void __attribute__((format(printf, 2, 3)))
76 buf_printf(struct buffer *buf, const char *fmt, ...);
77 
78 void
79 buf_write(struct buffer *buf, const char *s, int len);
80 
81 struct module {
82 	struct module *next;
83 	const char *name;
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 
93 struct elf_info {
94 	unsigned long size;
95 	Elf_Ehdr     *hdr;
96 	Elf_Shdr     *sechdrs;
97 	Elf_Sym      *symtab_start;
98 	Elf_Sym      *symtab_stop;
99 	const char   *strtab;
100 	char	     *modinfo;
101 	unsigned int modinfo_len;
102 };
103 
104 /* file2alias.c */
105 void handle_moddevtable(struct module *mod, struct elf_info *info,
106 			Elf_Sym *sym, const char *symname);
107 void add_moddevtable(struct buffer *buf, struct module *mod);
108 
109 /* sumversion.c */
110 void maybe_frob_rcs_version(const char *modfilename,
111 			    char *version,
112 			    void *modinfo,
113 			    unsigned long modinfo_offset);
114 void get_src_version(const char *modname, char sum[], unsigned sumlen);
115 
116 /* from modpost.c */
117 void *grab_file(const char *filename, unsigned long *size);
118 char* get_next_line(unsigned long *pos, void *file, unsigned long size);
119 void release_file(void *file, unsigned long size);
120 
121 void fatal(const char *fmt, ...);
122 void warn(const char *fmt, ...);
123