https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126230
Bug ID: 126230
Summary: std::atomic<T> when T has padding bytes violates
stable ABI
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: code at a dot krabler.eu
Target Milestone: ---
There is an ABI violation for std::atomic<T> when T contains padding bytes.
Given store_padding.cc:
#include <atomic>
#include <string.h>
struct WithPadding {
char small;
short big;
};
void store_padding(std::atomic<WithPadding>& awp) {
WithPadding wp;
::memset(&wp, 0xff, sizeof(wp));
awp.store(wp);
}
And the following main.cc:
#include <atomic>
struct WithPadding {
char small;
short big;
};
void store_padding(std::atomic<WithPadding>&);
int main() {
std::atomic<WithPadding> atomic_padding;
store_padding(atomic_padding);
auto expected = atomic_padding.load();
return !atomic_padding.compare_exchange_strong(expected, expected);
}
When store_padding.cc is compiled with gcc <= 12
(g++-12 -c -fPIC -std=c++17 store_padding.cc)
and then linked into the main.cc compiled with gcc >= 13
(g++ -std=c++17 main.cc store_padding.o),
the programs returns one, even if it should succeed and return zero.
Given C++17 is stable since GCC9, I think that is an ABI bug.