(I'm posting this question about UBSAN on the ASAN list because I couldn't
find a UBSAN list; let me know if there is one.)
Hello, I have a pretty large C++11 program that I just ran UBSAN on and I'm
getting errors related to misaligned addresses and alignments. It's
non-trivial to show a sample program so I'm hoping I can get pointed in the
right direction without that for now.
The class C in question has the following characteristics:
- Class C itself doesn't do anything special regarding memory alignment.
No posix_memalign, no alignas, etc.
- Class C, however, has a member that is of class M
- Class M does some alignment for some members using alignas. It looks
like this:
#define FALSE_SHARING_RANGE 128
class M {
char pad0_[FALSE_SHARING_RANGE];
alignas(FALSE_SHARING_RANGE) std::atomic<unsigned int> r;
alignas(FALSE_SHARING_RANGE) std::atomic<unsigned int> w;
char pad1_[FALSE_SHARING_RANGE - sizeof(w)];
void* v1;
const uint32_t s;
const uint32_t b;
const uint32_t pb;
}
Here are the UBSAN errors:
runtime error: constructor call on misaligned address 0x000003330ca0 for
type 'C', which requires 128 byte alignment
0x000003330ca0: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
^
runtime error: constructor call on misaligned address 0x000003330ca0 for
type 'C *', which requires 128 byte alignment
0x000003330ca0: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
^
runtime error: member call on misaligned address 0x000003330ca0 for type 'C
*', which requires 128 byte alignment
0x000003330ca0: note: pointer points here
00 00 00 00 85 eb 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
^
... similar errors continue
Note that when the alignas specifiers on r and w are removed, the UBSAN
errors go away.
I'd greatly appreciate if someone can explain 1) why this is occuring; 2)
and how to properly write the code to make the error go away. (Note: my
motivation for the alignas attributes is to prevent false sharing between r
and w as this class is used by concurrent threads.)
--
You received this message because you are subscribed to the Google Groups
"address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.