Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1 | From f4ca9db9d38f865505322595a8a1e8f69d5bb87c Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | From: Hongxu Jia <hongxu.jia@windriver.com> |
| 3 | Date: Fri, 23 Aug 2019 10:18:47 +0800 |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 4 | Subject: [PATCH] musl-libs |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | |
| 6 | Collection of fixes needed to compile libelf and other libraries |
| 7 | provided by elfutils for musl targets |
| 8 | |
| 9 | error is glibc specific API, so this patch will mostly not accepted |
| 10 | upstream given that elfutils has been closely tied to glibc |
| 11 | |
| 12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 13 | Upstream-Status: Inappropriate [workaround for musl] |
| 14 | |
| 15 | Rebase to 0.177 |
| 16 | Signed-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 Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 24 | libelf/elf.h | 7 +++++++ |
| 25 | 6 files changed, 45 insertions(+), 1 deletion(-) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 26 | create mode 100644 lib/error.h |
| 27 | |
| 28 | diff --git a/lib/error.h b/lib/error.h |
| 29 | new file mode 100644 |
| 30 | index 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_ */ |
| 61 | diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h |
| 62 | index 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 | |
| 73 | diff --git a/lib/libeu.h b/lib/libeu.h |
| 74 | index 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 | |
| 85 | diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c |
| 86 | index 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): |
| 106 | diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 107 | index 6edb27f..f331e3c 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 108 | --- 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. */ |
| 118 | diff --git a/libelf/elf.h b/libelf/elf.h |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 119 | index 6439c1a..a87c589 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 120 | --- a/libelf/elf.h |
| 121 | +++ b/libelf/elf.h |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 122 | @@ -19,6 +19,10 @@ |
| 123 | #ifndef _ELF_H |
| 124 | #define _ELF_H 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 125 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 126 | +#ifdef __cplusplus |
| 127 | +extern "C" { |
| 128 | +#endif |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 129 | + |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 130 | /* Standard ELF types. */ |
| 131 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 132 | #include <stdint.h> |
| 133 | @@ -4101,4 +4105,7 @@ enum |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 134 | #define R_ARC_TLS_LE_S9 0x4a |
| 135 | #define R_ARC_TLS_LE_32 0x4b |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 136 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 137 | +#ifdef __cplusplus |
| 138 | +} |
| 139 | +#endif |
| 140 | #endif /* elf.h */ |