Skip to content
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

Closed
rc-matthew-l-weber opened this issue Aug 13, 2018 · 6 comments
Closed

Compatibility with GCC < 4.7 and ATOMICS #97

rc-matthew-l-weber opened this issue Aug 13, 2018 · 6 comments

Comments

@rc-matthew-l-weber
Copy link

__atomic_load_n(&spec->regex_compiled, __ATOMIC_ACQUIRE);

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

@williamcroberts
Copy link

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.

@stephensmalley
Copy link
Member

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.
Not opposed to the use of syncs on older gcc.

@slightlyunconventional
Copy link

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.

@stephensmalley
Copy link
Member

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."
If that's a bogus argument, then I'm open to a patch to get rid of it, but probably ought to include the original author on that as well.

@slightlyunconventional
Copy link

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.

@slightlyunconventional
Copy link

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.

0001-Fix-build-break-around-_atomic-with-GCC-4.7.patch.txt

fishilico pushed a commit to fishilico/selinux that referenced this issue Aug 19, 2018
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"...)
fishilico pushed a commit to fishilico/selinux that referenced this issue Aug 19, 2018
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"...)
fishilico pushed a commit to fishilico/selinux that referenced this issue Aug 22, 2018
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"...)
charleseb pushed a commit to MotorolaMobilityLLC/external-selinux that referenced this issue Jan 21, 2020
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"...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants