[llvm-branch-commits] [lld] e8f03f2 - Force GHashCell to be 8-byte-aligned.

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Apr 18 17:10:02 PDT 2022


Author: Eli Friedman
Date: 2022-04-18T17:05:35-07:00
New Revision: e8f03f2057ee783439229391a14b2ffe17346100

URL: https://github.com/llvm/llvm-project/commit/e8f03f2057ee783439229391a14b2ffe17346100
DIFF: https://github.com/llvm/llvm-project/commit/e8f03f2057ee783439229391a14b2ffe17346100.diff

LOG: Force GHashCell to be 8-byte-aligned.

Otherwise, with recent versions of libstdc++, clang can't tell that the
atomic operations are properly aligned, and generates calls to
libatomic.  (Actually, because of the use of reinterpret_cast, it wasn't
guaranteed to be aligned, but I think it ended up being aligned in
practice.)

Fixes https://github.com/llvm/llvm-project/issues/54790 , the part where
LLVM failed to build.

Differential Revision: https://reviews.llvm.org/D123872

(cherry picked from commit 13fc1781735a327699d9522e8e44899acf92a61a)

Added: 
    

Modified: 
    lld/COFF/DebugTypes.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp
index aa2ce3bd9bbbf..0d25de464f9f6 100644
--- a/lld/COFF/DebugTypes.cpp
+++ b/lld/COFF/DebugTypes.cpp
@@ -902,7 +902,11 @@ struct GHashTable {
 
 /// A ghash table cell for deduplicating types from TpiSources.
 class GHashCell {
-  uint64_t data = 0;
+  // Force "data" to be 64-bit aligned; otherwise, some versions of clang
+  // will generate calls to libatomic when using some versions of libstdc++
+  // on 32-bit targets.  (Also, in theory, there could be a target where
+  // new[] doesn't always return an 8-byte-aligned allocation.)
+  alignas(sizeof(uint64_t)) uint64_t data = 0;
 
 public:
   GHashCell() = default;


        


More information about the llvm-branch-commits mailing list