This is an archive of the discontinued LLVM Phabricator instance.

[clang-repl][Orc] Export executable symbols in ClangReplInterpreterExceptionTests
ClosedPublic

Authored by lkail on Aug 29 2023, 10:57 PM.

Details

Summary

In Orc runtime, we use dlopen(nullptr, ...) to open current executable and use dlsym to find addresses of symbols, this requires -rdynamic flag.

As llvm/CMakeLists.txt suggests

# Make sure we don't get -rdynamic in every binary. For those that need it,
# use export_executable_symbols(target).

This patch exports symbols in ClangReplInterpreterExceptionTests. This also fixes ClangReplInterpreterExceptionTests is skipped on ppc64 when jitlink is used.

Diff Detail

Event Timeline

lkail created this revision.Aug 29 2023, 10:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 10:57 PM
lkail requested review of this revision.Aug 29 2023, 10:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 10:57 PM
lkail edited the summary of this revision. (Show Details)Aug 29 2023, 10:59 PM
This revision is now accepted and ready to land.Sep 6 2023, 11:37 PM
This revision was automatically updated to reflect the committed changes.
vitalybuka added a comment.EditedSep 13 2023, 9:11 AM

I landed b4b4d8bd61d8de946e130beff5049a4ab13e155d as workaround
I unlikely will have time to figure out what is going on there, but will try to help maintainers, if there is an interest in sanitizers support. I know that we have other JIT related tests were sanitizers are disabled.

Also maybe it's cleaner just disable a particular test (binary or test case) with incompatible sanitizer. Leaving this up to @lkail or @v.g.vassilev

@vitalybuka If we want to disable this test for now, what's the canonical way to do it? Should we just wrap the whole add_clang_unittest block in the conditional?

# export_executable_symbols triggers Lsan report.                                                                                                                                                                                                                                              
if (NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")

  add_clang_unittest(ClangReplInterpreterExceptionTests
    InterpreterExceptionTest.cpp
    )

  llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
  target_link_libraries(ClangReplInterpreterExceptionTests PUBLIC
    clangAST
    clangBasic
    clangInterpreter
    clangFrontend
    )
  add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)

  export_executable_symbols(ClangReplInterpreterExceptionTests)
endif()

@vitalybuka If we want to disable this test for now, what's the canonical way to do it? Should we just wrap the whole add_clang_unittest block in the conditional?

# export_executable_symbols triggers Lsan report.                                                                                                                                                                                                                                              
if (NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")

  add_clang_unittest(ClangReplInterpreterExceptionTests
    InterpreterExceptionTest.cpp
    )

  llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
  target_link_libraries(ClangReplInterpreterExceptionTests PUBLIC
    clangAST
    clangBasic
    clangInterpreter
    clangFrontend
    )
  add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)

  export_executable_symbols(ClangReplInterpreterExceptionTests)
endif()

This should work.

Also you can

#if LLVM_HWADDRESS_SANITIZER_BUILD || LLVM_ADDRESS_SANITIZER_BUILD
#  define MAYBE_MyTest DISABLED_MyTest
#else
#  define MAYBE_MyTest MyTest
#endif

But here we have just one test case

Also you can try disable only lsan, link time:

#if LLVM_ADDRESS_SANITIZER_BUILD || LLVM_HWADDRESS_SANITIZER_BUILD
#include <sanitizer/lsan_interface.h>
LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return 1; }
#endif

Ok -- I'll try disabling lsan for now. It'll be good to test this path (even with a leak), and it'll make reproduction extra simple when someone has cycles to look into the leak.