12 #include <sys/types.h>
14 #include <linux/elf.h>
15 #include <linux/types.h>
17 /* Symbols that we need in vdso2c. */
18 char const * const required_syms[] = {
20 "VDSO32_SYSENTER_RETURN",
23 "__kernel_rt_sigreturn",
26 __attribute__((format(printf, 1, 2))) __attribute__((noreturn))
27 static void fail(const char *format, ...)
31 fprintf(stderr, "Error: ");
32 vfprintf(stderr, format, ap);
37 #define NSYMS (sizeof(required_syms) / sizeof(required_syms[0]))
41 #define Elf_Ehdr Elf64_Ehdr
42 #define Elf_Shdr Elf64_Shdr
43 #define Elf_Phdr Elf64_Phdr
44 #define Elf_Sym Elf64_Sym
45 #define Elf_Dyn Elf64_Dyn
57 #define Elf_Ehdr Elf32_Ehdr
58 #define Elf_Shdr Elf32_Shdr
59 #define Elf_Phdr Elf32_Phdr
60 #define Elf_Sym Elf32_Sym
61 #define Elf_Dyn Elf32_Dyn
71 static int go(void *addr, size_t len, FILE *outfile, const char *name)
73 Elf64_Ehdr *hdr = (Elf64_Ehdr *)addr;
75 if (hdr->e_ident[EI_CLASS] == ELFCLASS64) {
76 return go64(addr, len, outfile, name);
77 } else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) {
78 return go32(addr, len, outfile, name);
80 fprintf(stderr, "Error: unknown ELF class\n");
85 int main(int argc, char **argv)
96 printf("Usage: vdso2c INPUT OUTPUT\n");
101 * Figure out the struct name. If we're writing to a .so file,
102 * generate raw output insted.
104 name = strdup(argv[2]);
105 namelen = strlen(name);
106 if (namelen >= 3 && !strcmp(name + namelen - 3, ".so")) {
109 tmp = strrchr(name, '/');
112 tmp = strchr(name, '.');
115 for (tmp = name; *tmp; tmp++)
120 fd = open(argv[1], O_RDONLY);
122 err(1, "%s", argv[1]);
124 len = lseek(fd, 0, SEEK_END);
125 if (len == (off_t)-1)
128 addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
129 if (addr == MAP_FAILED)
132 outfile = fopen(argv[2], "w");
134 err(1, "%s", argv[2]);
136 ret = go(addr, (size_t)len, outfile, name);