Merge pull request #4 from coldtobi/update-bfd

Fix compilation issue with newer binutils
This commit is contained in:
sstefani 2022-06-10 14:47:25 +02:00 committed by GitHub
commit 521b1a2bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -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/)

View File

@ -28,6 +28,20 @@
#include <string.h>
#include <libiberty/demangle.h>
#include <bfd.h>
/* 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;