Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMake/HPHPFindLibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ endif()

if (LINUX)
find_package(Bpf REQUIRED)
find_package(LibUnwind REQUIRED)
endif()

# This is required by Homebrew's libc. See
Expand Down Expand Up @@ -427,6 +428,10 @@ macro(hphp_link target)
target_link_libraries(${target} ${VISIBILITY} afdt)
target_link_libraries(${target} ${VISIBILITY} mbfl)

if (LINUX)
target_link_libraries(${target} ${VISIBILITY} ${LIBUNWIND_LIBRARIES})
endif()

if (EDITLINE_LIBRARIES)
target_link_libraries(${target} ${VISIBILITY} ${EDITLINE_LIBRARIES})
elseif (READLINE_LIBRARY)
Expand Down
3 changes: 2 additions & 1 deletion build/fbcode_builder/CMake/FindLibUnwind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

find_path(LIBUNWIND_INCLUDE_DIR NAMES libunwind.h)
# When using prepackaged LLVM libunwind on Ubuntu, its includes are installed in a subdirectory.
find_path(LIBUNWIND_INCLUDE_DIR NAMES libunwind.h PATH_SUFFIXES libunwind)
mark_as_advanced(LIBUNWIND_INCLUDE_DIR)

find_library(LIBUNWIND_LIBRARY NAMES unwind)
Expand Down
57 changes: 1 addition & 56 deletions hphp/runtime/vm/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@
#include <stdio.h>
#include <string.h>

#if defined USE_FOLLY_SYMBOLIZER

#include <folly/experimental/symbolizer/Symbolizer.h>

#elif defined HAVE_LIBBFD

#include <bfd.h>

#endif
#include <folly/debugging/symbolizer/Symbolizer.h>

#include <folly/portability/Unistd.h>
#include <folly/Demangle.h>
Expand Down Expand Up @@ -115,8 +107,6 @@ void DebugInfo::generatePidMapOverlay() {
};
std::vector<SymInfo> sorted;

#if defined USE_FOLLY_SYMBOLIZER

auto self = current_executable_path();
using folly::symbolizer::ElfFile;
ElfFile file;
Expand All @@ -141,51 +131,6 @@ void DebugInfo::generatePidMapOverlay() {
return false;
});

#elif defined HAVE_LIBBFD

auto self = current_executable_path();
bfd* abfd = bfd_openr(self.c_str(), nullptr);
#ifdef BFD_DECOMPRESS
abfd->flags |= BFD_DECOMPRESS;
#endif
SCOPE_EXIT { bfd_close(abfd); };
char **match = nullptr;
if (bfd_check_format(abfd, bfd_archive) ||
!bfd_check_format_matches(abfd, bfd_object, &match)) {
return;
}

long storage_needed = bfd_get_symtab_upper_bound (abfd);

if (storage_needed <= 0) return;

auto symbol_table = (asymbol**)malloc(storage_needed);

SCOPE_EXIT { free(symbol_table); free(match); };

long number_of_symbols = bfd_canonicalize_symtab(abfd, symbol_table);

for (long i = 0; i < number_of_symbols; i++) {
auto sym = symbol_table[i];
if (sym->flags &
(BSF_INDIRECT |
BSF_SECTION_SYM |
BSF_FILE |
BSF_DEBUGGING_RELOC |
BSF_OBJECT)) {
continue;
}
auto sec = sym->section;
if (!(sec->flags & (SEC_ALLOC|SEC_LOAD|SEC_CODE))) continue;
auto addr = sec->vma + sym->value;
if (addr < uintptr_t(pidMapOverlayStart) ||
addr >= uintptr_t(pidMapOverlayEnd)) {
continue;
}
sorted.push_back(SymInfo{sym->name, addr, 0});
}
#endif // HAVE_LIBBFD

std::sort(
sorted.begin(), sorted.end(),
[](const SymInfo& a, const SymInfo& b) {
Expand Down
7 changes: 0 additions & 7 deletions hphp/util/portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,6 @@

//////////////////////////////////////////////////////////////////////

#ifdef HHVM_FACEBOOK
#define USE_FOLLY_SYMBOLIZER 1
// Linking in libbfd is a gigantic PITA, but if folly symbolizer doesn't
// work on your platform, you'll need to figure it out.
#define HAVE_LIBBFD 1
#endif

#ifndef PACKAGE
// The value doesn't matter, but it must be defined before you include
// bfd.h
Expand Down
Loading