[lld] 4938b09 - [lld-macho] Don't use arrays as template parameters
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 15 18:16:54 PDT 2021
Author: Jez Ng
Date: 2021-04-15T21:16:34-04:00
New Revision: 4938b090cf0b8c0f716119a7f16205e53608cae2
URL: https://github.com/llvm/llvm-project/commit/4938b090cf0b8c0f716119a7f16205e53608cae2
DIFF: https://github.com/llvm/llvm-project/commit/4938b090cf0b8c0f716119a7f16205e53608cae2.diff
LOG: [lld-macho] Don't use arrays as template parameters
MSVC from VSCode 2017 appears unhappy with it (causes an
internal compiler error.)
This also means that we need to avoid doing `sizeof(stubCode)` as
`sizeof(int[N])` on function array parameters decays into `sizeof(int *)`.
Reviewed By: #lld-macho, gkm
Differential Revision: https://reviews.llvm.org/D100605
Added:
Modified:
lld/MachO/Arch/ARM64.cpp
lld/MachO/Arch/ARM64Common.h
lld/MachO/Arch/ARM64_32.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Arch/ARM64.cpp b/lld/MachO/Arch/ARM64.cpp
index a5953637b7f7b..708b12b92859c 100644
--- a/lld/MachO/Arch/ARM64.cpp
+++ b/lld/MachO/Arch/ARM64.cpp
@@ -76,7 +76,7 @@ static constexpr uint32_t stubCode[] = {
};
void ARM64::writeStub(uint8_t *buf8, const Symbol &sym) const {
- ::writeStub<LP64, stubCode>(buf8, sym);
+ ::writeStub<LP64>(buf8, stubCode, sym);
}
static constexpr uint32_t stubHelperHeaderCode[] = {
@@ -89,7 +89,7 @@ static constexpr uint32_t stubHelperHeaderCode[] = {
};
void ARM64::writeStubHelperHeader(uint8_t *buf8) const {
- ::writeStubHelperHeader<LP64, stubHelperHeaderCode>(buf8);
+ ::writeStubHelperHeader<LP64>(buf8, stubHelperHeaderCode);
}
static constexpr uint32_t stubHelperEntryCode[] = {
@@ -100,7 +100,7 @@ static constexpr uint32_t stubHelperEntryCode[] = {
void ARM64::writeStubHelperEntry(uint8_t *buf8, const DylibSymbol &sym,
uint64_t entryVA) const {
- ::writeStubHelperEntry<stubHelperEntryCode>(buf8, sym, entryVA);
+ ::writeStubHelperEntry(buf8, stubHelperEntryCode, sym, entryVA);
}
ARM64::ARM64() : ARM64Common(LP64()) {
diff --git a/lld/MachO/Arch/ARM64Common.h b/lld/MachO/Arch/ARM64Common.h
index 1e858f6748c79..934101caefb99 100644
--- a/lld/MachO/Arch/ARM64Common.h
+++ b/lld/MachO/Arch/ARM64Common.h
@@ -90,11 +90,13 @@ inline uint64_t pageBits(uint64_t address) {
return address & pageMask;
}
-template <class LP, const uint32_t stubCode[3]>
-inline void writeStub(uint8_t *buf8, const macho::Symbol &sym) {
+template <class LP>
+inline void writeStub(uint8_t *buf8, const uint32_t stubCode[3],
+ const macho::Symbol &sym) {
auto *buf32 = reinterpret_cast<uint32_t *>(buf8);
+ constexpr size_t stubCodeSize = 3 * sizeof(uint32_t);
uint64_t pcPageBits =
- pageBits(in.stubs->addr + sym.stubsIndex * sizeof(stubCode));
+ pageBits(in.stubs->addr + sym.stubsIndex * stubCodeSize);
uint64_t lazyPointerVA =
in.lazyPointers->addr + sym.stubsIndex * LP::wordSize;
buf32[0] = encodePage21({&sym, "stub"}, stubCode[0],
@@ -103,8 +105,9 @@ inline void writeStub(uint8_t *buf8, const macho::Symbol &sym) {
buf32[2] = stubCode[2];
}
-template <class LP, const uint32_t stubHelperHeaderCode[6]>
-inline void writeStubHelperHeader(uint8_t *buf8) {
+template <class LP>
+inline void writeStubHelperHeader(uint8_t *buf8,
+ const uint32_t stubHelperHeaderCode[6]) {
auto *buf32 = reinterpret_cast<uint32_t *>(buf8);
auto pcPageBits = [](int i) {
return pageBits(in.stubHelper->addr + i * sizeof(uint32_t));
@@ -123,9 +126,9 @@ inline void writeStubHelperHeader(uint8_t *buf8) {
buf32[5] = stubHelperHeaderCode[5];
}
-template <const uint32_t stubHelperEntryCode[3]>
-void writeStubHelperEntry(uint8_t *buf8, const DylibSymbol &sym,
- uint64_t entryVA) {
+inline void writeStubHelperEntry(uint8_t *buf8,
+ const uint32_t stubHelperEntryCode[3],
+ const DylibSymbol &sym, uint64_t entryVA) {
auto *buf32 = reinterpret_cast<uint32_t *>(buf8);
auto pcVA = [entryVA](int i) { return entryVA + i * sizeof(uint32_t); };
uint64_t stubHelperHeaderVA = in.stubHelper->addr;
diff --git a/lld/MachO/Arch/ARM64_32.cpp b/lld/MachO/Arch/ARM64_32.cpp
index f0d39c5b1a822..80bd933f0728a 100644
--- a/lld/MachO/Arch/ARM64_32.cpp
+++ b/lld/MachO/Arch/ARM64_32.cpp
@@ -74,7 +74,7 @@ static constexpr uint32_t stubCode[] = {
};
void ARM64_32::writeStub(uint8_t *buf8, const Symbol &sym) const {
- ::writeStub<ILP32, stubCode>(buf8, sym);
+ ::writeStub<ILP32>(buf8, stubCode, sym);
}
static constexpr uint32_t stubHelperHeaderCode[] = {
@@ -87,7 +87,7 @@ static constexpr uint32_t stubHelperHeaderCode[] = {
};
void ARM64_32::writeStubHelperHeader(uint8_t *buf8) const {
- ::writeStubHelperHeader<ILP32, stubHelperHeaderCode>(buf8);
+ ::writeStubHelperHeader<ILP32>(buf8, stubHelperHeaderCode);
}
static constexpr uint32_t stubHelperEntryCode[] = {
@@ -98,7 +98,7 @@ static constexpr uint32_t stubHelperEntryCode[] = {
void ARM64_32::writeStubHelperEntry(uint8_t *buf8, const DylibSymbol &sym,
uint64_t entryVA) const {
- ::writeStubHelperEntry<stubHelperEntryCode>(buf8, sym, entryVA);
+ ::writeStubHelperEntry(buf8, stubHelperEntryCode, sym, entryVA);
}
ARM64_32::ARM64_32() : ARM64Common(ILP32()) {
More information about the llvm-commits
mailing list