ascent icon indicating copy to clipboard operation
ascent copied to clipboard

Linker warning about weak symbols

Open ibaned opened this issue 3 years ago • 12 comments

Hi There!

We're getting the following linker warning when linking our application, which uses all static libraries for Ascent and its dependencies:

ld: warning: direct access in function 'std::__1::__shared_ptr_pointer<std::__1::__empty_state<char>*, std::__1::shared_ptr<std::__1::__empty_state<char> >::__shared_ptr_default_delete<std::__1::__empty_state<char>, std::__1::__empty_state<char> >, std::__1::allocator<std::__1::__empty_state<char> > >::__get_deleter(std::type_info const&) const' from file '/Users/daibane/capp-alegra-ng/flavor/skylake/install/ascent/lib/libascent_mpi.a(ascent_actions_utils.cpp.o)' to global weak symbol 'typeinfo name for std::__1::shared_ptr<std::__1::__empty_state<char> >::__shared_ptr_default_delete<std::__1::__empty_state<char>, std::__1::__empty_state<char> >' from file '/Users/daibane/capp-alegra-ng/flavor/skylake/install/mu/lib/libmu.a(mu_datafile.cpp.o)' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

Is there some visibility setting we could change in Ascent to silence this?

ibaned avatar Oct 12 '22 15:10 ibaned

I think those style of symbols come from C++ std namespaces.

There is nothing special going on in ascent_actions_utils.cpp.o so this might be hard to track down.

We do default to hidden symbol visibility:

set_target_properties(ascent_mpi PROPERTIES CXX_VISIBILITY_PRESET hidden)

https://github.com/Alpine-DAV/ascent/blob/d7f41651f8251ffffb2b74845489e7fb4eb3fcae/src/ascent/CMakeLists.txt#L526

Any ideas of how we could narrow down the culprit?

Do we also need CMAKE_VISIBILITY_INLINES_HIDDEN?

cyrush avatar Oct 12 '22 15:10 cyrush

Would an option to not do hidden visibility make any sense? Or would that break Ascent in some major way?

ibaned avatar Oct 12 '22 16:10 ibaned

We could try -- but we prefer hidden symbol visibility for VTK-m, else we get a ton of symbols exposed.

cyrush avatar Oct 12 '22 17:10 cyrush

Is it possible to leave this up to the user so that your builds would specify

-DCMAKE_CXX_VISIBILITY_PRESET=ON

and each user can choose what visibility their whole build uses?

ibaned avatar Oct 13 '22 16:10 ibaned

My bad, I meant:

-DCMAKE_CXX_VISIBILITY_PRESET=hidden

https://cmake.org/cmake/help/latest/prop_tgt/LANG_VISIBILITY_PRESET.html

ibaned avatar Oct 13 '22 16:10 ibaned

How about we default to hidden, but allow you to override?

cyrush avatar Oct 13 '22 16:10 cyrush

That works great for me, thank you!

ibaned avatar Oct 13 '22 16:10 ibaned

Hang on... I've tried removing the visibility preset commands from all of Ascen't CMakeLists.txt files and I'm still getting warnings like this... let me explore setting our app's visibility to hidden, see if I can get any combination at all that has no warnings

ibaned avatar Oct 13 '22 16:10 ibaned

Ah nevermind, I was bitten by CMake caches that were still making things hidden. If I remove all the visibility lines from the Ascent CMake and set -DVTKm_HIDE_PRIVATE_SYMBOLS=OFF for VTK-m, then all my link warnings go away! Perhaps Ascent could be set up the same way as VTK-m with a HIDE_PRIVATE_SYMBOLS option ON by default?

ibaned avatar Oct 13 '22 20:10 ibaned

I would be willing to do the PR to implement this if you're willing to accept it. It sounds like VTK-m implements that option for applications with static builds, which our application is.

ibaned avatar Oct 13 '22 20:10 ibaned

@ibaned absolutely -- that would be great

cyrush avatar Oct 13 '22 20:10 cyrush

I just opened #1033 which resolves this

ibaned avatar Oct 14 '22 15:10 ibaned

resolved in #1033

cyrush avatar Oct 17 '22 16:10 cyrush