summaryrefslogtreecommitdiff
path: root/Libraries/LibCxx/CMakeLists.txt
diff options
context:
space:
mode:
authorAndrew Kaster <andrewdkaster@gmail.com>2020-05-15 21:38:03 -0600
committerAndreas Kling <kling@serenityos.org>2020-05-20 08:37:50 +0200
commitcdbbe14062ea49f9a9d9b0e5627aba9efd07659a (patch)
treecc65775010ad3b4fdefdbd44ac88ee7e922a6afb /Libraries/LibCxx/CMakeLists.txt
parent4361a502255e409f04c9325ef73f3cd10f9cafdb (diff)
downloadserenity-cdbbe14062ea49f9a9d9b0e5627aba9efd07659a.zip
LibC: Implement Itanium C++ ABI for static variable guards
This is __cxa_guard_acquire, __cxa_guard_release, and __cxa_guard_abort. We put these symbols in a 'fake' libstdc++ to trick gcc into thinking it has libstdc++. These symbols are necessary for C++ programs and not C programs, so, seems file. There's no way to tell gcc that, for example, the standard lib it should use is libc++ or libc. So, this is what we have for now. When threaded code enters a block that is trying to call the constructor for a block-scope static, the compiler will emit calls to these methods to handle the "call_once" nature of block-scope statics. The compiler creates a 64-bit guard variable, which it checks the first byte of to determine if the variable should be intialized or not. If the compiler-generated code reads that byte as a 0, it will call __cxa_guard_acquire to try and be the thread to call the constructor for the static variable. If the first byte is 1, it will assume that the variable's constructor was called, and go on to access it. __cxa_guard_acquire uses one of the 7 implementation defined bytes of the guard variable as an atomic 8 bit variable. To control a state machine that lets each entering thread know if they gained 'initialization rights', someone is working on the varaible, someone is working on the varaible and there's at least one thread waiting for it to be intialized, or if the variable was initialized and it's time to access it. We only store a 1 to the byte the compiler looks at in __cxa_guard_release, and use a futex to handle waiting.
Diffstat (limited to 'Libraries/LibCxx/CMakeLists.txt')
-rw-r--r--Libraries/LibCxx/CMakeLists.txt7
1 files changed, 7 insertions, 0 deletions
diff --git a/Libraries/LibCxx/CMakeLists.txt b/Libraries/LibCxx/CMakeLists.txt
new file mode 100644
index 0000000000..f9cec683bb
--- /dev/null
+++ b/Libraries/LibCxx/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(SOURCES
+ CxaGuard.cpp
+)
+
+# Shhh don't worry gcc, we are totally libstdc++
+serenity_libc(LibCxx stdc++)
+target_link_libraries(LibCxx LibC)