Page MenuHomeFreeBSD

Make the system C11 atomics headers fully compatible with external GCC.
ClosedPublic

Authored by jhb on Aug 3 2018, 8:50 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 30, 10:22 AM
Unknown Object (File)
Apr 7 2024, 3:54 AM
Unknown Object (File)
Mar 7 2024, 6:51 PM
Unknown Object (File)
Jan 6 2024, 12:22 AM
Unknown Object (File)
Jan 6 2024, 12:22 AM
Unknown Object (File)
Jan 6 2024, 12:22 AM
Unknown Object (File)
Jan 6 2024, 12:10 AM
Unknown Object (File)
Dec 22 2023, 10:06 PM
Subscribers

Details

Summary

The <sys/cdefs.h> and <stdatomic.h> headers already included support for
C11 atomics via intrinsincs in modern versions of GCC, but these versions
tried to "hide" atomic variables inside a wrapper structure. This wrapper
is not compatible with GCC's internal <stdatomic.h> header, so that if
GCC's <stdatomic.h> was used together with <sys/cdefs.h>, use of C11
atomics would fail to compile. Fix this by not hiding atomic variables
in a structure for modern versions of GCC. The headers already avoid
using a wrapper structure on clang.

Note that this wrapper was only used if C11 was not enabled (e.g.
via -std=c99), so this also fixes compile failures if a modern version
of GCC was used with -std=c11 but with FreeBSD's <stdatomic.h> instead
of GCC's <stdatomic.h> and this change fixes that case as well.

Test Plan
  • compile a simple test program using C11 atomics using different combinations:
    • gcc -c bar.c
    • gcc -std=c99 -c bar.c
    • gcc -std=c99 -nostdinc -I /usr/include -c bar.c
    • gcc -nostdinc -I /usr/include -c bar.c
  • cross-build a world using i386-xtoolchain-gcc

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable