summaryrefslogtreecommitdiff
path: root/Libraries/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/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/CMakeLists.txt')
-rw-r--r--Libraries/CMakeLists.txt1
1 files changed, 1 insertions, 0 deletions
diff --git a/Libraries/CMakeLists.txt b/Libraries/CMakeLists.txt
index 3954f99c43..9bce4e6bbd 100644
--- a/Libraries/CMakeLists.txt
+++ b/Libraries/CMakeLists.txt
@@ -2,6 +2,7 @@ add_subdirectory(LibAudio)
add_subdirectory(LibC)
add_subdirectory(LibCore)
add_subdirectory(LibCrypto)
+add_subdirectory(LibCxx)
add_subdirectory(LibDebug)
add_subdirectory(LibDesktop)
add_subdirectory(LibGemini)