aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/vdso/vdsomunge.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/arch/arm/vdso/vdsomunge.c b/arch/arm/vdso/vdsomunge.c
index 9005b07296c8..aedec81d1198 100644
--- a/arch/arm/vdso/vdsomunge.c
+++ b/arch/arm/vdso/vdsomunge.c
@@ -45,13 +45,11 @@
45 * it does. 45 * it does.
46 */ 46 */
47 47
48#define _GNU_SOURCE
49
50#include <byteswap.h> 48#include <byteswap.h>
51#include <elf.h> 49#include <elf.h>
52#include <errno.h> 50#include <errno.h>
53#include <error.h>
54#include <fcntl.h> 51#include <fcntl.h>
52#include <stdarg.h>
55#include <stdbool.h> 53#include <stdbool.h>
56#include <stdio.h> 54#include <stdio.h>
57#include <stdlib.h> 55#include <stdlib.h>
@@ -82,11 +80,25 @@
82#define EF_ARM_ABI_FLOAT_HARD 0x400 80#define EF_ARM_ABI_FLOAT_HARD 0x400
83#endif 81#endif
84 82
83static int failed;
84static const char *argv0;
85static const char *outfile; 85static const char *outfile;
86 86
87static void fail(const char *fmt, ...)
88{
89 va_list ap;
90
91 failed = 1;
92 fprintf(stderr, "%s: ", argv0);
93 va_start(ap, fmt);
94 vfprintf(stderr, fmt, ap);
95 va_end(ap);
96 exit(EXIT_FAILURE);
97}
98
87static void cleanup(void) 99static void cleanup(void)
88{ 100{
89 if (error_message_count > 0 && outfile != NULL) 101 if (failed && outfile != NULL)
90 unlink(outfile); 102 unlink(outfile);
91} 103}
92 104
@@ -119,68 +131,66 @@ int main(int argc, char **argv)
119 int infd; 131 int infd;
120 132
121 atexit(cleanup); 133 atexit(cleanup);
134 argv0 = argv[0];
122 135
123 if (argc != 3) 136 if (argc != 3)
124 error(EXIT_FAILURE, 0, "Usage: %s [infile] [outfile]", argv[0]); 137 fail("Usage: %s [infile] [outfile]\n", argv[0]);
125 138
126 infile = argv[1]; 139 infile = argv[1];
127 outfile = argv[2]; 140 outfile = argv[2];
128 141
129 infd = open(infile, O_RDONLY); 142 infd = open(infile, O_RDONLY);
130 if (infd < 0) 143 if (infd < 0)
131 error(EXIT_FAILURE, errno, "Cannot open %s", infile); 144 fail("Cannot open %s: %s\n", infile, strerror(errno));
132 145
133 if (fstat(infd, &stat) != 0) 146 if (fstat(infd, &stat) != 0)
134 error(EXIT_FAILURE, errno, "Failed stat for %s", infile); 147 fail("Failed stat for %s: %s\n", infile, strerror(errno));
135 148
136 inbuf = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, infd, 0); 149 inbuf = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, infd, 0);
137 if (inbuf == MAP_FAILED) 150 if (inbuf == MAP_FAILED)
138 error(EXIT_FAILURE, errno, "Failed to map %s", infile); 151 fail("Failed to map %s: %s\n", infile, strerror(errno));
139 152
140 close(infd); 153 close(infd);
141 154
142 inhdr = inbuf; 155 inhdr = inbuf;
143 156
144 if (memcmp(&inhdr->e_ident, ELFMAG, SELFMAG) != 0) 157 if (memcmp(&inhdr->e_ident, ELFMAG, SELFMAG) != 0)
145 error(EXIT_FAILURE, 0, "Not an ELF file"); 158 fail("Not an ELF file\n");
146 159
147 if (inhdr->e_ident[EI_CLASS] != ELFCLASS32) 160 if (inhdr->e_ident[EI_CLASS] != ELFCLASS32)
148 error(EXIT_FAILURE, 0, "Unsupported ELF class"); 161 fail("Unsupported ELF class\n");
149 162
150 swap = inhdr->e_ident[EI_DATA] != HOST_ORDER; 163 swap = inhdr->e_ident[EI_DATA] != HOST_ORDER;
151 164
152 if (read_elf_half(inhdr->e_type, swap) != ET_DYN) 165 if (read_elf_half(inhdr->e_type, swap) != ET_DYN)
153 error(EXIT_FAILURE, 0, "Not a shared object"); 166 fail("Not a shared object\n");
154 167
155 if (read_elf_half(inhdr->e_machine, swap) != EM_ARM) { 168 if (read_elf_half(inhdr->e_machine, swap) != EM_ARM)
156 error(EXIT_FAILURE, 0, "Unsupported architecture %#x", 169 fail("Unsupported architecture %#x\n", inhdr->e_machine);
157 inhdr->e_machine);
158 }
159 170
160 e_flags = read_elf_word(inhdr->e_flags, swap); 171 e_flags = read_elf_word(inhdr->e_flags, swap);
161 172
162 if (EF_ARM_EABI_VERSION(e_flags) != EF_ARM_EABI_VER5) { 173 if (EF_ARM_EABI_VERSION(e_flags) != EF_ARM_EABI_VER5) {
163 error(EXIT_FAILURE, 0, "Unsupported EABI version %#x", 174 fail("Unsupported EABI version %#x\n",
164 EF_ARM_EABI_VERSION(e_flags)); 175 EF_ARM_EABI_VERSION(e_flags));
165 } 176 }
166 177
167 if (e_flags & EF_ARM_ABI_FLOAT_HARD) 178 if (e_flags & EF_ARM_ABI_FLOAT_HARD)
168 error(EXIT_FAILURE, 0, 179 fail("Unexpected hard-float flag set in e_flags\n");
169 "Unexpected hard-float flag set in e_flags");
170 180
171 clear_soft_float = !!(e_flags & EF_ARM_ABI_FLOAT_SOFT); 181 clear_soft_float = !!(e_flags & EF_ARM_ABI_FLOAT_SOFT);
172 182
173 outfd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); 183 outfd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
174 if (outfd < 0) 184 if (outfd < 0)
175 error(EXIT_FAILURE, errno, "Cannot open %s", outfile); 185 fail("Cannot open %s: %s\n", outfile, strerror(errno));
176 186
177 if (ftruncate(outfd, stat.st_size) != 0) 187 if (ftruncate(outfd, stat.st_size) != 0)
178 error(EXIT_FAILURE, errno, "Cannot truncate %s", outfile); 188 fail("Cannot truncate %s: %s\n", outfile, strerror(errno));
179 189
180 outbuf = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, 190 outbuf = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
181 outfd, 0); 191 outfd, 0);
182 if (outbuf == MAP_FAILED) 192 if (outbuf == MAP_FAILED)
183 error(EXIT_FAILURE, errno, "Failed to map %s", outfile); 193 fail("Failed to map %s: %s\n", outfile, strerror(errno));
184 194
185 close(outfd); 195 close(outfd);
186 196
@@ -195,7 +205,7 @@ int main(int argc, char **argv)
195 } 205 }
196 206
197 if (msync(outbuf, stat.st_size, MS_SYNC) != 0) 207 if (msync(outbuf, stat.st_size, MS_SYNC) != 0)
198 error(EXIT_FAILURE, errno, "Failed to sync %s", outfile); 208 fail("Failed to sync %s: %s\n", outfile, strerror(errno));
199 209
200 return EXIT_SUCCESS; 210 return EXIT_SUCCESS;
201} 211}