This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][Archer] Use dlsym rather than weak symbols for TSan annotations
ClosedPublic

Authored by protze.joachim on Jan 23 2023, 9:19 AM.

Details

Summary

This is to fix issues reported for Ubuntu and possibly other platforms:
https://github.com/llvm/llvm-project/issues/45290

The latest comment on this issue points out that using dlsym rather than the weak symbol approach to call TSan annotation functions fixes the issue for Ubuntu.

Diff Detail

Event Timeline

protze.joachim created this revision.Jan 23 2023, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 9:19 AM
protze.joachim requested review of this revision.Jan 23 2023, 9:19 AM

LG, assuming it fixes the problem and is not too much of a performance blow (the weak symbols will be resolved by the runtime loader, whereas we now do indirect function calls through pointers).

Out of curiosity (I came across this, but doesn't need to be addressed here): Is there a technical reason we implement RunningOnValgrind separately, not using the exact same dlsym infrastructure as for the TSan annotation?

Hahnfeld accepted this revision.Jan 24 2023, 12:55 AM
This revision is now accepted and ready to land.Jan 24 2023, 12:55 AM

Fix the special case handling for RunningOnValgrind pointed out by @Hahnfeld . We don't want to have output for a missing call, so it still has a separate macro.

Hahnfeld accepted this revision.Jan 24 2023, 6:10 AM

Thanks!

This breaks my build. It looks like CMAKE_DL_LIBS dependency is missing:

CMakeFiles/archer.dir/ompt-tsan.cpp.o: In function `ompt_start_tool':
ompt-tsan.cpp:(.text.ompt_start_tool+0x55): undefined reference to `dlsym'
CMakeFiles/archer.dir/ompt-tsan.cpp.o: In function `ompt_tsan_initialize(void (*(*)(char const*))(), int, ompt_data_t*)':
ompt-tsan.cpp:(.text._ZL20ompt_tsan_initializePFPFvvEPKcEiP11ompt_data_t+0x277): undefined reference to `dlsym'
ompt-tsan.cpp:(.text._ZL20ompt_tsan_initializePFPFvvEPKcEiP11ompt_data_t+0x295): undefined reference to `dlsym'
ompt-tsan.cpp:(.text._ZL20ompt_tsan_initializePFPFvvEPKcEiP11ompt_data_t+0x2b3): undefined reference to `dlsym'
ompt-tsan.cpp:(.text._ZL20ompt_tsan_initializePFPFvvEPKcEiP11ompt_data_t+0x2d1): undefined reference to `dlsym'
CMakeFiles/archer.dir/ompt-tsan.cpp.o:ompt-tsan.cpp:(.text._ZL20ompt_tsan_initializePFPFvvEPKcEiP11ompt_data_t+0x2ef): more undefined references to `dlsym' follow
collect2: error: ld returned 1 exit status

I reverted this to fix the buildbots. Please consider the following change to avoid the issue:

diff --git a/openmp/tools/archer/CMakeLists.txt b/openmp/tools/archer/CMakeLists.txt
index 85405af..46f38e2 100644
--- a/openmp/tools/archer/CMakeLists.txt
+++ b/openmp/tools/archer/CMakeLists.txt
@@ -12,6 +12,7 @@ if(LIBOMP_OMPT_SUPPORT)
   include_directories(${LIBOMP_INCLUDE_DIR})

   add_library(archer SHARED ompt-tsan.cpp)
+  target_link_libraries(archer ${CMAKE_DL_LIBS})
   add_library(archer_static STATIC ompt-tsan.cpp)

   install(TARGETS archer archer_static

Explicitly link libdl as suggested by @vzakhari.