Skip to content

[lld-macho] Fix Defined size increase with -mms-bitfields #107545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

BertalanD
Copy link
Member

@BertalanD BertalanD commented Sep 6, 2024

Under the Microsoft ABI, only those bit fields can be merged whose underlying types have the same size.

d175616 ([lld-macho][arm64] Enhance safe ICF with thunk-based deduplication) added an enum field (identicalCodeFoldingKind) next to booleans in the Defined class, which increased the size under the MS ABI. On MinGW targets, this triggered the static_assert which checks the size of Defined (for MSVC targets, the check is disabled due to another problem). Let's store it as a uint8_t to allow merging to take place.

Fixes #107511

Under the Microsoft ABI, only those bit fields can be merged whose
underlying types have the same size.

d175616 (`[lld-macho][arm64] Enhance safe ICF with thunk-based
deduplication`) added an enum field (`identicalCodeFoldingKind`) next to
booleans in the `Defined` class, which increased the size under the MS
ABI. This triggered the `static_assert` which checks the size of
`Defined`. Let's store it as a `uint8_t` to allow merging to take place.

Fixes llvm#107511
@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-macho

Author: Daniel Bertalan (BertalanD)

Changes

Under the Microsoft ABI, only those bit fields can be merged whose underlying types have the same size.

d175616 ([lld-macho][arm64] Enhance safe ICF with thunk-based deduplication) added an enum field (identicalCodeFoldingKind) next to booleans in the Defined class, which increased the size under the MS ABI. This triggered the static_assert which checks the size of Defined. Let's store it as a uint8_t to allow merging to take place.

Fixes #107511


Full diff: https://github.com/llvm/llvm-project/pull/107545.diff

1 Files Affected:

  • (modified) lld/MachO/Symbols.h (+3-1)
diff --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h
index 70fd195f25c929..beb97b35bf8817 100644
--- a/lld/MachO/Symbols.h
+++ b/lld/MachO/Symbols.h
@@ -14,6 +14,7 @@
 #include "Target.h"
 
 #include "llvm/Object/Archive.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/MathExtras.h"
 
 namespace lld {
@@ -152,7 +153,8 @@ class Defined : public Symbol {
   // Whether this symbol should appear in the output symbol table.
   bool includeInSymtab : 1;
   // The ICF folding kind of this symbol: None / Body / Thunk.
-  ICFFoldKind identicalCodeFoldingKind : 2;
+  LLVM_PREFERRED_TYPE(ICFFoldKind)
+  uint8_t identicalCodeFoldingKind : 2;
   // Symbols marked referencedDynamically won't be removed from the output's
   // symbol table by tools like strip. In theory, this could be set on arbitrary
   // symbols in input object files. In practice, it's used solely for the

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

The PR message is great, but it could also be good to further clarify that the failing static assert already is ifdeffed out for MSVC targets, but MinGW targets also use the same MS bitfield packing logic (for binary compatibility of C structs).

@BertalanD BertalanD merged commit 691e3c6 into llvm:main Sep 6, 2024
9 of 10 checks passed
@BertalanD BertalanD deleted the fix-107511 branch September 6, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lld] build failure
3 participants