blob: a4f301d9daea226233ecee3f7eec150e4cd927a9 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 990d377a92f4bab04bf6820fc81b3dcb6cf5e31d Mon Sep 17 00:00:00 2001
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002From: Khem Raj <raj.khem@gmail.com>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003Date: Mon, 2 Jul 2018 09:52:23 +0800
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004Subject: [PATCH] build: Provide alternatives for glibc assumptions helps
5 compiling it on musl
6
7Upstream-Status: Pending
8Signed-off-by: Khem Raj <raj.khem@gmail.com>
9
Brad Bishopa5c52ff2018-11-23 10:55:50 +130010Rebase to 0.175
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011
12Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Brad Bishop19323692019-04-05 15:28:33 -040013
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014---
15 Makefile.am | 2 +-
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016 lib/fixedsizehash.h | 1 -
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080017 lib/system.h | 12 +++++++++++-
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018 libdw/Makefile.am | 3 ++-
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080019 libdwfl/dwfl_build_id_find_elf.c | 1 +
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020 libdwfl/dwfl_error.c | 4 +++-
21 libdwfl/dwfl_module_getdwarf.c | 1 +
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022 libdwfl/libdwfl_crc32_file.c | 9 +++++++++
23 libdwfl/linux-kernel-modules.c | 1 +
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 libelf/elf.h | 8 ++++++--
25 libelf/libelf.h | 1 +
26 libelf/libelfP.h | 1 +
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027 12 files changed, 37 insertions(+), 7 deletions(-)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028
29diff --git a/Makefile.am b/Makefile.am
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030index 2ff444e..41f77df 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031--- a/Makefile.am
32+++ b/Makefile.am
33@@ -28,7 +28,7 @@ pkginclude_HEADERS = version.h
34
35 # Add doc back when we have some real content.
36 SUBDIRS = config m4 lib libelf libebl libdwelf libdwfl libdw libcpu libasm \
37- backends src po tests
38+ backends po tests
39
40 EXTRA_DIST = elfutils.spec GPG-KEY NOTES CONTRIBUTING \
41 COPYING COPYING-GPLV2 COPYING-LGPLV3
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080043index dac2a5f..43016fc 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044--- a/lib/fixedsizehash.h
45+++ b/lib/fixedsizehash.h
46@@ -30,7 +30,6 @@
47 #include <errno.h>
48 #include <stdlib.h>
49 #include <string.h>
50-#include <sys/cdefs.h>
51
52 #include <system.h>
53
54diff --git a/lib/system.h b/lib/system.h
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055index 292082b..308a762 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056--- a/lib/system.h
57+++ b/lib/system.h
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080058@@ -30,7 +30,7 @@
59 #define LIB_SYSTEM_H 1
60
61 #include <errno.h>
62-#include <error.h>
63+#include <err.h>
64 #include <stddef.h>
65 #include <stdint.h>
66 #include <sys/param.h>
67@@ -51,6 +51,16 @@
Brad Bishopd7bf8c12018-02-25 22:55:05 -050068 #else
69 # error "Unknown byte order"
70 #endif
71+#ifndef TEMP_FAILURE_RETRY
72+#define TEMP_FAILURE_RETRY(expression) \
73+ (__extension__ \
74+ ({ long int __result; \
75+ do __result = (long int) (expression); \
76+ while (__result == -1L && errno == EINTR); \
77+ __result; }))
78+#endif
79+
80+#define error(status, errno, ...) err(status, __VA_ARGS__)
81
82 #ifndef MAX
83 #define MAX(m, n) ((m) < (n) ? (n) : (m))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050084diff --git a/libdw/Makefile.am b/libdw/Makefile.am
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080085index 7a3d532..7ac1241 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050086--- a/libdw/Makefile.am
87+++ b/libdw/Makefile.am
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088@@ -108,7 +108,8 @@ am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050089 libdw_so_LIBS = libdw_pic.a ../libdwelf/libdwelf_pic.a \
90 ../libdwfl/libdwfl_pic.a ../libebl/libebl.a
91 libdw_so_DEPS = ../lib/libeu.a ../libelf/libelf.so
92-libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS)
93+fts_LDADD = -lfts
94+libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS) $(fts_LDADD)
95 libdw_so_SOURCES =
96 libdw.so$(EXEEXT): $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS)
97 # The rpath is necessary for libebl because its $ORIGIN use will
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099index cc6c3f6..b06ab59 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500100--- a/libdwfl/dwfl_build_id_find_elf.c
101+++ b/libdwfl/dwfl_build_id_find_elf.c
102@@ -31,6 +31,7 @@
103 #endif
104
105 #include "libdwflP.h"
106+#include "system.h"
107 #include <inttypes.h>
108 #include <fcntl.h>
109 #include <unistd.h>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800111index 7bcf61c..c345797 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112--- a/libdwfl/dwfl_error.c
113+++ b/libdwfl/dwfl_error.c
114@@ -140,6 +140,7 @@ __libdwfl_seterrno (Dwfl_Error error)
115 const char *
116 dwfl_errmsg (int error)
117 {
118+ static __thread char s[64] = "";
119 if (error == 0 || error == -1)
120 {
121 int last_error = global_error;
122@@ -154,7 +155,8 @@ dwfl_errmsg (int error)
123 switch (error &~ 0xffff)
124 {
125 case OTHER_ERROR (ERRNO):
126- return strerror_r (error & 0xffff, "bad", 0);
127+ strerror_r (error & 0xffff, s, sizeof(s));
128+ return s;
129 case OTHER_ERROR (LIBELF):
130 return elf_errmsg (error & 0xffff);
131 case OTHER_ERROR (LIBDW):
132diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300133index 56e6105..f4a0649 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500134--- a/libdwfl/dwfl_module_getdwarf.c
135+++ b/libdwfl/dwfl_module_getdwarf.c
136@@ -35,6 +35,7 @@
137 #include <fcntl.h>
138 #include <string.h>
139 #include <unistd.h>
140+#include "system.h"
141 #include "../libdw/libdwP.h" /* DWARF_E_* values are here. */
142 #include "../libelf/libelfP.h"
143 #include "system.h"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144diff --git a/libdwfl/libdwfl_crc32_file.c b/libdwfl/libdwfl_crc32_file.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800145index f849128..6f0aca1 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500146--- a/libdwfl/libdwfl_crc32_file.c
147+++ b/libdwfl/libdwfl_crc32_file.c
148@@ -29,6 +29,15 @@
149 # include <config.h>
150 #endif
151
152+#ifndef TEMP_FAILURE_RETRY
153+#define TEMP_FAILURE_RETRY(expression) \
154+ (__extension__ \
155+ ({ long int __result; \
156+ do __result = (long int) (expression); \
157+ while (__result == -1L && errno == EINTR); \
158+ __result; }))
159+#endif
160+
161 #define crc32_file attribute_hidden __libdwfl_crc32_file
162 #define crc32 __libdwfl_crc32
163 #include <libdwflP.h>
164diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300165index 360e4ee..b5aa397 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500166--- a/libdwfl/linux-kernel-modules.c
167+++ b/libdwfl/linux-kernel-modules.c
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300168@@ -41,6 +41,7 @@
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500169
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300170 #include "libelfP.h"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500171 #include "libdwflP.h"
172+#include "system.h"
173 #include <inttypes.h>
174 #include <errno.h>
175 #include <stdio.h>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500176diff --git a/libelf/elf.h b/libelf/elf.h
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800177index 5dc632b..14da1b7 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500178--- a/libelf/elf.h
179+++ b/libelf/elf.h
180@@ -21,7 +21,9 @@
181
182 #include <features.h>
183
184-__BEGIN_DECLS
185+#ifdef __cplusplus
186+extern "C" {
187+#endif
188
189 /* Standard ELF types. */
190
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800191@@ -3937,6 +3939,8 @@ enum
192 #define R_METAG_TLS_LE_HI16 60
193 #define R_METAG_TLS_LE_LO16 61
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500194
195-__END_DECLS
196+#ifdef __cplusplus
197+}
198+#endif
199
200 #endif /* elf.h */
201diff --git a/libelf/libelf.h b/libelf/libelf.h
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300202index 1ff11c9..c21e018 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500203--- a/libelf/libelf.h
204+++ b/libelf/libelf.h
205@@ -29,6 +29,7 @@
206 #ifndef _LIBELF_H
207 #define _LIBELF_H 1
208
209+#include <fcntl.h>
210 #include <stdint.h>
211 #include <sys/types.h>
212
213diff --git a/libelf/libelfP.h b/libelf/libelfP.h
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300214index 9f3e8e9..10a347a 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500215--- a/libelf/libelfP.h
216+++ b/libelf/libelfP.h
217@@ -32,6 +32,7 @@
218
219 #include <ar.h>
220 #include <gelf.h>
221+#include <libelf.h>
222
223 #include <errno.h>
224 #include <stdbool.h>