blob: b9b9f120dfa4912448c9de04badfa3bac1813c5e [file] [log] [blame]
Brad Bishopa34c0302019-09-23 22:34:48 -04001From d5a1651df9884fcf57ed320bc2f866538af2f420 Mon Sep 17 00:00:00 2001
2From: Hongxu Jia <hongxu.jia@windriver.com>
3Date: Fri, 23 Aug 2019 10:18:47 +0800
4Subject: [PATCH 2/3] musl-libs
5
Brad Bishop96ff1982019-08-19 13:50:42 -04006Collection 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
Brad Bishopa34c0302019-09-23 22:34:48 -040015Rebase to 0.177
16Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
17---
18 lib/error.h | 27 +++++++++++++++++++++++++++
19 lib/fixedsizehash.h | 1 -
20 lib/libeu.h | 1 +
21 libdwfl/dwfl_error.c | 9 +++++++++
22 libdwfl/linux-kernel-modules.c | 1 +
23 libelf/elf.h | 9 ++++++---
24 6 files changed, 44 insertions(+), 4 deletions(-)
25 create mode 100644 lib/error.h
26
27diff --git a/lib/error.h b/lib/error.h
28new file mode 100644
29index 0000000..ef06827
Brad Bishop96ff1982019-08-19 13:50:42 -040030--- /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_ */
Brad Bishopa34c0302019-09-23 22:34:48 -040060diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
61index dac2a5f..43016fc 100644
Brad Bishop96ff1982019-08-19 13:50:42 -040062--- 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
Brad Bishopa34c0302019-09-23 22:34:48 -040072diff --git a/lib/libeu.h b/lib/libeu.h
73index ecb4d01..edc85e3 100644
Brad Bishop96ff1982019-08-19 13:50:42 -040074--- 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
Brad Bishopa34c0302019-09-23 22:34:48 -040084diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
85index 7bcf61c..11dcc8b 100644
Brad Bishop96ff1982019-08-19 13:50:42 -040086--- a/libdwfl/dwfl_error.c
87+++ b/libdwfl/dwfl_error.c
88@@ -154,7 +154,16 @@ dwfl_errmsg (int error)
89 switch (error &~ 0xffff)
90 {
91 case OTHER_ERROR (ERRNO):
92+#if defined(__GLIBC__)
93 return strerror_r (error & 0xffff, "bad", 0);
94+#else
95+ {
96+ static __thread char buf[128] = "";
97+ if (strerror_r (error & 0xffff, buf, sizeof(buf)) == 0)
98+ return buf;
99+ }
100+ return "strerror_r() failed";
101+#endif
102 case OTHER_ERROR (LIBELF):
103 return elf_errmsg (error & 0xffff);
104 case OTHER_ERROR (LIBDW):
Brad Bishopa34c0302019-09-23 22:34:48 -0400105diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
106index d46ab5a..1c3faee 100644
Brad Bishop96ff1982019-08-19 13:50:42 -0400107--- a/libdwfl/linux-kernel-modules.c
108+++ b/libdwfl/linux-kernel-modules.c
109@@ -50,6 +50,7 @@
110 #include <sys/utsname.h>
111 #include <fcntl.h>
112 #include <unistd.h>
113+#include "system.h"
114
115 /* If fts.h is included before config.h, its indirect inclusions may not
116 give us the right LFS aliases of these functions, so map them manually. */
Brad Bishopa34c0302019-09-23 22:34:48 -0400117diff --git a/libelf/elf.h b/libelf/elf.h
118index bed273d..be228e6 100644
Brad Bishop96ff1982019-08-19 13:50:42 -0400119--- a/libelf/elf.h
120+++ b/libelf/elf.h
121@@ -21,7 +21,9 @@
122
123 #include <features.h>
124
125-__BEGIN_DECLS
126+#ifdef __cplusplus
127+extern "C" {
128+#endif
129
130 /* Standard ELF types. */
131
Brad Bishopa34c0302019-09-23 22:34:48 -0400132@@ -4029,6 +4031,7 @@ enum
133 #define R_NDS32_TLS_TPOFF 102
134 #define R_NDS32_TLS_DESC 119
Brad Bishop96ff1982019-08-19 13:50:42 -0400135
136-__END_DECLS
137-
138+#ifdef __cplusplus
139+}
140+#endif
141 #endif /* elf.h */
Brad Bishopa34c0302019-09-23 22:34:48 -0400142--
1432.7.4
144