diff options
author | Tom Tan <Tom.Tan@microsoft.com> | 2019-05-02 00:38:14 +0000 |
---|---|---|
committer | Tom Tan <Tom.Tan@microsoft.com> | 2019-05-02 00:38:14 +0000 |
commit | b7c6d95af5e295c560d1445e7090e31eb9289932 (patch) | |
tree | 17dc636dd19bfc8769acfe505a445ae1051a54c2 /clang/lib/Basic/Targets/AArch64.cpp | |
parent | a78ab77b6b784417a00287b082ab331355da2026 (diff) | |
download | bcm5719-llvm-b7c6d95af5e295c560d1445e7090e31eb9289932.tar.gz bcm5719-llvm-b7c6d95af5e295c560d1445e7090e31eb9289932.zip |
[COFF, ARM64] Align global symbol by size for ARM64 MSVC ABI
According to alignment section in below ARM64 ABI document, MSVC could increase
alignment of global data based on its total size. Clang doesn't do this. Compile
the same symbol into different alignments by Clang and MSVC could cause link
error because some instruction encodings, like 64-bit LDR/STR with immediate,
require the target to be 8 bytes aligned, and linker could choose code stream
with such LDR/STR instruction from MSVC and 4 bytes aligned data from Clang into
final image, which actually cannot be linked together
(see https://bugs.llvm.org/show_bug.cgi?id=41506 for more details).
https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=vs-2019#alignment
Differential Revision: https://reviews.llvm.org/D61225
llvm-svn: 359744
Diffstat (limited to 'clang/lib/Basic/Targets/AArch64.cpp')
-rw-r--r-- | clang/lib/Basic/Targets/AArch64.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index d61a6f4938b..120a0e2d4e8 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -551,6 +551,23 @@ MicrosoftARM64TargetInfo::getCallingConvKind(bool ClangABICompat4) const { return CCK_MicrosoftWin64; } +unsigned MicrosoftARM64TargetInfo::getMinGlobalAlign(uint64_t TypeSize) const { + unsigned Align = WindowsARM64TargetInfo::getMinGlobalAlign(TypeSize); + + // MSVC does size based alignment for arm64 based on alignment section in + // below document, replicate that to keep alignment consistent with object + // files compiled by MSVC. + // https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions + if (TypeSize >= 512) { // TypeSize >= 64 bytes + Align = std::max(Align, 128u); // align type at least 16 bytes + } else if (TypeSize >= 64) { // TypeSize >= 8 bytes + Align = std::max(Align, 64u); // align type at least 8 butes + } else if (TypeSize >= 16) { // TypeSize >= 2 bytes + Align = std::max(Align, 32u); // align type at least 4 bytes + } + return Align; +} + MinGWARM64TargetInfo::MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : WindowsARM64TargetInfo(Triple, Opts) { |