Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame^] | 1 | From 9a57efb0f826a70ae360aa55504ee2de656b92b6 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 + |
| 24 | libelf/elf.h | 9 ++++++--- |
| 25 | 6 files changed, 44 insertions(+), 4 deletions(-) |
| 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 | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame^] | 107 | index 0434f1e..5afaee8 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 | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame^] | 119 | index 197b557..8e5b94c 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 120 | --- a/libelf/elf.h |
| 121 | +++ b/libelf/elf.h |
| 122 | @@ -21,7 +21,9 @@ |
| 123 | |
| 124 | #include <features.h> |
| 125 | |
| 126 | -__BEGIN_DECLS |
| 127 | +#ifdef __cplusplus |
| 128 | +extern "C" { |
| 129 | +#endif |
| 130 | |
| 131 | /* Standard ELF types. */ |
| 132 | |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame^] | 133 | @@ -4103,6 +4105,7 @@ enum |
| 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 | |
| 137 | -__END_DECLS |
| 138 | - |
| 139 | +#ifdef __cplusplus |
| 140 | +} |
| 141 | +#endif |
| 142 | #endif /* elf.h */ |