aboutsummaryrefslogtreecommitdiff
blob: 12dd516e3e62ee68db86c27b9f95fb161395d39a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2d23226..1798a96 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,35 @@ if (NOT HAVE_REALLOCARRAY_SUPPORT)
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOMPAT_NEED_REALLOCARRAY")
 endif()
 
+CHECK_C_SOURCE_COMPILES(
+"
+#include <obstack.h>
+int main(void)
+{
+        _obstack_begin(0, 0, 0, NULL, NULL);
+        return 0;
+}
+" LIBC_IMPLEMENTS_OBSTACK)
+if (NOT LIBC_IMPLEMENTS_OBSTACK)
+  find_package(OBSTACK)
+endif()
+
+CHECK_C_SOURCE_COMPILES(
+"
+#include <obstack.h>
+int main(void)
+{
+        int argc=1;
+        char *argv[]={\"argp\"};
+        argp_parse(0,argc,&argv,0,0,0); return 0;
+        return 0;
+}
+" LIBC_IMPLEMENTS_ARGP)
+
+if (NOT LIBC_IMPLEMENTS_ARGP)
+  find_package(ARGP)
+endif()
+
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64")
 
 file(GLOB libbpf_sources "lib/bpf/src/*.c")
@@ -91,7 +120,8 @@ set_target_properties(dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
 set_target_properties(dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "")
 target_include_directories(dwarves PRIVATE
 			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
-target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES})
+target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES}
+    ${ARGP_LIBRARY} ${OBSTACK_LIBRARY})
 
 set(dwarves_emit_LIB_SRCS dwarves_emit.c)
 add_library(dwarves_emit SHARED ${dwarves_emit_LIB_SRCS})
diff --git a/cmake/modules/FindARGP.cmake b/cmake/modules/FindARGP.cmake
new file mode 100644
index 0000000..aa7984f
--- /dev/null
+++ b/cmake/modules/FindARGP.cmake
@@ -0,0 +1,17 @@
+# - Find argp
+# If argp_parse is not implemented by libc find
+# a standalone version.
+
+message(STATUS "Checking availability of standalone argp library")
+
+find_path(ARGP_INCLUDE_DIR argp.h
+	/usr/include
+	/usr/local/include
+	/usr/include/libdwarf
+	~/usr/local/include
+)
+
+find_library(ARGP_LIBRARY
+	NAMES argp
+	PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 ~/usr/local/lib ~/usr/local/lib64
+)
diff --git a/cmake/modules/FindOBSTACK.cmake b/cmake/modules/FindOBSTACK.cmake
new file mode 100644
index 0000000..905fc4c
--- /dev/null
+++ b/cmake/modules/FindOBSTACK.cmake
@@ -0,0 +1,19 @@
+# - Find obstack
+# If obstack is not implemented by libc find
+# a standalone version.
+
+message(STATUS "Checking availability of standalone obstack library")
+
+INCLUDE(CheckLibraryExists)
+
+find_path(OBSTACK_INCLUDE_DIR obstack.h
+	/usr/include
+	/usr/local/include
+	/usr/include/libdwarf
+	~/usr/local/include
+)
+
+find_library(OBSTACK_LIBRARY
+	NAMES obstack
+	PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 ~/usr/local/lib ~/usr/local/lib64
+)
diff --git a/dtagnames.c b/dtagnames.c
index 0ffcbf7..1629fb3 100644
--- a/dtagnames.c
+++ b/dtagnames.c
@@ -14,9 +14,11 @@
 
 static void print_malloc_stats(void)
 {
+#ifdef __GLIBC__
 	struct mallinfo m = mallinfo();
 
 	fprintf(stderr, "size: %u\n", m.uordblks);
+#endif
 }
 
 static int class__tag_name(struct tag *tag, struct cu *cu __unused,
diff --git a/dutil.h b/dutil.h
index 0f5f74a..3d771c4 100644
--- a/dutil.h
+++ b/dutil.h
@@ -15,6 +15,7 @@
 #include <elf.h>
 #include <gelf.h>
 #include <asm/bitsperlong.h>
+#include <linux/stddef.h>
 #include "rbtree.h"
 
 #define BITS_PER_LONG __BITS_PER_LONG
diff --git a/dwarves.c b/dwarves.c
index eb7885f..a437761 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -14,6 +14,7 @@
 #include <fcntl.h>
 #include <fnmatch.h>
 #include <libelf.h>
+#include <limits.h>
 #include <search.h>
 #include <stdio.h>
 #include <stdarg.h>
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
index b8124a1..310631e 100644
--- a/dwarves_fprintf.c
+++ b/dwarves_fprintf.c
@@ -1910,7 +1910,11 @@ void cus__print_error_msg(const char *progname, const struct cus *cus,
 void dwarves__fprintf_init(uint16_t user_cacheline_size)
 {
 	if (user_cacheline_size == 0) {
+#ifdef __GLIBC__
 		long sys_cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+#else
+		long sys_cacheline_size = 0;
+#endif
 
 		if (sys_cacheline_size > 0)
 			cacheline_size = sys_cacheline_size;
diff --git a/dwarves_reorganize.c b/dwarves_reorganize.c
index bae5b6e..62616f3 100644
--- a/dwarves_reorganize.c
+++ b/dwarves_reorganize.c
@@ -10,6 +10,7 @@
 #include "list.h"
 #include "dwarves_reorganize.h"
 #include "dwarves.h"
+#include "dutil.h"
 
 static void class__recalc_holes(struct class *class)
 {
diff --git a/hash.h b/hash.h
index d3aa416..b1bd419 100644
--- a/hash.h
+++ b/hash.h
@@ -15,6 +15,7 @@
  */
 
 #include <stdint.h>
+#include <sys/reg.h>
 
 /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
 #define GOLDEN_RATIO_PRIME_32 0x9e370001UL
diff --git a/lib/bpf/src/libbpf.c b/lib/bpf/src/libbpf.c
index 514b1a5..b187734 100644
--- a/lib/bpf/src/libbpf.c
+++ b/lib/bpf/src/libbpf.c
@@ -32,6 +32,7 @@
 #include <linux/filter.h>
 #include <linux/list.h>
 #include <linux/limits.h>
+#include <linux/stddef.h>
 #include <linux/perf_event.h>
 #include <linux/ring_buffer.h>
 #include <linux/version.h>