[PATCH - RFC] WIP: fix backtrace test to work on musl

Mark Wielaard mark@klomp.org
Fri Feb 12 19:05:40 GMT 2021


Hi Érico,

On Mon, 2021-02-08 at 20:37 -0300, Érico Nogueira via Elfutils-devel
wrote:
> Currently, the run-backtrace-native.sh test fails on musl systems. As
> seen here in the test suite log, this appears to happen because
> elfutils
> expects raise() to be the last function in the stack trace, which it
> isn't, because unlike glibc, which uses inline functions for setting
> and
> resetting the signal mask, musl chose to use a normal function.

I think the testcase is way to specific indeed.
It would good if it only checked some main symbol/frame names were in
the backtrace. Maybe it should just check if the "raise", "main" and
"_start" symbols appear in the backtrace in that order for the main
thread, and "raise", "sigusr2", "stdarg", "bakctracegen" and "start"?

I haven't really looked at the testcase too closely to know whether
that is too simplistic.

> 0x5572f0661000	0x5572f0666000	/builddir/elfutils-
> 0.183/tests/backtrace-child
> 0x7ff1dac68000	0x7ff1dad15000	/usr/lib/libc.so
> 0x7fff70fc1000	0x7fff70fc2000	[vdso: 10694]
> TID 10694:
> # 0 0x7ff1dacbe3e7    	__restore_sigs
> # 1 0x7ff1dacbe590 - 1	raise
> # 2 0x5572f0662240 - 1	main
> # 3 0x7ff1dac866fa - 1	libc_start_main_stage2
> # 4 0x5572f0662329 - 1	_start
> TID 10697:
> # 0 0x7ff1dacbe3e7    	__restore_sigs
> frameno: 0 symname: __restore_sigs
> # 1 0x7ff1dacbe590 - 1	raise
> frameno: 0 symname: raise
> # 2 0x5572f066251b - 1	sigusr2
> frameno: 1 symname: sigusr2
> # 3 0x5572f06625bc - 1	stdarg
> frameno: 4 symname: stdarg
> # 4 0x5572f06625e2 - 1	backtracegen
> frameno: 5 symname: backtracegen
> # 5 0x5572f06625fb - 1	start
> frameno: 6 symname: start
> # 6 0x7ff1daccf7ee - 1	start
> frameno: 7 symname: start
> # 7 0x7ff1dacdc91b - 1	__clone
> frameno: 8 symname: __clone
> # 8 0x7ff1dacdc91b - 1	__clone
> frameno: 9 symname: __clone
> # 9 0x7ff1dacdc91b - 1	__clone
> frameno: 10 symname: __clone
> #10 0x7ff1dacdc91b - 1	__clone
> frameno: 11 symname: __clone
> #11 0x7ff1dacdc91b - 1	__clone
> frameno: 12 symname: __clone
> #12 0x7ff1dacdc91b - 1	__clone
> frameno: 13 symname: __clone
> #13 0x7ff1dacdc91b - 1	__clone
> frameno: 14 symname: __clone
> #14 0x7ff1dacdc91b - 1	__clone
> frameno: 15 symname: __clone
> #15 0x7ff1dacdc91b - 1	__clone
> frameno: 16 symname: __clone
> #16 0x7ff1dacdc91b - 1	__clone
> frameno: 17 symname: __clone
> /builddir/elfutils-0.183/tests/backtrace: dwfl_thread_getframes: no
> matching address range
> /builddir/elfutils-0.183/tests/backtrace: Too many frames: 17

BTW. Here I think another issue is the __clone isn't recognized as
terminating (starting?) frame. That might be a bug in musl CFI
decorating of the __clone function. It should explicitly mark that
function as terminating the call stack.

> I have also thought about looping through stack frames until symname is
> "raise", since other libcs (and possibly even glibc?) could one day add
> a function call inside raise(), which would break this test. What do you
> think of that solution?

I think that is a better approach.

Cheers,

Mark


More information about the Elfutils-devel mailing list