aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/vdso
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-05-30 11:48:48 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2014-05-30 19:58:39 -0400
commit011561837dad082a92c0537db2d134e66419c6ad (patch)
treeab06fc63a9dc39a17867030b0e04441aaf2af004 /arch/x86/vdso
parent94aca80897501f994c795cffc458ecd0404377c7 (diff)
x86/vdso, build: When vdso2c fails, unlink the output
This avoids bizarre failures if make is run again. Signed-off-by: Andy Lutomirski <luto@amacapital.net> Link: http://lkml.kernel.org/r/1764385fe9931e8940b9d001132515448ea89523.1401464755.git.luto@amacapital.net Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/vdso')
-rw-r--r--arch/x86/vdso/vdso2c.c20
-rw-r--r--arch/x86/vdso/vdso2c.h10
2 files changed, 14 insertions, 16 deletions
diff --git a/arch/x86/vdso/vdso2c.c b/arch/x86/vdso/vdso2c.c
index 81edd1ec9df8..fe8bfbf62612 100644
--- a/arch/x86/vdso/vdso2c.c
+++ b/arch/x86/vdso/vdso2c.c
@@ -14,6 +14,8 @@
14#include <linux/elf.h> 14#include <linux/elf.h>
15#include <linux/types.h> 15#include <linux/types.h>
16 16
17const char *outfilename;
18
17/* Symbols that we need in vdso2c. */ 19/* Symbols that we need in vdso2c. */
18enum { 20enum {
19 sym_vvar_page, 21 sym_vvar_page,
@@ -44,6 +46,7 @@ static void fail(const char *format, ...)
44 va_start(ap, format); 46 va_start(ap, format);
45 fprintf(stderr, "Error: "); 47 fprintf(stderr, "Error: ");
46 vfprintf(stderr, format, ap); 48 vfprintf(stderr, format, ap);
49 unlink(outfilename);
47 exit(1); 50 exit(1);
48 va_end(ap); 51 va_end(ap);
49} 52}
@@ -82,17 +85,16 @@ static void fail(const char *format, ...)
82#undef Elf_Sym 85#undef Elf_Sym
83#undef Elf_Dyn 86#undef Elf_Dyn
84 87
85static int go(void *addr, size_t len, FILE *outfile, const char *name) 88static void go(void *addr, size_t len, FILE *outfile, const char *name)
86{ 89{
87 Elf64_Ehdr *hdr = (Elf64_Ehdr *)addr; 90 Elf64_Ehdr *hdr = (Elf64_Ehdr *)addr;
88 91
89 if (hdr->e_ident[EI_CLASS] == ELFCLASS64) { 92 if (hdr->e_ident[EI_CLASS] == ELFCLASS64) {
90 return go64(addr, len, outfile, name); 93 go64(addr, len, outfile, name);
91 } else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) { 94 } else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) {
92 return go32(addr, len, outfile, name); 95 go32(addr, len, outfile, name);
93 } else { 96 } else {
94 fprintf(stderr, "Error: unknown ELF class\n"); 97 fail("unknown ELF class\n");
95 return 1;
96 } 98 }
97} 99}
98 100
@@ -102,7 +104,6 @@ int main(int argc, char **argv)
102 off_t len; 104 off_t len;
103 void *addr; 105 void *addr;
104 FILE *outfile; 106 FILE *outfile;
105 int ret;
106 char *name, *tmp; 107 char *name, *tmp;
107 int namelen; 108 int namelen;
108 109
@@ -143,14 +144,15 @@ int main(int argc, char **argv)
143 if (addr == MAP_FAILED) 144 if (addr == MAP_FAILED)
144 err(1, "mmap"); 145 err(1, "mmap");
145 146
146 outfile = fopen(argv[2], "w"); 147 outfilename = argv[2];
148 outfile = fopen(outfilename, "w");
147 if (!outfile) 149 if (!outfile)
148 err(1, "%s", argv[2]); 150 err(1, "%s", argv[2]);
149 151
150 ret = go(addr, (size_t)len, outfile, name); 152 go(addr, (size_t)len, outfile, name);
151 153
152 munmap(addr, len); 154 munmap(addr, len);
153 fclose(outfile); 155 fclose(outfile);
154 156
155 return ret; 157 return 0;
156} 158}
diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index 3dcc61e796e9..26a7c1fa7452 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -4,7 +4,7 @@
4 * are built for 32-bit userspace. 4 * are built for 32-bit userspace.
5 */ 5 */
6 6
7static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name) 7static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
8{ 8{
9 int found_load = 0; 9 int found_load = 0;
10 unsigned long load_size = -1; /* Work around bogus warning */ 10 unsigned long load_size = -1; /* Work around bogus warning */
@@ -62,10 +62,8 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
62 alt_sec = sh; 62 alt_sec = sh;
63 } 63 }
64 64
65 if (!symtab_hdr) { 65 if (!symtab_hdr)
66 fail("no symbol table\n"); 66 fail("no symbol table\n");
67 return 1;
68 }
69 67
70 strtab_hdr = addr + hdr->e_shoff + 68 strtab_hdr = addr + hdr->e_shoff +
71 hdr->e_shentsize * symtab_hdr->sh_link; 69 hdr->e_shentsize * symtab_hdr->sh_link;
@@ -112,7 +110,7 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
112 110
113 if (!name) { 111 if (!name) {
114 fwrite(addr, load_size, 1, outfile); 112 fwrite(addr, load_size, 1, outfile);
115 return 0; 113 return;
116 } 114 }
117 115
118 fprintf(outfile, "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n\n"); 116 fprintf(outfile, "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n\n");
@@ -152,6 +150,4 @@ static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
152 required_syms[i], syms[i]); 150 required_syms[i], syms[i]);
153 } 151 }
154 fprintf(outfile, "};\n"); 152 fprintf(outfile, "};\n");
155
156 return 0;
157} 153}