diff options
| author | Ivan Maidanski <ivmai@mail.ru> | 2017-01-20 11:58:13 +0300 |
|---|---|---|
| committer | Ivan Maidanski <ivmai@mail.ru> | 2017-01-20 11:58:13 +0300 |
| commit | 69c4010c1b3d43e2e179421e27379aaa5aeeb6d8 (patch) | |
| tree | 4085bc13d83e611096ea342a564d8b74441c9a13 /doc | |
| parent | e213ec3b782fe18babff4044a36d9a1c0a894f52 (diff) | |
| download | libatomic_ops-69c4010c1b3d43e2e179421e27379aaa5aeeb6d8.tar.gz | |
Fix test_atomic failure caused unaligned AO_double_t access on x86 (VC++)
Passing an unaligned AO_double_t pointer to AO double-wide primitives
results in an undefined behavior of the latter when running on x86 (or
violation of the corresponding assertion on the alignment).
MS VC++/x86 aligns AO_double_t values on a 4-byte boundary by default.
For the proper alignment, __declspec(align(8)) should be applied to
variables defined in the client code (which uses double-wide AO
primitives). Unfortunately, the attribute cannot be added to
AO_double_t definition itself because the compiler does not allow the
attribute for function arguments.
This patch introduces AO_DOUBLE_ALIGN attribute for use by clients of
the double-wide AO primitives (and, thus, AO_stack clients).
Matters only Visual Studio compiler for X86.
The inner clients (atomic_ops_malloc, test_atomic, test_stack) are
updated to use this attribute.
* doc/README_win32.txt [x86] (AO_DOUBLE_ALIGN): Document.
* src/atomic_ops/sysdeps/generic_pthread.h (AO_DOUBLE_ALIGN): Define
(as empty).
* src/atomic_ops/sysdeps/standard_ao_double_t.h [!_WIN64 && _WIN32
&& !__GNUC__ && _MSC_VER] (AO_DOUBLE_ALIGN): Define as declspec
align(8); document it.
* src/atomic_ops/sysdeps/standard_ao_double_t.h [!AO_DOUBLE_ALIGN]
(AO_DOUBLE_ALIGN): Define as empty (otherwise).
* src/atomic_ops_stack.h [AO_USE_ALMOST_LOCK_FREE && !AO_DOUBLE_ALIGN]
(AO_DOUBLE_ALIGN): Likewise.
* src/atomic_ops_malloc.c (AO_free_list): Use AO_DOUBLE_ALIGN attribute.
* tests/test_stack.c (the_list): Likewise.
* src/atomic_ops_stack.h [!AO_USE_ALMOST_LOCK_FREE] (AO_stack_t):
Document AO_DOUBLE_ALIGN usage (by clients).
* tests/test_atomic_include.template (test_atomicXX): Use
AO_DOUBLE_ALIGN attribute for old_w and w double-wide local variables
(to avoid alignment assertion violation or AO primitives undefined
behavior on x86 if the test code is compiled by VC++).
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/README_win32.txt | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/doc/README_win32.txt b/doc/README_win32.txt index e2b87ad..812006c 100644 --- a/doc/README_win32.txt +++ b/doc/README_win32.txt @@ -26,6 +26,11 @@ Most clients of atomic_ops.h will need to define AO_ASSUME_WINDOWS98 before including it. Compare_and_swap is otherwise not available. Defining AO_ASSUME_VISTA will make compare_double_and_swap_double available as well. +Please note that MS compiler for x86 does not align AO_double_t on an 8-byte +boundary, thus to avoid an undefined behavior, an AO_double_t (volatile) +variable should be declared with AO_DOUBLE_ALIGN attribute if the variable +reference is passed to an AO primitive (the attribute is not applicable to +arguments and pointers). Note that the library is covered by the GNU General Public License, while the top 2 of these pieces allow use in proprietary code. |
