Skip to content

Commit

Permalink
Add -fno-semantic-interposition (#360)
Browse files Browse the repository at this point in the history
"-fno-semantic-interposition" allows the compiler to inline code within
a compilation unit even with "-fPIC".
Also make all symbols hidden by default amd use "-Bsymbolic-functions"
(this is probably redudant with -fno-semantic-interposition but should
not hurt).

cf. https://maskray.me/blog/2021-05-16-elf-interposition-and-bsymbolic
cf. https://maskray.me/blog/2021-05-09-fno-semantic-interposition
  • Loading branch information
nsavoire authored Jan 18, 2024
1 parent 1daa692 commit 37106ee
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ target_static_libcxx(dd_profiling-embedded)
target_static_sanitizer(dd_profiling-embedded)
set_target_properties(dd_profiling-embedded PROPERTIES LINK_DEPENDS "${dd_profiling_linker_script}")
target_link_options(dd_profiling-embedded PRIVATE
"LINKER:--version-script=${dd_profiling_linker_script}")
"LINKER:--version-script=${dd_profiling_linker_script};LINKER:-Bsymbolic")
if(BUILD_UNIVERSAL_DDPROF)
target_link_options(dd_profiling-embedded PRIVATE "-nolibc")
if(USE_AUXILIARY)
Expand Down Expand Up @@ -393,7 +393,7 @@ target_static_libcxx(dd_profiling-shared)
target_static_sanitizer(dd_profiling-shared)
set_target_properties(dd_profiling-shared PROPERTIES LINK_DEPENDS "${dd_profiling_linker_script}")
target_link_options(dd_profiling-shared PRIVATE
"LINKER:--version-script=${dd_profiling_linker_script}")
"LINKER:--version-script=${dd_profiling_linker_script};LINKER:-Bsymbolic")

set_target_properties(dd_profiling-shared PROPERTIES OUTPUT_NAME dd_profiling)
target_include_directories(dd_profiling-shared PUBLIC ${CMAKE_SOURCE_DIR}/include/lib
Expand Down
2 changes: 1 addition & 1 deletion cmake/ExtendBuildTypes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 11)

add_compile_options(-Wall -g)
add_compile_options(-Wall -g -fno-semantic-interposition -fvisibility=hidden)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
Expand Down
1 change: 1 addition & 0 deletions include/ddprof_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define DDPROF_ALWAYS_INLINE __attribute__((always_inline))
#define DDPROF_NO_SANITIZER_ADDRESS __attribute__((no_sanitize("address")))
#define DDPROF_WEAK __attribute__((weak))
#define DDPROF_EXPORT __attribute__((__visibility__("default")))

#if defined(__clang__)
# define DDPROF_NOIPO __attribute__((noinline))
Expand Down
5 changes: 3 additions & 2 deletions include/lib/dd_profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
extern "C" {
#endif

int ddprof_start_profiling();
void ddprof_stop_profiling(int timeout_ms);
__attribute__((__visibility__("default"))) int ddprof_start_profiling();
__attribute__((__visibility__("default"))) void
ddprof_stop_profiling(int timeout_ms);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion test/simple_malloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ extern "C" DDPROF_NOINLINE void recursive_call(const Options &options,
DDPROF_BLOCK_TAIL_CALL_OPTIMIZATION();
}

extern "C" DDPROF_NOINLINE void wrapper(const Options &options, Stats &stats) {
extern "C" DDPROF_EXPORT DDPROF_NOINLINE void wrapper(const Options &options,
Stats &stats) {
recursive_call(options, stats, options.callstack_depth);
}
// NOLINTEND(clang-analyzer-unix.Malloc)
Expand Down

0 comments on commit 37106ee

Please sign in to comment.