This is an archive of the discontinued LLVM Phabricator instance.

Fix detection of backtrace() availability on FreeBSD
ClosedPublic

Authored by arichardson on Nov 26 2016, 4:04 PM.

Details

Summary

On FreeBSD backtrace is not part of libc and depends on libexecinfo being
available. Instead of using manual checks we can use the builtin CMake
module FindBacktrace.cmake to detect availability of backtrace() in a
portable way.

Event Timeline

arichardson retitled this revision from to Reenable backtraces on FreeBSD.
arichardson updated this object.
arichardson added a reviewer: theraven.
arichardson set the repository for this revision to rL LLVM.Dec 16 2016, 6:11 AM
arichardson added a subscriber: llvm-commits.
arichardson retitled this revision from Reenable backtraces on FreeBSD to Reenable crash backtraces on FreeBSD.
arichardson edited the summary of this revision. (Show Details)
arichardson added a reviewer: dim.
dim accepted this revision.Mar 27 2017, 12:44 PM

LGTM.

This revision is now accepted and ready to land.Mar 27 2017, 12:44 PM
emaste accepted this revision.Mar 29 2017, 7:46 AM

FYI I added libexecinfo before FreeBSD 10 so all supported FreeBSD releases have it.

Does NetBSD need it too?

Backtrace seems to work for me..

(lldb) bt
* thread #1, stop reason = step over
  * frame #0: 0x00007816c08f3eaf libc.so.12`fopen(file="", mode="") at fopen.c:116
    frame #1: 0x0000000096e0b0d2 phantasia`main at main.c:317
    frame #2: 0x0000000096e0b047 phantasia`main(argc=1, argv=0x00007f7fff162b48) at main.c:95
    frame #3: 0x0000000096e0203b phantasia`___start + 229
theraven edited edge metadata.Mar 30 2017, 3:20 AM

It's probably worth having Joerg look at this, as I believe a similar fix is needed on NetBSD.

krytarowski requested changes to this revision.Mar 30 2017, 8:04 AM

Right, it's no LLDB....

For detecting libexecinfo please go for: Backtrace_LIBRARY It will handle FreeBSD and NetBSD

This revision now requires changes to proceed.Mar 30 2017, 8:04 AM
arichardson edited edge metadata.
arichardson retitled this revision from Reenable crash backtraces on FreeBSD to Fix detection of backtrace() availability on FreeBSD.
arichardson edited the summary of this revision. (Show Details)

Use FindBacktrace.cmake instead

Thanks, I'm going to test it.

I noticed that the backtraces are not particularly useful on FreeBSD, they always look like this (even when I disable sigaltstack()):

#0 0x000000080183d35c llvm::sys::PrintStackTrace(llvm::raw_ostream&) /exports/users/alr48/sources/llvm-upstream/lib/Support/Unix/Signals.inc:399:11
#1 0x000000080183d799 PrintStackTraceSignalHandler(void*) /exports/users/alr48/sources/llvm-upstream/lib/Support/Unix/Signals.inc:463:1
#2 0x000000080183a797 llvm::sys::RunSignalHandlers(void) /exports/users/alr48/sources/llvm-upstream/lib/Support/Signals.cpp:45:5
#3 0x000000080183da0a SignalHandler(int) /exports/users/alr48/sources/llvm-upstream/lib/Support/Unix/Signals.inc:253:1
#4 0x0000000801aa778f (/lib/libthr.so.3+0xe78f)
#5 0x0000000801aa6d6f (/lib/libthr.so.3+0xdd6f)

I hacked around this issue by printing the stacktrace prior to calling abort but there must be a better solution.

krytarowski accepted this revision.Mar 30 2017, 10:52 AM

Build for me:

NetBSD chieftec 7.99.66 NetBSD 7.99.66 (GENERIC) #6: Wed Mar 29 21:21:19 CEST 2017  root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC amd64
$ grep  -i backtrace CMakeCache.txt    
//Header providing backtrace(3) facility
Backtrace_HEADER:STRING=execinfo.h
Backtrace_INCLUDE_DIR:PATH=/usr/include
Backtrace_LIBRARY:FILEPATH=/usr/lib/libexecinfo.so
//Enable embedding backtraces on crash.
LLVM_ENABLE_BACKTRACES:BOOL=ON
//ADVANCED property for variable: Backtrace_HEADER
Backtrace_HEADER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: Backtrace_INCLUDE_DIR
Backtrace_INCLUDE_DIR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: Backtrace_LIBRARY
Backtrace_LIBRARY-ADVANCED:INTERNAL=1
//Details about finding Backtrace
FIND_PACKAGE_MESSAGE_DETAILS_Backtrace:INTERNAL=[/usr/lib/libexecinfo.so][/usr/include][v()]
//Have symbol _Unwind_Backtrace
HAVE__UNWIND_BACKTRACE:INTERNAL=1
//Have symbol backtrace
_Backtrace_SYM_FOUND:INTERNAL=
This revision is now accepted and ready to land.Mar 30 2017, 10:52 AM

I don't have commit access, could someone commit for me?

This revision was automatically updated to reflect the committed changes.