Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 207be05c44da5c4c31179a34660e176145ff8d4b Mon Sep 17 00:00:00 2001 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 3 | Date: Mon, 2 Jul 2018 09:52:23 +0800 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4 | Subject: [PATCH] build: Provide alternatives for glibc assumptions helps |
| 5 | compiling it on musl |
| 6 | |
| 7 | Upstream-Status: Pending |
| 8 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 9 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 10 | Rebase to 0.175 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | |
| 12 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> |
| 13 | --- |
| 14 | Makefile.am | 2 +- |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 15 | lib/fixedsizehash.h | 1 - |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 16 | lib/system.h | 12 +++++++++++- |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 17 | libdw/Makefile.am | 3 ++- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | libdwfl/dwfl_build_id_find_elf.c | 1 + |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | libdwfl/dwfl_error.c | 4 +++- |
| 20 | libdwfl/dwfl_module_getdwarf.c | 1 + |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | libdwfl/libdwfl_crc32_file.c | 9 +++++++++ |
| 22 | libdwfl/linux-kernel-modules.c | 1 + |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | libelf/elf.h | 8 ++++++-- |
| 24 | libelf/libelf.h | 1 + |
| 25 | libelf/libelfP.h | 1 + |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 26 | 12 files changed, 37 insertions(+), 7 deletions(-) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 27 | |
| 28 | diff --git a/Makefile.am b/Makefile.am |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | index 2ff444e..41f77df 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | --- a/Makefile.am |
| 31 | +++ b/Makefile.am |
| 32 | @@ -28,7 +28,7 @@ pkginclude_HEADERS = version.h |
| 33 | |
| 34 | # Add doc back when we have some real content. |
| 35 | SUBDIRS = config m4 lib libelf libebl libdwelf libdwfl libdw libcpu libasm \ |
| 36 | - backends src po tests |
| 37 | + backends po tests |
| 38 | |
| 39 | EXTRA_DIST = elfutils.spec GPG-KEY NOTES CONTRIBUTING \ |
| 40 | COPYING COPYING-GPLV2 COPYING-LGPLV3 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 41 | diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 42 | index dac2a5f..43016fc 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 43 | --- a/lib/fixedsizehash.h |
| 44 | +++ b/lib/fixedsizehash.h |
| 45 | @@ -30,7 +30,6 @@ |
| 46 | #include <errno.h> |
| 47 | #include <stdlib.h> |
| 48 | #include <string.h> |
| 49 | -#include <sys/cdefs.h> |
| 50 | |
| 51 | #include <system.h> |
| 52 | |
| 53 | diff --git a/lib/system.h b/lib/system.h |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 54 | index 292082b..308a762 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 55 | --- a/lib/system.h |
| 56 | +++ b/lib/system.h |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 57 | @@ -30,7 +30,7 @@ |
| 58 | #define LIB_SYSTEM_H 1 |
| 59 | |
| 60 | #include <errno.h> |
| 61 | -#include <error.h> |
| 62 | +#include <err.h> |
| 63 | #include <stddef.h> |
| 64 | #include <stdint.h> |
| 65 | #include <sys/param.h> |
| 66 | @@ -51,6 +51,16 @@ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 67 | #else |
| 68 | # error "Unknown byte order" |
| 69 | #endif |
| 70 | +#ifndef TEMP_FAILURE_RETRY |
| 71 | +#define TEMP_FAILURE_RETRY(expression) \ |
| 72 | + (__extension__ \ |
| 73 | + ({ long int __result; \ |
| 74 | + do __result = (long int) (expression); \ |
| 75 | + while (__result == -1L && errno == EINTR); \ |
| 76 | + __result; })) |
| 77 | +#endif |
| 78 | + |
| 79 | +#define error(status, errno, ...) err(status, __VA_ARGS__) |
| 80 | |
| 81 | #ifndef MAX |
| 82 | #define MAX(m, n) ((m) < (n) ? (n) : (m)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 83 | diff --git a/libdw/Makefile.am b/libdw/Makefile.am |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 84 | index 7a3d532..7ac1241 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 85 | --- a/libdw/Makefile.am |
| 86 | +++ b/libdw/Makefile.am |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 87 | @@ -108,7 +108,8 @@ am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 88 | libdw_so_LIBS = libdw_pic.a ../libdwelf/libdwelf_pic.a \ |
| 89 | ../libdwfl/libdwfl_pic.a ../libebl/libebl.a |
| 90 | libdw_so_DEPS = ../lib/libeu.a ../libelf/libelf.so |
| 91 | -libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS) |
| 92 | +fts_LDADD = -lfts |
| 93 | +libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS) $(fts_LDADD) |
| 94 | libdw_so_SOURCES = |
| 95 | libdw.so$(EXEEXT): $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS) |
| 96 | # The rpath is necessary for libebl because its $ORIGIN use will |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 97 | diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 98 | index cc6c3f6..b06ab59 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 99 | --- a/libdwfl/dwfl_build_id_find_elf.c |
| 100 | +++ b/libdwfl/dwfl_build_id_find_elf.c |
| 101 | @@ -31,6 +31,7 @@ |
| 102 | #endif |
| 103 | |
| 104 | #include "libdwflP.h" |
| 105 | +#include "system.h" |
| 106 | #include <inttypes.h> |
| 107 | #include <fcntl.h> |
| 108 | #include <unistd.h> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 109 | diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 110 | index 7bcf61c..c345797 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 111 | --- a/libdwfl/dwfl_error.c |
| 112 | +++ b/libdwfl/dwfl_error.c |
| 113 | @@ -140,6 +140,7 @@ __libdwfl_seterrno (Dwfl_Error error) |
| 114 | const char * |
| 115 | dwfl_errmsg (int error) |
| 116 | { |
| 117 | + static __thread char s[64] = ""; |
| 118 | if (error == 0 || error == -1) |
| 119 | { |
| 120 | int last_error = global_error; |
| 121 | @@ -154,7 +155,8 @@ dwfl_errmsg (int error) |
| 122 | switch (error &~ 0xffff) |
| 123 | { |
| 124 | case OTHER_ERROR (ERRNO): |
| 125 | - return strerror_r (error & 0xffff, "bad", 0); |
| 126 | + strerror_r (error & 0xffff, s, sizeof(s)); |
| 127 | + return s; |
| 128 | case OTHER_ERROR (LIBELF): |
| 129 | return elf_errmsg (error & 0xffff); |
| 130 | case OTHER_ERROR (LIBDW): |
| 131 | diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 132 | index 56e6105..f4a0649 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 133 | --- a/libdwfl/dwfl_module_getdwarf.c |
| 134 | +++ b/libdwfl/dwfl_module_getdwarf.c |
| 135 | @@ -35,6 +35,7 @@ |
| 136 | #include <fcntl.h> |
| 137 | #include <string.h> |
| 138 | #include <unistd.h> |
| 139 | +#include "system.h" |
| 140 | #include "../libdw/libdwP.h" /* DWARF_E_* values are here. */ |
| 141 | #include "../libelf/libelfP.h" |
| 142 | #include "system.h" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 143 | diff --git a/libdwfl/libdwfl_crc32_file.c b/libdwfl/libdwfl_crc32_file.c |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 144 | index f849128..6f0aca1 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 145 | --- a/libdwfl/libdwfl_crc32_file.c |
| 146 | +++ b/libdwfl/libdwfl_crc32_file.c |
| 147 | @@ -29,6 +29,15 @@ |
| 148 | # include <config.h> |
| 149 | #endif |
| 150 | |
| 151 | +#ifndef TEMP_FAILURE_RETRY |
| 152 | +#define TEMP_FAILURE_RETRY(expression) \ |
| 153 | + (__extension__ \ |
| 154 | + ({ long int __result; \ |
| 155 | + do __result = (long int) (expression); \ |
| 156 | + while (__result == -1L && errno == EINTR); \ |
| 157 | + __result; })) |
| 158 | +#endif |
| 159 | + |
| 160 | #define crc32_file attribute_hidden __libdwfl_crc32_file |
| 161 | #define crc32 __libdwfl_crc32 |
| 162 | #include <libdwflP.h> |
| 163 | diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 164 | index 360e4ee..b5aa397 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 165 | --- a/libdwfl/linux-kernel-modules.c |
| 166 | +++ b/libdwfl/linux-kernel-modules.c |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 167 | @@ -41,6 +41,7 @@ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 168 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 169 | #include "libelfP.h" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 170 | #include "libdwflP.h" |
| 171 | +#include "system.h" |
| 172 | #include <inttypes.h> |
| 173 | #include <errno.h> |
| 174 | #include <stdio.h> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 175 | diff --git a/libelf/elf.h b/libelf/elf.h |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 176 | index 5dc632b..14da1b7 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 177 | --- a/libelf/elf.h |
| 178 | +++ b/libelf/elf.h |
| 179 | @@ -21,7 +21,9 @@ |
| 180 | |
| 181 | #include <features.h> |
| 182 | |
| 183 | -__BEGIN_DECLS |
| 184 | +#ifdef __cplusplus |
| 185 | +extern "C" { |
| 186 | +#endif |
| 187 | |
| 188 | /* Standard ELF types. */ |
| 189 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 190 | @@ -3937,6 +3939,8 @@ enum |
| 191 | #define R_METAG_TLS_LE_HI16 60 |
| 192 | #define R_METAG_TLS_LE_LO16 61 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 193 | |
| 194 | -__END_DECLS |
| 195 | +#ifdef __cplusplus |
| 196 | +} |
| 197 | +#endif |
| 198 | |
| 199 | #endif /* elf.h */ |
| 200 | diff --git a/libelf/libelf.h b/libelf/libelf.h |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 201 | index 1ff11c9..c21e018 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 202 | --- a/libelf/libelf.h |
| 203 | +++ b/libelf/libelf.h |
| 204 | @@ -29,6 +29,7 @@ |
| 205 | #ifndef _LIBELF_H |
| 206 | #define _LIBELF_H 1 |
| 207 | |
| 208 | +#include <fcntl.h> |
| 209 | #include <stdint.h> |
| 210 | #include <sys/types.h> |
| 211 | |
| 212 | diff --git a/libelf/libelfP.h b/libelf/libelfP.h |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 213 | index 9f3e8e9..10a347a 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 214 | --- a/libelf/libelfP.h |
| 215 | +++ b/libelf/libelfP.h |
| 216 | @@ -32,6 +32,7 @@ |
| 217 | |
| 218 | #include <ar.h> |
| 219 | #include <gelf.h> |
| 220 | +#include <libelf.h> |
| 221 | |
| 222 | #include <errno.h> |
| 223 | #include <stdbool.h> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 224 | -- |
| 225 | 2.7.4 |
| 226 | |