Skip to content

Commit 559ab7c

Browse files
libbacktrace: update to current version from GCC trunk
This adds DWARF 5 support as well as an enhanced testsuite. Patch assembled by Than McIntosh.
1 parent 5a99ff7 commit 559ab7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+17863
-3829
lines changed

Makefile.am

+264-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile.am -- Backtrace Makefile.
2-
# Copyright (C) 2012-2018 Free Software Foundation, Inc.
2+
# Copyright (C) 2012-2019 Free Software Foundation, Inc.
33

44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions are
@@ -31,6 +31,8 @@
3131

3232
ACLOCAL_AMFLAGS = -I config
3333

34+
AM_CPPFLAGS =
35+
3436
AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG)
3537

3638
include_HEADERS = backtrace.h backtrace-supported.h
@@ -83,77 +85,279 @@ libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
8385

8486
# Testsuite.
8587

88+
# Add test to this variable, if you want it to be build.
8689
check_PROGRAMS =
87-
CLEANFILES =
8890

89-
TESTS = $(check_PROGRAMS)
91+
# Add test to this variable, if you want it to be run.
92+
TESTS =
93+
94+
# Add test to this variable, if you want it to be build and run.
95+
BUILDTESTS =
9096

9197
if NATIVE
98+
check_LTLIBRARIES = libbacktrace_alloc.la
99+
100+
libbacktrace_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
101+
libbacktrace_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) read.lo alloc.lo
102+
103+
libbacktrace_alloc_la_DEPENDENCIES = $(libbacktrace_alloc_la_LIBADD)
104+
105+
check_LTLIBRARIES += libbacktrace_noformat.la
106+
107+
libbacktrace_noformat_la_SOURCES = $(libbacktrace_la_SOURCES)
108+
libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
109+
110+
libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
111+
112+
if HAVE_ELF
113+
if HAVE_OBJCOPY_DEBUGLINK
114+
115+
TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
116+
117+
check_LTLIBRARIES += libbacktrace_elf_for_test.la
118+
119+
libbacktrace_elf_for_test_la_SOURCES = $(libbacktrace_la_SOURCES)
120+
libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
121+
$(VIEW_FILE) $(ALLOC_FILE)
122+
123+
elf_for_test.c: elf.c
124+
SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \
125+
REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \
126+
$(SED) "s%$$SEARCH%$$REPLACE%" \
127+
$< \
128+
> $@.tmp
129+
mv $@.tmp $@
130+
131+
endif HAVE_OBJCOPY_DEBUGLINK
132+
endif HAVE_ELF
133+
134+
elf_%.c: elf.c
135+
SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
136+
REPLACE='#undef BACKTRACE_ELF_SIZE\
137+
#define BACKTRACE_ELF_SIZE'; \
138+
$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
139+
$< \
140+
> $@.tmp
141+
mv $@.tmp $@
142+
143+
xcoff_%.c: xcoff.c
144+
SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
145+
REPLACE='#undef BACKTRACE_XCOFF_SIZE\
146+
#define BACKTRACE_XCOFF_SIZE'; \
147+
$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
148+
$< \
149+
> $@.tmp
150+
mv $@.tmp $@
151+
152+
test_elf_32_SOURCES = test_format.c testlib.c
153+
test_elf_32_LDADD = libbacktrace_noformat.la elf_32.lo
154+
155+
BUILDTESTS += test_elf_32
156+
157+
test_elf_64_SOURCES = test_format.c testlib.c
158+
test_elf_64_LDADD = libbacktrace_noformat.la elf_64.lo
159+
160+
BUILDTESTS += test_elf_64
161+
162+
test_xcoff_32_SOURCES = test_format.c testlib.c
163+
test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
164+
165+
BUILDTESTS += test_xcoff_32
166+
167+
test_xcoff_64_SOURCES = test_format.c testlib.c
168+
test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
169+
170+
BUILDTESTS += test_xcoff_64
171+
172+
test_pecoff_SOURCES = test_format.c testlib.c
173+
test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
174+
175+
BUILDTESTS += test_pecoff
176+
177+
test_unknown_SOURCES = test_format.c testlib.c
178+
test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
179+
180+
BUILDTESTS += test_unknown
181+
182+
unittest_SOURCES = unittest.c testlib.c
183+
unittest_LDADD = libbacktrace.la
184+
185+
BUILDTESTS += unittest
186+
187+
unittest_alloc_SOURCES = $(unittest_SOURCES)
188+
unittest_alloc_LDADD = libbacktrace_alloc.la
189+
190+
BUILDTESTS += unittest_alloc
191+
192+
check_LTLIBRARIES += libbacktrace_instrumented_alloc.la
193+
194+
libbacktrace_instrumented_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
195+
libbacktrace_instrumented_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) \
196+
read.lo instrumented_alloc.lo
197+
198+
libbacktrace_instrumented_alloc_la_DEPENDENCIES = \
199+
$(libbacktrace_instrumented_alloc_la_LIBADD)
200+
201+
instrumented_alloc.lo: alloc.c
202+
203+
allocfail_SOURCES = allocfail.c testlib.c
204+
allocfail_LDADD = libbacktrace_instrumented_alloc.la
205+
206+
check_PROGRAMS += allocfail
207+
208+
allocfail.sh: allocfail
209+
210+
TESTS += allocfail.sh
211+
212+
if HAVE_ELF
213+
if HAVE_OBJCOPY_DEBUGLINK
214+
215+
b2test_SOURCES = $(btest_SOURCES)
216+
b2test_CFLAGS = $(btest_CFLAGS)
217+
b2test_LDFLAGS = -Wl,--build-id
218+
b2test_LDADD = libbacktrace_elf_for_test.la
219+
220+
check_PROGRAMS += b2test
221+
TESTS += b2test_buildid
222+
223+
if HAVE_DWZ
224+
225+
b3test_SOURCES = $(btest_SOURCES)
226+
b3test_CFLAGS = $(btest_CFLAGS)
227+
b3test_LDFLAGS = -Wl,--build-id
228+
b3test_LDADD = libbacktrace_elf_for_test.la
229+
230+
check_PROGRAMS += b3test
231+
TESTS += b3test_dwz_buildid
232+
233+
endif HAVE_DWZ
234+
235+
endif HAVE_OBJCOPY_DEBUGLINK
236+
endif HAVE_ELF
92237

