Skip to content

Commit 33c13cd

Browse files
Sterling-Augustinezmodem
authored andcommitted
Default to disabling the libunwind frameheader cache.
Although it works fine with glibc, as currently implemented the frameheader cache is incompatible with certain platforms with slightly different locking semantics inside dl_iterate_phdr. Therefore only enable it when it is turned on explicitly with a configure-time option. Differential Revision: https://reviews.llvm.org/D86163 (cherry picked from commit a20f5fe)
1 parent f2b2668 commit 33c13cd

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

libunwind/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
137137
option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF)
138138
option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
139139
option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS})
140+
option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
140141

141142
set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
142143
"Define suffix of library directory name (32/64)")
@@ -365,6 +366,10 @@ if (LIBUNWIND_ENABLE_ARM_WMMX)
365366
add_compile_flags(-D__ARM_WMMX)
366367
endif()
367368

369+
if(LIBUNWIND_USE_FRAME_HEADER_CACHE)
370+
add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
371+
endif()
372+
368373
# This is the _ONLY_ place where add_definitions is called.
369374
if (MSVC)
370375
add_definitions(-D_CRT_SECURE_NO_WARNINGS)

libunwind/src/AddressSpace.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,12 @@ struct _LIBUNWIND_HIDDEN dl_iterate_cb_data {
452452
#error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
453453
#endif
454454

455+
#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
455456
#include "FrameHeaderCache.hpp"
456457

457458
// There should be just one of these per process.
458459
static FrameHeaderCache ProcessFrameHeaderCache;
460+
#endif
459461

460462
static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base,
461463
dl_iterate_cb_data *cbdata) {
@@ -476,8 +478,10 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t pinfo_size,
476478
auto cbdata = static_cast<dl_iterate_cb_data *>(data);
477479
if (pinfo->dlpi_phnum == 0 || cbdata->targetAddr < pinfo->dlpi_addr)
478480
return 0;
481+
#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
479482
if (ProcessFrameHeaderCache.find(pinfo, pinfo_size, data))
480483
return 1;
484+
#endif
481485

482486
Elf_Addr image_base = calculateImageBase(pinfo);
483487
bool found_obj = false;
@@ -505,7 +509,9 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t pinfo_size,
505509
found_obj = checkAddrInSegment(phdr, image_base, cbdata);
506510
}
507511
if (found_obj && found_hdr) {
512+
#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
508513
ProcessFrameHeaderCache.add(cbdata->sects);
514+
#endif
509515
return 1;
510516
}
511517
}

libunwind/test/frameheadercache_test.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// The frame header cache should work fine for other architectures,
77
// but the #ifdefs end up being even more complicated than this.
88

9-
#ifdef __x86_64__
9+
#if defined(__x86_64__) && defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
1010

1111
// This #if chain is ugly, but see the comments in AddressSpace.hpp for
1212
// the reasoning.

0 commit comments

Comments
 (0)