blob: c6f766f680f21065654ff7aec5491655c78ce166 [file] [log] [blame]
Andrew Geissler09209ee2020-12-13 08:44:15 -06001From f4ca9db9d38f865505322595a8a1e8f69d5bb87c 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 +
22 libdwfl/dwfl_error.c | 9 +++++++++
23 libdwfl/linux-kernel-modules.c | 1 +
Andrew Geissler09209ee2020-12-13 08:44:15 -060024 libelf/elf.h | 7 +++++++
25 6 files changed, 45 insertions(+), 1 deletion(-)
Andrew Geissler82c905d2020-04-13 13:39:40 -050026 create mode 100644 lib/error.h
27
28diff --git a/lib/error.h b/lib/error.h
29new file mode 100644
30index 0000000..ef06827
31--- /dev/null
32+++ b/lib/error.h
33@@ -0,0 +1,27 @@
34+#ifndef _ERROR_H_
35+#define _ERROR_H_
36+
37+#include <stdarg.h>
38+#include <stdio.h>
39+#include <stdlib.h>
40+#include <string.h>
41+#include <errno.h>
42+
43+static unsigned int error_message_count = 0;
44+
45+static inline void error(int status, int errnum, const char* format, ...)
46+{
47+ va_list ap;
48+ fprintf(stderr, "%s: ", program_invocation_name);
49+ va_start(ap, format);
50+ vfprintf(stderr, format, ap);
51+ va_end(ap);
52+ if (errnum)
53+ fprintf(stderr, ": %s", strerror(errnum));
54+ fprintf(stderr, "\n");
55+ error_message_count++;
56+ if (status)
57+ exit(status);
58+}
59+
60+#endif /* _ERROR_H_ */
61diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
62index dac2a5f..43016fc 100644
63--- a/lib/fixedsizehash.h
64+++ b/lib/fixedsizehash.h
65@@ -30,7 +30,6 @@
66 #include <errno.h>
67 #include <stdlib.h>
68 #include <string.h>
69-#include <sys/cdefs.h>
70
71 #include <system.h>
72
73diff --git a/lib/libeu.h b/lib/libeu.h
74index ecb4d01..edc85e3 100644
75--- a/lib/libeu.h
76+++ b/lib/libeu.h
77@@ -29,6 +29,7 @@
78 #ifndef LIBEU_H
79 #define LIBEU_H
80
81+#include "system.h"
82 #include <stddef.h>
83 #include <stdint.h>
84
85diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
86index 7bcf61c..11dcc8b 100644
87--- a/libdwfl/dwfl_error.c
88+++ b/libdwfl/dwfl_error.c
89@@ -154,7 +154,16 @@ dwfl_errmsg (int error)
90 switch (error &~ 0xffff)
91 {
92 case OTHER_ERROR (ERRNO):
93+#if defined(__GLIBC__)
94 return strerror_r (error & 0xffff, "bad", 0);
95+#else
96+ {
97+ static __thread char buf[128] = "";
98+ if (strerror_r (error & 0xffff, buf, sizeof(buf)) == 0)
99+ return buf;
100+ }
101+ return "strerror_r() failed";
102+#endif
103 case OTHER_ERROR (LIBELF):
104 return elf_errmsg (error & 0xffff);
105 case OTHER_ERROR (LIBDW):
106diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
Andrew Geissler09209ee2020-12-13 08:44:15 -0600107index 6edb27f..f331e3c 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500108--- a/libdwfl/linux-kernel-modules.c
109+++ b/libdwfl/linux-kernel-modules.c
110@@ -50,6 +50,7 @@
111 #include <sys/utsname.h>
112 #include <fcntl.h>
113 #include <unistd.h>
114+#include "system.h"
115
116 /* If fts.h is included before config.h, its indirect inclusions may not
117 give us the right LFS aliases of these functions, so map them manually. */
118diff --git a/libelf/elf.h b/libelf/elf.h
Andrew Geissler09209ee2020-12-13 08:44:15 -0600119index 6439c1a..a87c589 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500120--- a/libelf/elf.h
121+++ b/libelf/elf.h
Andrew Geissler09209ee2020-12-13 08:44:15 -0600122@@ -19,6 +19,10 @@
123 #ifndef _ELF_H
124 #define _ELF_H 1
Andrew Geissler82c905d2020-04-13 13:39:40 -0500125
Andrew Geissler82c905d2020-04-13 13:39:40 -0500126+#ifdef __cplusplus
127+extern "C" {
128+#endif
Andrew Geissler09209ee2020-12-13 08:44:15 -0600129+
Andrew Geissler82c905d2020-04-13 13:39:40 -0500130 /* Standard ELF types. */
131
Andrew Geissler09209ee2020-12-13 08:44:15 -0600132 #include <stdint.h>
133@@ -4101,4 +4105,7 @@ enum
Andrew Geissler475cb722020-07-10 16:00:51 -0500134 #define R_ARC_TLS_LE_S9 0x4a
135 #define R_ARC_TLS_LE_32 0x4b
Andrew Geissler82c905d2020-04-13 13:39:40 -0500136
Andrew Geissler82c905d2020-04-13 13:39:40 -0500137+#ifdef __cplusplus
138+}
139+#endif
140 #endif /* elf.h */