diff --git a/CMakeLists.txt b/CMakeLists.txt index 48fb79d..47c998a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,9 +115,11 @@ if (NOT DISABLE_CLIENT) find_and_test_library(LIB_READLINE readline "stdio.h;readline/readline.h" "rl_callback_read_char") - set(CMAKE_REQUIRED_DEFINITIONS "-DPACKAGE_VERSION=${MT_VERSION_STRING}") - find_and_test_library(LIB_BFD bfd "bfd.h" "bfd_openr") - unset(CMAKE_REQUIRED_DEFINITIONS) + set(CMAKE_REQUIRED_DEFINITIONS "-DPACKAGE_VERSION=${MT_VERSION_STRING} -DPACKAGE=1") + find_library(LIB_BFD bfd) + if(NOT LIB_BFD) + message(FATAL_ERROR "libbfd not found.") + endif() CHECK_INCLUDE_FILES_ERROR("termcap.h" HAVE_TERMCAP_H) @@ -138,7 +140,11 @@ if (LIB_ELF_INCLUDE_DIRS) endif() add_executable(${MT} ${C_SRCS}) -target_link_libraries(${MT} ${LIB_ELF_LIBRARIES} ${LIB_PTHREAD} ${LIB_DL} ${LIB_RT} ${LIB_READLINE} ${LIB_BFD}) +target_link_libraries(${MT} ${LIB_ELF_LIBRARIES} ${LIB_PTHREAD} ${LIB_DL} ${LIB_RT} ${LIB_READLINE}) +if(LIB_BFD) + target_compile_options(${MT} PRIVATE -DPACKAGE) + target_link_libraries(${MT} ${LIB_BFD}) +endif() target_compile_options(${MT} PUBLIC ${LIB_ELF_CFLAGS_OTHER}) install(TARGETS ${PROJECT_NAME} DESTINATION bin/) diff --git a/client/binfile.c b/client/binfile.c index 3c56d2c..21b6251 100644 --- a/client/binfile.c +++ b/client/binfile.c @@ -28,6 +28,20 @@ #include #include +#include + +/* try to detect libfd version and set up wrapper accprdingly. */ +#ifdef bfd_get_section_flags +// 2.31 (and possibly earlier) has bfd_get_section_flags +#define bfd_section_size_wrapper(_ptr, _section) bfd_section_size(_ptr, _section) +#define bfd_section_vma_wrapper(_ptr, _section) bfd_section_vma(_ptr, _section) +#else +// works for 2.34 +#define bfd_get_section_flags(_unused, _section) bfd_section_flags(_section) +#define bfd_section_size_wrapper(_unused, _section) bfd_section_size(_section) +#define bfd_section_vma_wrapper(_unused, _section) bfd_section_vma(_section) +#endif + #include "binfile.h" #include "process.h" @@ -92,10 +106,10 @@ static void find_address_in_section(bfd *abfd, asection *section, void *data __a if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0) return; - vma = bfd_get_section_vma(abfd, section); + vma = bfd_section_vma_wrapper(abfd, section); if (psi->pc < vma) return; - size = bfd_section_size(abfd, section); + size = bfd_section_size_wrapper(abfd, section); if (psi->pc >= vma + size) return;