blob: c7360da7a7adbf8cadec06df4129c3f7fa1e4d0f [file] [log] [blame]
Andrew Geissler09036742021-06-25 14:25:14 -05001From 0f4667f0bb4b000d74ade07e90bd690b7217a19d Mon Sep 17 00:00:00 2001
Andrew Geissler82c905d2020-04-13 13:39:40 -05002From: Hongxu Jia <hongxu.jia@windriver.com>
3Date: Fri, 23 Aug 2019 10:18:47 +0800
Andrew Geissler475cb722020-07-10 16:00:51 -05004Subject: [PATCH] musl-libs
Andrew Geissler82c905d2020-04-13 13:39:40 -05005
6Collection of fixes needed to compile libelf and other libraries
7provided by elfutils for musl targets
8
9error is glibc specific API, so this patch will mostly not accepted
10upstream given that elfutils has been closely tied to glibc
11
12Signed-off-by: Khem Raj <raj.khem@gmail.com>
13Upstream-Status: Inappropriate [workaround for musl]
14
15Rebase to 0.177
16Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
17
18---
19 lib/error.h | 27 +++++++++++++++++++++++++++
20 lib/fixedsizehash.h | 1 -
21 lib/libeu.h | 1 +
Andrew Geissler82c905d2020-04-13 13:39:40 -050022 libdwfl/linux-kernel-modules.c | 1 +
Andrew Geissler09209ee2020-12-13 08:44:15 -060023 libelf/elf.h | 7 +++++++
Andrew Geissler90fd73c2021-03-05 15:25:55 -060024 5 files changed, 36 insertions(+), 1 deletion(-)
Andrew Geissler82c905d2020-04-13 13:39:40 -050025 create mode 100644 lib/error.h
26
27diff --git a/lib/error.h b/lib/error.h
28new file mode 100644
29index 0000000..ef06827
30--- /dev/null
31+++ b/lib/error.h
32@@ -0,0 +1,27 @@
33+#ifndef _ERROR_H_
34+#define _ERROR_H_
35+
36+#include <stdarg.h>
37+#include <stdio.h>
38+#include <stdlib.h>
39+#include <string.h>
40+#include <errno.h>
41+
42+static unsigned int error_message_count = 0;
43+
44+static inline void error(int status, int errnum, const char* format, ...)
45+{
46+ va_list ap;
47+ fprintf(stderr, "%s: ", program_invocation_name);
48+ va_start(ap, format);
49+ vfprintf(stderr, format, ap);
50+ va_end(ap);
51+ if (errnum)
52+ fprintf(stderr, ": %s", strerror(errnum));
53+ fprintf(stderr, "\n");
54+ error_message_count++;
55+ if (status)
56+ exit(status);
57+}
58+
59+#endif /* _ERROR_H_ */
60diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
61index dac2a5f..43016fc 100644
62--- a/lib/fixedsizehash.h
63+++ b/lib/fixedsizehash.h
64@@ -30,7 +30,6 @@
65 #include <errno.h>
66 #include <stdlib.h>
67 #include <string.h>
68-#include <sys/cdefs.h>
69
70 #include <system.h>
71
72diff --git a/lib/libeu.h b/lib/libeu.h
73index ecb4d01..edc85e3 100644
74--- a/lib/libeu.h
75+++ b/lib/libeu.h
76@@ -29,6 +29,7 @@
77 #ifndef LIBEU_H
78 #define LIBEU_H
79
80+#include "system.h"
81 #include <stddef.h>
82 #include <stdint.h>
83
Andrew Geissler82c905d2020-04-13 13:39:40 -050084diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
Andrew Geissler09036742021-06-25 14:25:14 -050085index c0f8dfa..aa78033 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050086--- a/libdwfl/linux-kernel-modules.c
87+++ b/libdwfl/linux-kernel-modules.c
88@@ -50,6 +50,7 @@
89 #include <sys/utsname.h>
90 #include <fcntl.h>
91 #include <unistd.h>
92+#include "system.h"
93
94 /* If fts.h is included before config.h, its indirect inclusions may not
95 give us the right LFS aliases of these functions, so map them manually. */
96diff --git a/libelf/elf.h b/libelf/elf.h
Andrew Geissler90fd73c2021-03-05 15:25:55 -060097index 8e3e618..1353890 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050098--- a/libelf/elf.h
99+++ b/libelf/elf.h
Andrew Geissler09209ee2020-12-13 08:44:15 -0600100@@ -19,6 +19,10 @@
101 #ifndef _ELF_H
102 #define _ELF_H 1
Andrew Geissler82c905d2020-04-13 13:39:40 -0500103
Andrew Geissler82c905d2020-04-13 13:39:40 -0500104+#ifdef __cplusplus
105+extern "C" {
106+#endif
Andrew Geissler09209ee2020-12-13 08:44:15 -0600107+
Andrew Geissler82c905d2020-04-13 13:39:40 -0500108 /* Standard ELF types. */
109
Andrew Geissler09209ee2020-12-13 08:44:15 -0600110 #include <stdint.h>
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600111@@ -4102,4 +4106,7 @@ enum
Andrew Geissler475cb722020-07-10 16:00:51 -0500112 #define R_ARC_TLS_LE_S9 0x4a
113 #define R_ARC_TLS_LE_32 0x4b
Andrew Geissler82c905d2020-04-13 13:39:40 -0500114
Andrew Geissler82c905d2020-04-13 13:39:40 -0500115+#ifdef __cplusplus
116+}
117+#endif
118 #endif /* elf.h */