Commit 3371470
committed
CMake: Build zigcpp as a shared library when LLVM/Clang are shared libraries
This change intends to avoid the "Static Initialization Order Fiasco"
In general static initialization order is not guaranteed by C/C++, but
as @kubkon helpfully explained to me today (thanks!), there are some
guarantees provided by the linker (either static or dynamic) w.r.t.
initialization order that LLVM/Clang may depend upon.
These guarantees are apparently preserved when one shared library
resolves static symbols in another, but they break down when resolving
static symbols in a shared library from the main application. The concern
in this case is that the static initializers from the library may be
executed after those of the main executable.
In order to restore this ordering guarantee, we have to ensure any code
that references a static variable of a dynamically-loaded library is not
statically linked to the main application. This means that `zigcpp`
needs to be compiled as a shared library, and linked dynamically.1 parent 7acbb91 commit 3371470
1 file changed
+25
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
902 | | - | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
903 | 908 | | |
904 | 909 | | |
905 | 910 | | |
| |||
1005 | 1010 | | |
1006 | 1011 | | |
1007 | 1012 | | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
1008 | 1024 | | |
1009 | 1025 | | |
1010 | 1026 | | |
| |||
1019 | 1035 | | |
1020 | 1036 | | |
1021 | 1037 | | |
1022 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1023 | 1046 | | |
1024 | 1047 | | |
1025 | 1048 | | |
| |||
0 commit comments