Skip to content

Commit

Permalink
Updating binutils support to work with modern compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Feb 19, 2024
1 parent 8a7403e commit c9d2c29
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmake/Modules/FindBFD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ if((APEX_BUILD_BFD OR (NOT BFD_FOUND)) AND NOT APPLE)
set(TMP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(TMP_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC")
ExternalProject_Add(project_binutils
URL "http://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.bz2"
URL_HASH SHA256=67fc1a4030d08ee877a4867d3dcab35828148f87e1fd05da6db585ed5a166bd4
URL "http://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.bz2"
URL_HASH SHA256=5d2a6c1d49686a557869caae08b6c2e83699775efd27505e01b2f4db1a024ffc
CONFIGURE_COMMAND <SOURCE_DIR>/configure CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} CFLAGS=${TMP_C_FLAGS} CXXFLAGS=${TMP_CXX_FLAGS} LDFLAGS=${TMP_LINKER_FLAGS} --prefix=${CMAKE_INSTALL_PREFIX} --disable-dependency-tracking --enable-interwork --disable-multilib --enable-shared --enable-64-bit-bfd --target=${TARGET_ARCH} --enable-install-libiberty --disable-gold --program-prefix=g --disable-nls --disable-ld --disable-lto --disable-gas
BUILD_COMMAND make MAKEINFO=true -j${MAKEJOBS}
INSTALL_COMMAND make MAKEINFO=true install
Expand Down
7 changes: 2 additions & 5 deletions src/apex/apex_bfd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
#define PACKAGE_VERSION
#endif
#include <bfd.h>
#if APEX_BFD >= 022300
#include <elf-bfd.h>
#endif
#include <dirent.h>
#include <stdint.h>
#include <cctype>
Expand Down Expand Up @@ -135,7 +132,7 @@ struct ApexBfdModule
return (bfdOpen = false);
}

#if APEX_BFD >= 022200
#if defined(BFD_DECOMPRESS)
// Decompress sections
bfdImage->flags |= BFD_DECOMPRESS;
#endif
Expand Down Expand Up @@ -1025,7 +1022,7 @@ void Apex_bfd_internal_locateAddress(bfd * bfdptr,
// ApexBfdInfo fields without an extra copy. This also means
// that the pointers in ApexBfdInfo must never be deleted
// since they point directly into the module's BFD.
#if (APEX_BFD >= 022200)
#if defined(bfd_find_nearest_line_discriminator)
data.found = bfd_find_nearest_line_discriminator(bfdptr, section,
data.module->syms, (data.info.probeAddr - vma),
&data.info.filename, &data.info.funcname,
Expand Down
23 changes: 16 additions & 7 deletions src/unit_tests/C++/apex_malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@
#include "apex_api.hpp"

void bar(char* data) {
apex::scoped_timer(__func__);
apex::scoped_timer((uint64_t)&bar);
auto s = strlen(data);
std::cout << "Size: " << s << std::endl;
}

void test_malloc() {
apex::scoped_timer(__func__);
void test_leak(void) {
apex::scoped_timer((uint64_t)&test_leak);
auto foo = (char*)(malloc(42 * sizeof(char)));
memset(foo, 'a', 41);
foo[41] = 0;
bar(foo);
}

void test_malloc(void) {
apex::scoped_timer((uint64_t)&test_malloc);
auto foo = (char*)(malloc(42 * sizeof(char)));
memset(foo, 'a', 41);
foo[41] = 0;
bar(foo);
free(foo);
}

void test_calloc() {
apex::scoped_timer(__func__);
void test_calloc(void) {
apex::scoped_timer((uint64_t)&test_calloc);
auto foo = (char*)(calloc(42, sizeof(char)));
memset(foo, 'a', 41);
bar(foo);
free(foo);
}

void test_realloc() {
apex::scoped_timer(__func__);
void test_realloc(void) {
apex::scoped_timer((uint64_t)&test_realloc);
auto foo = (char*)(malloc(42 * sizeof(char)));
memset(foo, 'a', 41);
foo[41] = 0;
Expand All @@ -42,6 +50,7 @@ void test_all(void) {
test_malloc();
test_calloc();
test_realloc();
test_leak();
}

void apex_enable_memory_wrapper(void);
Expand Down

0 comments on commit c9d2c29

Please sign in to comment.