From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Doods Pav <doodspav@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Is changing __STDCPP_DEFAULT_NEW_ALIGNMENT__ an ABI break
Date: Mon, 21 Mar 2022 11:15:05 +0000 [thread overview]
Message-ID: <CAH6eHdT6jswxV=yNgcUCYn3D9_LznWOeHFVRVtRZSP-=XuGByQ@mail.gmail.com> (raw)
In-Reply-To: <CAA41uA6YY2yGvhtF9zbK6Srb2QB4sQyEMN0k121kZ+tNy0-qGg@mail.gmail.com>
On Sun, 20 Mar 2022 at 15:39, Doods Pav via Gcc-help
<gcc-help@gcc.gnu.org> wrote:
>
> Is changing the value of the predefined macro
> `__STDCPP_DEFAULT_NEW_ALIGNMENT__` considered an ABI break? (in the same
> way that modifying `alignof(std::max_align_t)` would be).
It depends.
If the OS's C library does not provide aligned_alloc or posix_memalign
or memalign then it's an ABI break. If the C library doesn't provide
one of those functions, then the operator new(size_t, align_val_t)
function needs to do additional bookkeeping to be able to deallocate
the aligned memory. The value of that macro determines whether a given
object size uses operator new(size_t) or operator new(size_t,
align_val_t), so if you change the value of the macro you change
whether additional bookkeeping is needed for a given object size. If
different parts of the program disagree, you could allocate memory
using the aligned form and then try to deallocate it using the
non-aligned operator delete(void*, size_t), which would have undefined
behaviour.
This is the case on Windows, as it only provides
_aligned_malloc/_aligned_free, which are not compatible with
malloc/free. It might also be the case on very old versions of newlib
and other C libraries.
Also, if your program replaces operator new(size_t) and/or operator
new(size_t, align_val_t) and makes them incompatible, then changing
the default new alignment is also an ABI break (because for the same
reasons as above, different parts of the program will disagree on
whether a given object size uses the overaligned new/delete or not).
In the common case (the OS supports one of the libc aligned allocation
functions, and you don't replace new/delete) it's not an ABI break.
> I would assume that it is, but I saw this comment on a bug report (
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77691#c33) and I'm unsure if
> the value of the macro was later changed in a patch, and if so, if that was
> considered an ABI break.
The macro wasn't changed.
prev parent reply other threads:[~2022-03-21 11:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-20 15:38 Doods Pav
2022-03-21 11:15 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH6eHdT6jswxV=yNgcUCYn3D9_LznWOeHFVRVtRZSP-=XuGByQ@mail.gmail.com' \
--to=jwakely.gcc@gmail.com \
--cc=doodspav@gmail.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).