Skip to content

Commit

Permalink
Fix builds against libbfd(binutils) >=2.39
Browse files Browse the repository at this point in the history
Binutils 2.39 changed signature of the init_disassemble_info function by
adding an extra parameter for styled printf function. Let CMake detect
which of the versions is present and call it appropriately.
  • Loading branch information
viktormalik authored and danobi committed Aug 16, 2022
1 parent 1c6687e commit 0fba258
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -41,6 +41,8 @@ and this project adheres to
- [#2313](https://github.com/iovisor/bpftrace/pull/2313)
- Fix invalid LLVM IR as detected by tests
- [#2316](https://github.com/iovisor/bpftrace/pull/2316)
- Fix builds against libbfd(binutils) >=2.39
- [#2328](https://github.com/iovisor/bpftrace/pull/2328)

#### Added
#### Docs
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -249,6 +249,9 @@ if(HAVE_BFD_DISASM)
if(LIBBFD_DISASM_FOUR_ARGS_SIGNATURE)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" LIBBFD_DISASM_FOUR_ARGS_SIGNATURE)
endif(LIBBFD_DISASM_FOUR_ARGS_SIGNATURE)
if(LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE)
set(BPFTRACE_FLAGS "${BPFTRACE_FLAGS}" LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE)
endif(LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE)
endif(HAVE_BFD_DISASM)

if (LIBBPF_BTF_DUMP_FOUND)
Expand Down
10 changes: 10 additions & 0 deletions cmake/FindLibBfd.cmake
Expand Up @@ -75,5 +75,15 @@ int main(void) {
abfd);
return 0;
}" LIBBFD_DISASM_FOUR_ARGS_SIGNATURE)
CHECK_CXX_SOURCE_COMPILES("
// See comment in bfd-disasm.cpp for why this needs to exist
#define PACKAGE \"bpftrace-test\"
#include <dis-asm.h>
int main(void) {
init_disassemble_info(NULL, NULL, NULL, NULL);
return 0;
}
" LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE)
SET(CMAKE_REQUIRED_LIBRARIES)
endif()
14 changes: 14 additions & 0 deletions src/bfd-disasm.cpp
Expand Up @@ -38,6 +38,16 @@ static int fprintf_nop(void *out __attribute__((unused)), const char *fmt __attr
return 0;
}

#ifdef LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE
static int fprintf_styled_nop(void *out __attribute__((unused)),
enum disassembler_style s __attribute__((unused)),
const char *fmt __attribute__((unused)),
...)
{
return 0;
}
#endif

static AlignState is_aligned_buf(void *buf, uint64_t size, uint64_t offset)
{
disassembler_ftype disassemble;
Expand All @@ -55,7 +65,11 @@ static AlignState is_aligned_buf(void *buf, uint64_t size, uint64_t offset)
return AlignState::Fail;
}

#ifdef LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE
init_disassemble_info(&info, stdout, fprintf_nop, fprintf_styled_nop);
#else
init_disassemble_info(&info, stdout, fprintf_nop);
#endif

info.arch = bfd_get_arch(bfdf);
info.mach = bfd_get_mach(bfdf);
Expand Down

0 comments on commit 0fba258

Please sign in to comment.