This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] Call global destructors from entries
ClosedPublic

Authored by beanz on Sep 8 2022, 1:10 PM.

Details

Summary

HLSL doesn't have a C++ runtime that supports atexit registration. To
enable global destructors we instead rely on the llvm.global_dtor
mechanism.

This change disables atexit generation for HLSL and updates the HLSL
code generation to call global destructors on the exit from entry
functions.

Depends on D132977.

Diff Detail

Event Timeline

beanz created this revision.Sep 8 2022, 1:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 8 2022, 1:10 PM
Herald added a subscriber: Anastasia. · View Herald Transcript
beanz requested review of this revision.Sep 8 2022, 1:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 8 2022, 1:10 PM

This generally LGTM, but to double-check: the behavior if the user does call atexit() or or at_quick_exit() is that we simply don't call those handlers? As opposed to something worse like we dispatch to the handler and then crash on exit or something like that?

beanz added a comment.Sep 9 2022, 1:07 PM

This generally LGTM, but to double-check: the behavior if the user does call atexit() or or at_quick_exit() is that we simply don't call those handlers? As opposed to something worse like we dispatch to the handler and then crash on exit or something like that?

There should be no way to successfully compile and link a shader calling atexit() or at_quick_exit(). Neither of those functions are provided by the runtime so it should turn into a compile or linking error somewhere in the build process (either missing declaration or missing symbol resolution).

aaron.ballman accepted this revision.Sep 10 2022, 5:22 AM

This generally LGTM, but to double-check: the behavior if the user does call atexit() or or at_quick_exit() is that we simply don't call those handlers? As opposed to something worse like we dispatch to the handler and then crash on exit or something like that?

There should be no way to successfully compile and link a shader calling atexit() or at_quick_exit(). Neither of those functions are provided by the runtime so it should turn into a compile or linking error somewhere in the build process (either missing declaration or missing symbol resolution).

Wonderful! Then this LGTM!

This revision is now accepted and ready to land.Sep 10 2022, 5:22 AM
This revision was automatically updated to reflect the committed changes.