celeritas-project / celeritas

Celeritas is a new Monte Carlo transport code designed to accelerate scientific discovery in high energy physics by improving detector simulation throughput and energy efficiency using GPUs.
https://celeritas-project.github.io/celeritas/
Other
65 stars 35 forks source link

Anchor vtables to fix broken dynamic cast in tests #1474

Closed sethrj closed 3 weeks ago

sethrj commented 3 weeks ago

This follow-on to https://github.com/celeritas-project/celeritas/pull/1436 is to fix another manifestation of the bug caused by https://github.com/llvm/llvm-project/commit/9d525bf94b255df89587db955b5fa2d3c03c2c3e : in optimized mode, llvm fails to dynamic_cast classes that are declared final but have weak vtables. The weird part of fixing this instance was that to make the vtable strong, I had to anchor the GeoParamsInterface virtual destructor because that was in a separate library. (The GeantGeoParams and VecgeomParams worked because the inline virtual destructor was in the same library, so the final class had a "strong" vtable symbol.)

Before:

$ ninja orange && nm lib/liborange.dylib | c++filt | grep 'vtable for celeritas::.*Orange.*' | cut -b 18- | sort
S vtable for celeritas::OrangeParamsOutput
S vtable for celeritas::RaytraceImager<celeritas::OrangeParams>
s vtable for celeritas::CollectionMirror<celeritas::OrangeParamsData>
s vtable for celeritas::OrangeParams
$ ninja geocel && nm lib/libgeocel.dylib | c++filt | grep 'vtable for celeritas::.*Params.*' | cut -b 18- | sort
S vtable for celeritas::GeantGeoParams
S vtable for celeritas::GeoParamsOutput
S vtable for celeritas::RaytraceImager<celeritas::GeantGeoParams>
S vtable for celeritas::RaytraceImager<celeritas::VecgeomParams>
S vtable for celeritas::VecgeomParams
S vtable for celeritas::VecgeomParamsOutput
s vtable for celeritas::CollectionMirror<celeritas::ImageParamsData>
s vtable for celeritas::ImageParams

After (note celeritas::OrangeParams changes from s to S:

$ ninja orange && nm lib/liborange.dylib | c++filt | grep 'vtable for celeritas::.*Orange.*' | cut -b 18- | sort
S vtable for celeritas::CollectionMirror<celeritas::OrangeParamsData>
S vtable for celeritas::OrangeParams
S vtable for celeritas::OrangeParamsOutput
S vtable for celeritas::ParamsDataInterface<celeritas::OrangeParamsData>
S vtable for celeritas::RaytraceImager<celeritas::OrangeParams>
$ ninja geocel && nm lib/libgeocel.dylib | c++filt | grep 'vtable for celeritas::.*Params.*' | cut -b 18- | sort
S vtable for celeritas::GeantGeoParams
S vtable for celeritas::GeoParamsOutput
S vtable for celeritas::RaytraceImager<celeritas::GeantGeoParams>
S vtable for celeritas::RaytraceImager<celeritas::VecgeomParams>
S vtable for celeritas::VecgeomParams
S vtable for celeritas::VecgeomParamsOutput
s vtable for celeritas::CollectionMirror<celeritas::ImageParamsData>
s vtable for celeritas::ImageParams
github-actions[bot] commented 3 weeks ago

Test summary

 3 350 files   5 176 suites   3m 53s :stopwatch:  1 558 tests  1 530 :white_check_mark: 28 :zzz: 0 :x: 17 198 runs  17 135 :white_check_mark: 63 :zzz: 0 :x:

Results for commit 0d6553bd.