Skip to content

Commit 13ee9fd

Browse files
nsz-armRussell King
authored andcommitted
ARM: 8397/1: fix vdsomunge not to depend on glibc specific error.h
If the host toolchain is not glibc based then the arm kernel build fails with arch/arm/vdso/vdsomunge.c:53:19: fatal error: error.h: No such file or directory error.h is a glibc only header (ie not available in musl, newlib and bsd libcs). Changed the error reporting to standard conforming code to avoid depending on specific C implementations. Signed-off-by: Szabolcs Nagy <szabolcs.nagy@arm.com> Acked-by: Will Deacon <will.deacon@arm.com> Fixes: 8512287 ("ARM: 8330/1: add VDSO user-space code") Cc: stable@vger.kernel.org Signed-off-by: Nathan Lynch <nathan_lynch@mentor.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent eeb3fee commit 13ee9fd

1 file changed

Lines changed: 33 additions & 23 deletions

File tree

‎arch/arm/vdso/vdsomunge.c‎

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@
4545
* it does.
4646
*/
4747

48-
#define _GNU_SOURCE
49-
5048
#include <byteswap.h>
5149
#include <elf.h>
5250
#include <errno.h>
53-
#include <error.h>
5451
#include <fcntl.h>
52+
#include <stdarg.h>
5553
#include <stdbool.h>
5654
#include <stdio.h>
5755
#include <stdlib.h>
@@ -82,11 +80,25 @@
8280
#define EF_ARM_ABI_FLOAT_HARD 0x400
8381
#endif
8482

83+
static int failed;
84+
static const char *argv0;
8585
static const char *outfile;
8686

87+
static 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+
8799
static void cleanup(void)
88100
{
89-
if (error_message_count > 0 && outfile != NULL)
101+
if (failed && outfile != NULL)
90102
unlink(outfile);
91103
}
92104

@@ -119,68 +131,66 @@ int main(int argc, char **argv)
119131
int infd;
120132

121133
atexit(cleanup);
134+
argv0 = argv[0];
122135

123136
if (argc != 3)
124-
error(EXIT_FAILURE, 0, "Usage: %s [infile] [outfile]", argv[0]);
137+
fail("Usage: %s [infile] [outfile]\n", argv[0]);
125138

126139
infile = argv[1];
127140
outfile = argv[2];
128141

129142
infd = open(infile, O_RDONLY);
130143
if (infd < 0)
131-
error(EXIT_FAILURE, errno, "Cannot open %s", infile);
144+
fail("Cannot open %s: %s\n", infile, strerror(errno));
132145

133146
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));
135148

136149
inbuf = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, infd, 0);
137150
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));
139152

140153
close(infd);
141154

142155
inhdr = inbuf;
143156

144157
if (memcmp(&inhdr->e_ident, ELFMAG, SELFMAG) != 0)
145-
error(EXIT_FAILURE, 0, "Not an ELF file");
158+
fail("Not an ELF file\n");
146159

147160
if (inhdr->e_ident[EI_CLASS] != ELFCLASS32)
148-
error(EXIT_FAILURE, 0, "Unsupported ELF class");
161+
fail("Unsupported ELF class\n");
149162

150163
swap = inhdr->e_ident[EI_DATA] != HOST_ORDER;
151164

152165
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");
154167

155-
if (read_elf_half(inhdr->e_machine, swap) != EM_ARM) {
156-
error(EXIT_FAILURE, 0, "Unsupported architecture %#x",
157-
inhdr->e_machine);
158-
}
168+
if (read_elf_half(inhdr->e_machine, swap) != EM_ARM)
169+
fail("Unsupported architecture %#x\n", inhdr->e_machine);
159170

160171
e_flags = read_elf_word(inhdr->e_flags, swap);
161172

162173
if (EF_ARM_EABI_VERSION(e_flags) != EF_ARM_EABI_VER5) {
163-
error(EXIT_FAILURE, 0, "Unsupported EABI version %#x",
164-
EF_ARM_EABI_VERSION(e_flags));
174+
fail("Unsupported EABI version %#x\n",
175+
EF_ARM_EABI_VERSION(e_flags));
165176
}
166177

167178
if (e_flags & EF_ARM_ABI_FLOAT_HARD)
168-
error(EXIT_FAILURE, 0,
169-
"Unexpected hard-float flag set in e_flags");
179+
fail("Unexpected hard-float flag set in e_flags\n");
170180

171181
clear_soft_float = !!(e_flags & EF_ARM_ABI_FLOAT_SOFT);
172182

173183
outfd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
174184
if (outfd < 0)
175-
error(EXIT_FAILURE, errno, "Cannot open %s", outfile);
185+
fail("Cannot open %s: %s\n", outfile, strerror(errno));
176186

177187
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));
179189

180190
outbuf = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
181191
outfd, 0);
182192
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));
184194

185195
close(outfd);
186196

@@ -195,7 +205,7 @@ int main(int argc, char **argv)
195205
}
196206

197207
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));
199209

200210
return EXIT_SUCCESS;
201211
}

0 commit comments

Comments
 (0)