Skip to content

Commit

Permalink
fix: add workaround to build on ubuntu 20.04 (#5)
Browse files Browse the repository at this point in the history
Signed-off-by: wep21 <daisuke.nishimatsu1021@gmail.com>
  • Loading branch information
wep21 committed Aug 11, 2023
1 parent ec260d7 commit 99c2628
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,25 @@ endif()

add_executable(app src/app.cpp)

include(CheckSymbolExists)
check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)

add_library(preloaded_heaptrack SHARED src/preloaded.cpp)
if(HAVE_MALLINFO2)
target_compile_definitions(preloaded_heaptrack
PRIVATE
HAVE_MALLINFO2
)
endif()

add_library(preloaded_tlsf SHARED src/preloaded_tlsf.cpp)
target_link_libraries(preloaded_tlsf PRIVATE tlsf::tlsf)
if(HAVE_MALLINFO2)
target_compile_definitions(preloaded_tlsf
PRIVATE
HAVE_MALLINFO2
)
endif()

install(TARGETS preloaded_heaptrack preloaded_tlsf DESTINATION lib)
install(TARGETS app DESTINATION bin)
Expand Down
2 changes: 2 additions & 0 deletions src/preloaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,15 @@ struct mallinfo mallinfo()
return orig();
}

#ifdef HAVE_MALLINFO2
using mallinfo2_type = struct mallinfo2 (*)( void);
struct mallinfo2 mallinfo2()
{
static mallinfo2_type orig = reinterpret_cast<mallinfo2_type>(dlsym(RTLD_NEXT, "mallinfo2"));
printf("hoge: mallinfo2 called\n");
return orig();
}
#endif

using mallopt_type = int (*)(int, int);
int mallopt(int param, int value)
Expand Down
2 changes: 2 additions & 0 deletions src/preloaded_tlsf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,15 @@ struct mallinfo mallinfo()
return orig();
}

#ifdef HAVE_MALLINFO2
using mallinfo2_type = struct mallinfo2 (*)( void);
struct mallinfo2 mallinfo2()
{
static mallinfo2_type orig = reinterpret_cast<mallinfo2_type>(dlsym(RTLD_NEXT, "mallinfo2"));
printf("hoge: mallinfo2 called\n");
return orig();
}
#endif

using mallopt_type = int (*)(int, int);
int mallopt(int param, int value)
Expand Down

0 comments on commit 99c2628

Please sign in to comment.