mirror of
https://github.com/sstefani/mtrace.git
synced 2025-12-06 16:56:41 +08:00
Fix compilation issue with newer binutils
- Fixes for binutuils 2.31 / 2.34 - Fix CMake fails to error out if libbfd is not found. - Fix conditiopnal linking if libbfd is not available. (e.g for client mode)
This commit is contained in:
parent
6f097d37e6
commit
c38415317c
@ -115,9 +115,11 @@ if (NOT DISABLE_CLIENT)
|
|||||||
|
|
||||||
find_and_test_library(LIB_READLINE readline "stdio.h;readline/readline.h" "rl_callback_read_char")
|
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}")
|
set(CMAKE_REQUIRED_DEFINITIONS "-DPACKAGE_VERSION=${MT_VERSION_STRING} -DPACKAGE=1")
|
||||||
find_and_test_library(LIB_BFD bfd "bfd.h" "bfd_openr")
|
find_library(LIB_BFD bfd)
|
||||||
unset(CMAKE_REQUIRED_DEFINITIONS)
|
if(NOT LIB_BFD)
|
||||||
|
message(FATAL_ERROR "libbfd not found.")
|
||||||
|
endif()
|
||||||
|
|
||||||
CHECK_INCLUDE_FILES_ERROR("termcap.h" HAVE_TERMCAP_H)
|
CHECK_INCLUDE_FILES_ERROR("termcap.h" HAVE_TERMCAP_H)
|
||||||
|
|
||||||
@ -138,7 +140,10 @@ if (LIB_ELF_INCLUDE_DIRS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(${MT} ${C_SRCS})
|
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_link_libraries(${MT} ${LIB_BFD})
|
||||||
|
endif()
|
||||||
target_compile_options(${MT} PUBLIC ${LIB_ELF_CFLAGS_OTHER})
|
target_compile_options(${MT} PUBLIC ${LIB_ELF_CFLAGS_OTHER})
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
|
install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
|
||||||
|
|||||||
@ -28,6 +28,20 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <libiberty/demangle.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 "binfile.h"
|
||||||
#include "process.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)
|
if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vma = bfd_get_section_vma(abfd, section);
|
vma = bfd_section_vma_wrapper(abfd, section);
|
||||||
if (psi->pc < vma)
|
if (psi->pc < vma)
|
||||||
return;
|
return;
|
||||||
size = bfd_section_size(abfd, section);
|
size = bfd_section_size_wrapper(abfd, section);
|
||||||
if (psi->pc >= vma + size)
|
if (psi->pc >= vma + size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user