diff options
author | Andy Lutomirski <luto@amacapital.net> | 2014-06-18 18:59:47 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2014-06-19 18:44:59 -0400 |
commit | c1979c370273fd9f7326ffa27a63b9ddb0f495f4 (patch) | |
tree | a68748a48f4b25cc5f5483f2a676ca48a2925d68 | |
parent | 5f56e7167e6d438324fcba87018255d81e201383 (diff) |
x86/vdso2c: Use better macros for ELF bitness
Rather than using a separate macro for each replacement, use generic
macros.
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/d953cd2e70ceee1400985d091188cdd65fba2f05.1403129369.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r-- | arch/x86/vdso/vdso2c.c | 42 | ||||
-rw-r--r-- | arch/x86/vdso/vdso2c.h | 23 |
2 files changed, 25 insertions, 40 deletions
diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c index 7a6bf50f9165..734389976cc0 100644 --- a/arch/x86/vdso/vdso2c.c +++ b/arch/x86/vdso/vdso2c.c | |||
@@ -83,37 +83,21 @@ extern void bad_put_le(void); | |||
83 | 83 | ||
84 | #define NSYMS (sizeof(required_syms) / sizeof(required_syms[0])) | 84 | #define NSYMS (sizeof(required_syms) / sizeof(required_syms[0])) |
85 | 85 | ||
86 | #define BITS 64 | 86 | #define BITSFUNC3(name, bits) name##bits |
87 | #define GOFUNC go64 | 87 | #define BITSFUNC2(name, bits) BITSFUNC3(name, bits) |
88 | #define Elf_Ehdr Elf64_Ehdr | 88 | #define BITSFUNC(name) BITSFUNC2(name, ELF_BITS) |
89 | #define Elf_Shdr Elf64_Shdr | 89 | |
90 | #define Elf_Phdr Elf64_Phdr | 90 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x |
91 | #define Elf_Sym Elf64_Sym | 91 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x) |
92 | #define Elf_Dyn Elf64_Dyn | 92 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x) |
93 | |||
94 | #define ELF_BITS 64 | ||
93 | #include "vdso2c.h" | 95 | #include "vdso2c.h" |
94 | #undef BITS | 96 | #undef ELF_BITS |
95 | #undef GOFUNC | 97 | |
96 | #undef Elf_Ehdr | 98 | #define ELF_BITS 32 |
97 | #undef Elf_Shdr | ||
98 | #undef Elf_Phdr | ||
99 | #undef Elf_Sym | ||
100 | #undef Elf_Dyn | ||
101 | |||
102 | #define BITS 32 | ||
103 | #define GOFUNC go32 | ||
104 | #define Elf_Ehdr Elf32_Ehdr | ||
105 | #define Elf_Shdr Elf32_Shdr | ||
106 | #define Elf_Phdr Elf32_Phdr | ||
107 | #define Elf_Sym Elf32_Sym | ||
108 | #define Elf_Dyn Elf32_Dyn | ||
109 | #include "vdso2c.h" | 99 | #include "vdso2c.h" |
110 | #undef BITS | 100 | #undef ELF_BITS |
111 | #undef GOFUNC | ||
112 | #undef Elf_Ehdr | ||
113 | #undef Elf_Shdr | ||
114 | #undef Elf_Phdr | ||
115 | #undef Elf_Sym | ||
116 | #undef Elf_Dyn | ||
117 | 101 | ||
118 | static void go(void *addr, size_t len, FILE *outfile, const char *name) | 102 | static void go(void *addr, size_t len, FILE *outfile, const char *name) |
119 | { | 103 | { |
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h index c6eefaf389b9..8e185ce39e69 100644 --- a/arch/x86/vdso/vdso2c.h +++ b/arch/x86/vdso/vdso2c.h | |||
@@ -4,23 +4,24 @@ | |||
4 | * are built for 32-bit userspace. | 4 | * are built for 32-bit userspace. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name) | 7 | static void BITSFUNC(go)(void *addr, size_t len, |
8 | FILE *outfile, const char *name) | ||
8 | { | 9 | { |
9 | int found_load = 0; | 10 | int found_load = 0; |
10 | unsigned long load_size = -1; /* Work around bogus warning */ | 11 | unsigned long load_size = -1; /* Work around bogus warning */ |
11 | unsigned long data_size; | 12 | unsigned long data_size; |
12 | Elf_Ehdr *hdr = (Elf_Ehdr *)addr; | 13 | ELF(Ehdr) *hdr = (ELF(Ehdr) *)addr; |
13 | int i; | 14 | int i; |
14 | unsigned long j; | 15 | unsigned long j; |
15 | Elf_Shdr *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr, | 16 | ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr, |
16 | *alt_sec = NULL; | 17 | *alt_sec = NULL; |
17 | Elf_Dyn *dyn = 0, *dyn_end = 0; | 18 | ELF(Dyn) *dyn = 0, *dyn_end = 0; |
18 | const char *secstrings; | 19 | const char *secstrings; |
19 | uint64_t syms[NSYMS] = {}; | 20 | uint64_t syms[NSYMS] = {}; |
20 | 21 | ||
21 | uint64_t fake_sections_value = 0, fake_sections_size = 0; | 22 | uint64_t fake_sections_value = 0, fake_sections_size = 0; |
22 | 23 | ||
23 | Elf_Phdr *pt = (Elf_Phdr *)(addr + GET_LE(&hdr->e_phoff)); | 24 | ELF(Phdr) *pt = (ELF(Phdr) *)(addr + GET_LE(&hdr->e_phoff)); |
24 | 25 | ||
25 | /* Walk the segment table. */ | 26 | /* Walk the segment table. */ |
26 | for (i = 0; i < GET_LE(&hdr->e_phnum); i++) { | 27 | for (i = 0; i < GET_LE(&hdr->e_phnum); i++) { |
@@ -61,7 +62,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name) | |||
61 | GET_LE(&hdr->e_shentsize)*GET_LE(&hdr->e_shstrndx); | 62 | GET_LE(&hdr->e_shentsize)*GET_LE(&hdr->e_shstrndx); |
62 | secstrings = addr + GET_LE(&secstrings_hdr->sh_offset); | 63 | secstrings = addr + GET_LE(&secstrings_hdr->sh_offset); |
63 | for (i = 0; i < GET_LE(&hdr->e_shnum); i++) { | 64 | for (i = 0; i < GET_LE(&hdr->e_shnum); i++) { |
64 | Elf_Shdr *sh = addr + GET_LE(&hdr->e_shoff) + | 65 | ELF(Shdr) *sh = addr + GET_LE(&hdr->e_shoff) + |
65 | GET_LE(&hdr->e_shentsize) * i; | 66 | GET_LE(&hdr->e_shentsize) * i; |
66 | if (GET_LE(&sh->sh_type) == SHT_SYMTAB) | 67 | if (GET_LE(&sh->sh_type) == SHT_SYMTAB) |
67 | symtab_hdr = sh; | 68 | symtab_hdr = sh; |
@@ -82,7 +83,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name) | |||
82 | i < GET_LE(&symtab_hdr->sh_size) / GET_LE(&symtab_hdr->sh_entsize); | 83 | i < GET_LE(&symtab_hdr->sh_size) / GET_LE(&symtab_hdr->sh_entsize); |
83 | i++) { | 84 | i++) { |
84 | int k; | 85 | int k; |
85 | Elf_Sym *sym = addr + GET_LE(&symtab_hdr->sh_offset) + | 86 | ELF(Sym) *sym = addr + GET_LE(&symtab_hdr->sh_offset) + |
86 | GET_LE(&symtab_hdr->sh_entsize) * i; | 87 | GET_LE(&symtab_hdr->sh_entsize) * i; |
87 | const char *name = addr + GET_LE(&strtab_hdr->sh_offset) + | 88 | const char *name = addr + GET_LE(&strtab_hdr->sh_offset) + |
88 | GET_LE(&sym->st_name); | 89 | GET_LE(&sym->st_name); |
@@ -123,12 +124,12 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name) | |||
123 | fail("end_mapping must be a multiple of 4096\n"); | 124 | fail("end_mapping must be a multiple of 4096\n"); |
124 | 125 | ||
125 | /* Remove sections or use fakes */ | 126 | /* Remove sections or use fakes */ |
126 | if (fake_sections_size % sizeof(Elf_Shdr)) | 127 | if (fake_sections_size % sizeof(ELF(Shdr))) |
127 | fail("vdso_fake_sections size is not a multiple of %ld\n", | 128 | fail("vdso_fake_sections size is not a multiple of %ld\n", |
128 | (long)sizeof(Elf_Shdr)); | 129 | (long)sizeof(ELF(Shdr))); |
129 | PUT_LE(&hdr->e_shoff, fake_sections_value); | 130 | PUT_LE(&hdr->e_shoff, fake_sections_value); |
130 | PUT_LE(&hdr->e_shentsize, fake_sections_value ? sizeof(Elf_Shdr) : 0); | 131 | PUT_LE(&hdr->e_shentsize, fake_sections_value ? sizeof(ELF(Shdr)) : 0); |
131 | PUT_LE(&hdr->e_shnum, fake_sections_size / sizeof(Elf_Shdr)); | 132 | PUT_LE(&hdr->e_shnum, fake_sections_size / sizeof(ELF(Shdr))); |
132 | PUT_LE(&hdr->e_shstrndx, SHN_UNDEF); | 133 | PUT_LE(&hdr->e_shstrndx, SHN_UNDEF); |
133 | 134 | ||
134 | if (!name) { | 135 | if (!name) { |