93238
btest_SOURCES = btest.c testlib.c
94239
btest_CFLAGS = $(AM_CFLAGS) -g -O
95240
btest_LDADD = libbacktrace.la
96241

97-
check_PROGRAMS += btest
242+
BUILDTESTS += btest
243+
244+
if HAVE_ELF
245+
246+
btest_lto_SOURCES = btest.c testlib.c
247+
btest_lto_CFLAGS = $(AM_CFLAGS) -g -O -flto
248+
btest_lto_LDADD = libbacktrace.la
249+
250+
BUILDTESTS += btest_lto
251+
252+
endif HAVE_ELF
253+
254+
btest_alloc_SOURCES = $(btest_SOURCES)
255+
btest_alloc_CFLAGS = $(btest_CFLAGS)
256+
btest_alloc_LDADD = libbacktrace_alloc.la
257+
258+
BUILDTESTS += btest_alloc
259+
260+
if HAVE_DWZ
98261

99-
btest_static_SOURCES = btest.c testlib.c
100-
btest_static_CFLAGS = $(AM_CFLAGS) -g -O
101-
btest_static_LDADD = libbacktrace.la
102-
btest_static_LDFLAGS = -static-libtool-libs
262+
%_dwz: %
263+
rm -f $@ $@_common.debug
264+
cp $< $@_1
265+
cp $< $@_2
266+
$(DWZ) -m $@_common.debug $@_1 $@_2
267+
rm -f $@_2
268+
mv $@_1 $@
103269

104-
check_PROGRAMS += btest_static
270+
TESTS += btest_dwz
271+
272+
if HAVE_OBJCOPY_DEBUGLINK
273+
274+
TESTS += btest_dwz_gnudebuglink
275+
276+
endif HAVE_OBJCOPY_DEBUGLINK
277+
278+
endif HAVE_DWZ
105279

106280
stest_SOURCES = stest.c
107281
stest_LDADD = libbacktrace.la
108282

109-
check_PROGRAMS += stest
283+
BUILDTESTS += stest
284+
285+
stest_alloc_SOURCES = $(stest_SOURCES)
286+
stest_alloc_LDADD = libbacktrace_alloc.la
287+
288+
BUILDTESTS += stest_alloc
289+
290+
if HAVE_ELF
110291

111292
ztest_SOURCES = ztest.c testlib.c
112293
ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\"
113294
ztest_LDADD = libbacktrace.la
295+
ztest_alloc_LDADD = libbacktrace_alloc.la
114296

115297
if HAVE_ZLIB
116298
ztest_LDADD += -lz
299+
ztest_alloc_LDADD += -lz
117300
endif
118301
ztest_LDADD += $(CLOCK_GETTIME_LINK)
302+
ztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
303+
304+
BUILDTESTS += ztest
305+
306+
ztest_alloc_SOURCES = $(ztest_SOURCES)
307+
ztest_alloc_CFLAGS = $(ztest_CFLAGS)
119308

120-
check_PROGRAMS += ztest
309+
BUILDTESTS += ztest_alloc
310+
311+
endif HAVE_ELF
121312

122313
edtest_SOURCES = edtest.c edtest2_build.c testlib.c
123314
edtest_LDADD = libbacktrace.la
124315

