aboutsummaryrefslogtreecommitdiff
path: root/linux-user/gen-vdso.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux-user/gen-vdso.c')
-rw-r--r--linux-user/gen-vdso.c67
1 files changed, 36 insertions, 31 deletions
diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c
index 31e333b..fce9d5c 100644
--- a/linux-user/gen-vdso.c
+++ b/linux-user/gen-vdso.c
@@ -56,13 +56,14 @@ static unsigned rt_sigreturn_addr;
int main(int argc, char **argv)
{
- FILE *inf, *outf;
+ FILE *inf = NULL, *outf = NULL;
long total_len;
const char *prefix = "vdso";
const char *inf_name;
const char *outf_name = NULL;
- unsigned char *buf;
+ unsigned char *buf = NULL;
bool need_bswap;
+ int ret = EXIT_FAILURE;
while (1) {
int opt = getopt(argc, argv, "o:p:r:s:");
@@ -129,24 +130,6 @@ int main(int argc, char **argv)
fprintf(stderr, "%s: incomplete read\n", inf_name);
return EXIT_FAILURE;
}
- fclose(inf);
-
- /*
- * Write out the vdso image now, before we make local changes.
- */
-
- fprintf(outf,
- "/* Automatically generated from linux-user/gen-vdso.c. */\n"
- "\n"
- "static const uint8_t %s_image[] = {",
- prefix);
- for (long i = 0; i < total_len; ++i) {
- if (i % 12 == 0) {
- fputs("\n ", outf);
- }
- fprintf(outf, " 0x%02x,", buf[i]);
- }
- fprintf(outf, "\n};\n\n");
/*
* Identify which elf flavor we're processing.
@@ -179,14 +162,17 @@ int main(int argc, char **argv)
* Output relocation addresses as we go.
*/
- fprintf(outf, "static const unsigned %s_relocs[] = {\n", prefix);
+ fprintf(outf,
+ "/* Automatically generated by linux-user/gen-vdso.c. */\n"
+ "\n"
+ "static const unsigned %s_relocs[] = {\n", prefix);
switch (buf[EI_CLASS]) {
case ELFCLASS32:
- elf32_process(outf, buf, need_bswap);
+ elf32_process(outf, buf, total_len, need_bswap);
break;
case ELFCLASS64:
- elf64_process(outf, buf, need_bswap);
+ elf64_process(outf, buf, total_len, need_bswap);
break;
default:
fprintf(stderr, "%s: invalid elf EI_CLASS (%u)\n",
@@ -196,6 +182,20 @@ int main(int argc, char **argv)
fprintf(outf, "};\n\n"); /* end vdso_relocs. */
+ /*
+ * Write out the vdso image now, after we made local changes.
+ */
+ fprintf(outf,
+ "static const uint8_t %s_image[] = {",
+ prefix);
+ for (long i = 0; i < total_len; ++i) {
+ if (i % 12 == 0) {
+ fputs("\n ", outf);
+ }
+ fprintf(outf, " 0x%02x,", buf[i]);
+ }
+ fprintf(outf, "\n};\n\n");
+
fprintf(outf, "static const VdsoImageInfo %s_image_info = {\n", prefix);
fprintf(outf, " .image = %s_image,\n", prefix);
fprintf(outf, " .relocs = %s_relocs,\n", prefix);
@@ -205,19 +205,24 @@ int main(int argc, char **argv)
fprintf(outf, " .rt_sigreturn_ofs = 0x%x,\n", rt_sigreturn_addr);
fprintf(outf, "};\n");
- /*
- * Everything should have gone well.
- */
- if (fclose(outf)) {
- goto perror_outf;
+ ret = EXIT_SUCCESS;
+
+ cleanup:
+ free(buf);
+
+ if (outf && fclose(outf) != 0) {
+ ret = EXIT_FAILURE;
+ }
+ if (inf && fclose(inf) != 0) {
+ ret = EXIT_FAILURE;
}
- return EXIT_SUCCESS;
+ return ret;
perror_inf:
perror(inf_name);
- return EXIT_FAILURE;
+ goto cleanup;
perror_outf:
perror(outf_name);
- return EXIT_FAILURE;
+ goto cleanup;
}