-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility with GCC < 4.7 and ATOMICS #97
Comments
Well, albeit slower, the use of atomics there could be removed and the existing mutex (spec->regex_compiled) be used within the mutex. Then their are no atomics. Not sure how badly that would affct performance, but I would wager it won't be noticeable. |
Just using the mutex was deemed unacceptable for performance reasons by the Android team when the patch was first proposed that addressed the thread safety issues in selabel_lookup. |
Normal (non-atomic) accesses to 'spec->regex_compiled' would have equivalent effects to today's code. Atomic accesses would only be needed if you were trying to implement thread-safe algorithm without any locks. But you're not; you're just doing a first pass "should we even attempt to lock?" filter. In the current code, the pre-lock accesses to regex_compiled will race whether atomic or not; it's the mutex that ensures safety. |
Yes, I questioned the need for atomics in the original patch. At the time, the author of the patch said "I was thinking of that, but I figure I don't want to fix a multi threading issue by introducing a potential / even more subtle multi threading issue by relying on the compiler / architecture to do what I want. The atomics make it explicit that if compile_regex() returns success, that the regex is ready to be used, which isn't necessarily a guarantee that can be made across architectures without them." |
I'm very very skeptical (see in particular POSIX 4.12 "Memory Synchronization"), but as an incremental improvement I'll just address the build issue. |
I guess I'll submit to [email protected] too, but that list doesn't seem to have public archives so I wouldn't be able to include a link here. |
The __atomic_* GCC primitives were introduced in GCC 4.7, but Red Hat Enterprise Linux 6.x (for example) provides GCC 4.4. Tweak the current code to use the (most conservative) __sync_synchronize() primitive provided by those older GCC versions. Fixes SELinuxProject#97 (Really, no __atomic or __sync operations are needed here at all, since POSIX 4.12 "Memory Synchronization" says pthread_mutex_lock() and pthread_mutex_unlock() "synchronize memory with respect to other threads"...)
The __atomic_* GCC primitives were introduced in GCC 4.7, but Red Hat Enterprise Linux 6.x (for example) provides GCC 4.4. Tweak the current code to use the (most conservative) __sync_synchronize() primitive provided by those older GCC versions. Fixes SELinuxProject#97 (Really, no __atomic or __sync operations are needed here at all, since POSIX 4.12 "Memory Synchronization" says pthread_mutex_lock() and pthread_mutex_unlock() "synchronize memory with respect to other threads"...)
The __atomic_* GCC primitives were introduced in GCC 4.7, but Red Hat Enterprise Linux 6.x (for example) provides GCC 4.4. Tweak the current code to use the (most conservative) __sync_synchronize() primitive provided by those older GCC versions. Fixes SELinuxProject#97 (Really, no __atomic or __sync operations are needed here at all, since POSIX 4.12 "Memory Synchronization" says pthread_mutex_lock() and pthread_mutex_unlock() "synchronize memory with respect to other threads"...)
The __atomic_* GCC primitives were introduced in GCC 4.7, but Red Hat Enterprise Linux 6.x (for example) provides GCC 4.4. Tweak the current code to use the (most conservative) __sync_synchronize() primitive provided by those older GCC versions. Fixes SELinuxProject/selinux#97 (Really, no __atomic or __sync operations are needed here at all, since POSIX 4.12 "Memory Synchronization" says pthread_mutex_lock() and pthread_mutex_unlock() "synchronize memory with respect to other threads"...)
selinux/libselinux/src/label_file.h
Line 355 in f6e7613
Would an approach using sync's like the suggestion here be viable?
http:https://buildroot-busybox.2317881.n4.nabble.com/PATCH-docs-manual-gcc-4-4-is-the-lowest-we-are-known-to-work-with-tp200075p200254.html
The text was updated successfully, but these errors were encountered: