]> git.ipfire.org Git - thirdparty/gcc.git/commit
Objective-C, Darwin: Do not overalign CFStrings and Objective-C metadata.
authorIain Sandoe <iain@sandoe.co.uk>
Thu, 25 Jan 2024 20:11:09 +0000 (20:11 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Sun, 28 Jan 2024 11:46:27 +0000 (11:46 +0000)
commitf74f840d35117bcaf995cee99fb2ab30c60f64f3
tree17f1e5a983aa1c51844edcefb0a41726d93f3f45
parent30d9e81c19d69e15b2e9c53e4377879cbf9b0b84
Objective-C, Darwin: Do not overalign CFStrings and Objective-C metadata.

We have reports of regressions in both Objective-C and Objective-C++ on
Darwin23 (macOS 14).  In some cases, these are linker warnings about the
alignment of CFString constants; in other cases the built executables
crash during runtime initialization.  The underlying issue is the same in
both cases; since the objects (CFStrings, Objective-C meta-data) are TU-
local, we are choosing to increase their alignment for efficiency - to
values greater than ABI alignment.

However, although these objects are TU-local, they are also visible to the
linker (since they are placed in specific named sections).  In many cases
the metadata can be regarded as tables of data, and thus it is expected
that these sections can be concatenated from multiple TUs and the data
treated as tabular.  In order for this to work the data cannot be allowed
to exceed ABI alignment - which leads to the crashes.

For GCC-15+ it would be nice to find a more elegant solution to this issue
(perhaps by adjusting the concept of binds-locally to exclude specific
named sections) - but I do not want to do that in stage 4.

The solution here is to force the alignment to be preserved as created by
setting DECL_USER_ALIGN on the relevant objects.

gcc/ChangeLog:

* config/darwin.cc (darwin_build_constant_cfstring): Prevent over-
alignment of CFString constants by setting DECL_USER_ALIGN.

gcc/objc/ChangeLog:

* objc-next-runtime-abi-02.cc (build_v2_address_table): Prevent
over-alignment of Objective-C metadata by setting DECL_USER_ALIGN
on relevant variables.
(build_v2_protocol_list_address_table): Likewise.
(generate_v2_protocol_list): Likewise.
(generate_v2_meth_descriptor_table): Likewise.
(generate_v2_meth_type_list): Likewise.
(generate_v2_property_table): Likewise.
(generate_v2_dispatch_table): Likewise.
(generate_v2_ivars_list): Likewise.
(generate_v2_class_structs): Likewise.
(build_ehtype): Likewise.
* objc-runtime-shared-support.cc (generate_strings): Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/config/darwin.cc
gcc/objc/objc-next-runtime-abi-02.cc
gcc/objc/objc-runtime-shared-support.cc