ports/devel/dwz/patches/patch-dwz_c

121 lines
3.2 KiB
Text
Raw Normal View History

2023-08-16 22:26:55 +00:00
Create error() function, Linux-ism.
Our libelf doesn't have some of these defines.
obstack is not a system header
xxhash is not a system header
Index: dwz.c
--- dwz.c.orig
+++ dwz.c
@@ -20,13 +20,13 @@
#include <assert.h>
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
#include <setjmp.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <stdarg.h>
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
@@ -36,10 +36,10 @@
#include <sys/times.h>
#include <sys/wait.h>
-#include <obstack.h>
+#include "obstack.h"
#include <gelf.h>
-#include <xxhash.h>
+#include "xxhash.h"
#include "dwarf2.h"
#include "hashtab.h"
@@ -216,6 +216,29 @@ report_progress (void)
/* Where to longjmp on OOM. */
static jmp_buf oom_buf;
+/* error () wrapper based on the Linux manual page at
+ http://man7.org/linux/man-pages/man3/error.3.html. */
+void
+error (int status, int errnum, const char *fmt, ...)
+{
+ va_list ap;
+
+ fprintf (stderr, "%s: ", getprogname());
+ if (fmt != NULL) {
+ va_start (ap, fmt);
+ vfprintf (stderr, fmt, ap);
+ va_end (ap);
+ }
+
+ if (errnum != 0)
+ fprintf (stderr, ": %s", strerror(errnum));
+
+ fputc ('\n', stderr);
+
+ if (status != 0)
+ exit (status);
+}
+
/* Handle OOM situation. If handling more than one file, we might
just fail to handle some large file due to OOM, but could very well
handle other smaller files after it. */
@@ -13675,7 +13698,7 @@ fdopen_dso (int fd, const char *name)
int i;
DSO *dso = NULL;
- elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);
+ elf = elf_begin (fd, ELF_C_READ, NULL);
if (elf == NULL)
{
error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1));
@@ -13713,7 +13736,7 @@ fdopen_dso (int fd, const char *name)
goto error_out;
}
- elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT | ELF_F_PERMISSIVE);
+ elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT);
memset (dso, 0, sizeof(DSO));
dso->elf = elf;
@@ -14210,7 +14233,7 @@ write_dso (DSO *dso, const char *file, struct stat *st
free (shstrtab);
return 1;
}
- elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT | ELF_F_PERMISSIVE);
+ elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT);
for (i = 0; i < ehdr.e_phnum; ++i)
{
GElf_Phdr *phdr, phdr_mem;
@@ -14283,7 +14306,7 @@ write_dso (DSO *dso, const char *file, struct stat *st
}
}
- if (elf_update (elf, ELF_C_WRITE_MMAP) == -1)
+ if (elf_update (elf, ELF_C_WRITE) == -1)
{
error (0, 0, "%s: elf_update failed", dso->filename);
unlink (file);
@@ -15902,7 +15925,7 @@ optimize_multifile (unsigned int *die_count)
error (0, 0, "Could not create new ELF headers");
goto fail;
}
- elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT | ELF_F_PERMISSIVE);
+ elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT);
sha1_init_ctx (&ctx);
for (i = 0; debug_sections[i].name; i++)
@@ -15995,7 +16018,7 @@ optimize_multifile (unsigned int *die_count)
data->d_off = 0;
data->d_align = 1;
- if (elf_update (elf, ELF_C_WRITE_MMAP) == -1)
+ if (elf_update (elf, ELF_C_WRITE) == -1)
{
error (0, 0, "%s: elf_update failed", multifile);
goto fail;