125-
check_PROGRAMS += edtest
316+
BUILDTESTS += edtest
317+
318+
edtest_alloc_SOURCES = $(edtest_SOURCES)
319+
edtest_alloc_LDADD = libbacktrace_alloc.la
320+
321+
BUILDTESTS += edtest_alloc
126322

127323
edtest2_build.c: gen_edtest2_build; @true
128324
gen_edtest2_build: $(srcdir)/edtest2.c
129325
cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
130326
$(SHELL) $(srcdir)/move-if-change tmp-edtest2_build.c edtest2_build.c
131327
echo timestamp > $@
132328

133-
CLEANFILES += edtest2_build.c gen_edtest2_build
134-
135329
if HAVE_PTHREAD
136330

137-
check_PROGRAMS += ttest
331+
BUILDTESTS += ttest
138332

139333
ttest_SOURCES = ttest.c testlib.c
140334
ttest_CFLAGS = $(AM_CFLAGS) -pthread
141335
ttest_LDADD = libbacktrace.la
142336

337+
BUILDTESTS += ttest_alloc
338+
339+
ttest_alloc_SOURCES = $(ttest_SOURCES)
340+
ttest_alloc_CFLAGS = $(ttest_CFLAGS)
341+
ttest_alloc_LDADD = libbacktrace_alloc.la
342+
143343
endif HAVE_PTHREAD
144344

145345
if HAVE_OBJCOPY_DEBUGLINK
146346

147-
TESTS += dtest
347+
TESTS += btest_gnudebuglink
148348

149-
dtest: btest_static
150-
$(OBJCOPY) --only-keep-debug btest_static btest.debug
151-
$(OBJCOPY) --strip-debug --add-gnu-debuglink=btest.debug btest_static dtest
152-
153-
CLEANFILES += dtest btest.debug
349+
%_gnudebuglink: %
350+
$(OBJCOPY) --only-keep-debug $< $@.debug
351+
$(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
154352

155353
endif HAVE_OBJCOPY_DEBUGLINK
156354

355+
%_buildid: %
356+
./install-debuginfo-for-buildid.sh \
357+
"$(TEST_BUILD_ID_DIR)" \
358+
$<
359+
$(OBJCOPY) --strip-debug $< $@
360+
157361
if HAVE_COMPRESSED_DEBUG
158362

159363
ctestg_SOURCES = btest.c testlib.c
@@ -166,12 +370,49 @@ ctesta_CFLAGS = $(AM_CFLAGS) -g
166370
ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
167371
ctesta_LDADD = libbacktrace.la
168372

169-
check_PROGRAMS += ctestg ctesta
373+
BUILDTESTS += ctestg ctesta
374+
375+
ctestg_alloc_SOURCES = $(ctestg_SOURCES)
376+
ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
377+
ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)
378+
ctestg_alloc_LDADD = libbacktrace_alloc.la
379+
380+
ctesta_alloc_SOURCES = $(ctesta_SOURCES)
381+
ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
382+
ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS)
383+
ctesta_alloc_LDADD = libbacktrace_alloc.la
384+
385+
BUILDTESTS += ctestg_alloc ctesta_alloc
386+
387+
endif
388+
389+
if HAVE_DWARF5
390+
391+
dwarf5_SOURCES = btest.c testlib.c
392+
dwarf5_CFLAGS = $(AM_CFLAGS) -gdwarf-5
393+
dwarf5_LDADD = libbacktrace.la
394+
395+
BUILDTESTS += dwarf5
396+
397+
dwarf5_alloc_SOURCES = $(dwarf5_SOURCES)
398+
dwarf5_alloc_CFLAGS = $(dwarf5_CFLAGS)
399+
dwarf5_alloc_LDADD = libbacktrace_alloc.la
400+
401+
BUILDTESTS += dwarf5_alloc
170402

171403
endif
172404

173405
endif NATIVE
174406

407+
check_PROGRAMS += $(BUILDTESTS)
408+
409+
TESTS += $(BUILDTESTS)
410+
411+
CLEANFILES = $(TESTS) *.debug elf_for_test.c edtest2_build.c gen_edtest2_build
412+
413+
clean-local:
414+
-rm -rf usr
415+
175416
# We can't use automake's automatic dependency tracking, because it
176417
# breaks when using bootstrap-lean. Automatic dependency tracking
177418
# with GCC bootstrap will cause some of the objects to depend on
@@ -186,7 +427,7 @@ endif NATIVE
186427

187428
alloc.lo: config.h backtrace.h internal.h
188429
backtrace.lo: config.h backtrace.h internal.h
189-
btest.lo: backtrace.h backtrace-supported.h filenames.h
430+
btest.lo: filenames.h backtrace.h backtrace-supported.h
190431
dwarf.lo: config.h filenames.h backtrace.h internal.h
191432
elf.lo: config.h backtrace.h internal.h
192433
fileline.lo: config.h backtrace.h internal.h

0 commit comments

Comments
 (0)