Skip to content

Commit b00b235

Browse files
authored
Merge pull request #796 from hvdijk/windows-arm
Fixes for Windows on ARM.
2 parents a1002f8 + aa87bbd commit b00b235

4 files changed

Lines changed: 40 additions & 77 deletions

File tree

modules/compiler/targets/host/source/target.cpp

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -175,76 +175,39 @@ compiler::Result HostTarget::initWithBuiltins(
175175
auto host_device_info =
176176
static_cast<host::device_info_s &>(*compiler_info->device_info);
177177

178-
switch (host_device_info.arch) {
179-
case host::arch::ARM:
180-
assert(host::os::LINUX == host_device_info.os &&
181-
"ARM cross-compile only supports Linux");
182-
// For cross compiled ARM builds, we can't rely on sys::getProcessTriple
183-
// to determine our target. Instead, we set it to a known working triple.
184-
triple = llvm::Triple("armv7-unknown-linux-gnueabihf-elf");
185-
break;
186-
case host::arch::AARCH64:
187-
switch (host_device_info.os) {
188-
case host::os::LINUX:
178+
switch (host_device_info.os) {
179+
case host::os::ANDROID:
180+
case host::os::LINUX:
181+
// For Linux, we support cross compilation, which means we cannot rely on
182+
// sys::getProcessTriple to determine our target. Instead, we set it to a
183+
// known working triple.
184+
switch (host_device_info.arch) {
185+
case host::arch::ARM:
186+
triple = llvm::Triple("armv7-unknown-linux-gnueabihf-elf");
187+
break;
188+
case host::arch::AARCH64:
189189
triple = llvm::Triple("aarch64-linux-gnu-elf");
190190
break;
191-
case host::os::MACOS:
192-
assert(host_device_info.native &&
193-
"macOS cross-compile not supported");
194-
// Our generated code does not meet Mach-O restrictions: "mach-o
195-
// section specifier requires a segment and section separated by a
196-
// comma" when we use "notes" as a section name. Force ELF generation
197-
// instead, which makes things easier for us anyway as we can reuse
198-
// the existing ELF loading logic.
199-
triple = llvm::Triple(llvm::sys::getProcessTriple() + "-elf");
191+
case host::arch::RISCV32:
192+
triple = llvm::Triple("riscv32-unknown-elf");
200193
break;
201-
default:
202-
llvm_unreachable("AArch64 cross-compile only supports Linux");
203-
}
204-
break;
205-
case host::arch::RISCV32:
206-
assert(host::os::LINUX == host_device_info.os &&
207-
"RISCV cross-compile only supports Linux");
208-
// For cross compiled RISCV builds, we can't rely on sys::getProcessTriple
209-
// to determine our target. Instead, we set it to a known working triple.
210-
triple = llvm::Triple("riscv32-unknown-elf");
211-
break;
212-
case host::arch::RISCV64:
213-
assert(host::os::LINUX == host_device_info.os &&
214-
"RISCV cross-compile only supports Linux");
215-
triple = llvm::Triple("riscv64-unknown-elf");
216-
break;
217-
case host::arch::X86:
218-
case host::arch::X86_64:
219-
switch (host_device_info.os) {
220-
case host::os::ANDROID:
221-
case host::os::LINUX:
222-
triple = llvm::Triple(host::arch::X86 == host_device_info.arch
223-
? "i386-unknown-unknown-elf"
224-
: "x86_64-unknown-unknown-elf");
194+
case host::arch::RISCV64:
195+
triple = llvm::Triple("riscv64-unknown-elf");
225196
break;
226-
case host::os::WINDOWS:
227-
// Using windows here ensures that _chkstk() is called which is
228-
// important for paging in the stack.
229-
#if defined(__MINGW32__) || defined(__MINGW64__)
230-
triple = llvm::Triple(host::arch::X86 == host_device_info.arch
231-
? "i386-pc-windows-gnu-elf"
232-
: "x86_64-w64-windows-gnu-elf");
233-
#else
234-
triple = llvm::Triple(host::arch::X86 == host_device_info.arch
235-
? "i386-pc-windows-msvc-elf"
236-
: "x86_64-pc-windows-msvc-elf");
237-
#endif
197+
case host::arch::X86:
198+
triple = llvm::Triple("i386-unknown-unknown-elf");
238199
break;
239-
case host::os::MACOS:
240-
assert(host_device_info.native &&
241-
"macOS cross-compile not supported");
242-
// On Apple, the MachO loader has a bug and can't JIT correctly. We
243-
// have to force elf generation for MachO builds. See Redmine #7621.
244-
triple = llvm::Triple(llvm::sys::getProcessTriple() + "-elf");
200+
case host::arch::X86_64:
201+
triple = llvm::Triple("x86_64-unknown-unknown-elf");
245202
break;
246203
}
247204
break;
205+
case host::os::WINDOWS:
206+
case host::os::MACOS:
207+
assert(host_device_info.native &&
208+
"Cross compilation only supported for Linux");
209+
triple = llvm::Triple(llvm::sys::getProcessTriple() + "-elf");
210+
break;
248211
}
249212

250213
std::string CPU;

modules/mux/targets/host/test/UnitCL/host_clGetDeviceInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST_F(host_clGetDeviceInfoTest, Name) {
4949
#if defined(__arm__) || defined(__thumb__) || defined(_M_ARM) || \
5050
defined(_M_ARMT)
5151
const char *arch = "Arm";
52-
#elif defined(__aarch64__)
52+
#elif defined(__aarch64__) || defined(_M_ARM64)
5353
const char *arch = "AArch64";
5454
#elif defined(__i386__) || defined(_M_IX86)
5555
const char *arch = "x86";

modules/utils/include/utils/system.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
/// @{
2828

2929
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || \
30-
(defined(__riscv) && __riscv_xlen == 64)
30+
defined(_M_ARM64) || (defined(__riscv) && __riscv_xlen == 64)
3131
#define UTILS_SYSTEM_64_BIT 1
3232
#else
3333
#define UTILS_SYSTEM_32_BIT 1
3434
#endif
3535

3636
#if defined(__arm__) || defined(__thumb__) || defined(_M_ARM) || \
37-
defined(_M_ARMT) || defined(__aarch64__)
37+
defined(_M_ARMT) || defined(__aarch64__) || defined(_M_ARM64)
3838
#define UTILS_SYSTEM_ARM 1
3939
#elif defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || \
4040
defined(_M_X64)

modules/utils/targets/host/source/relocations.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@
4242
extern "C" {
4343

4444
// Windows uses chkstk() to ensure there is enough stack space paged in.
45-
#if defined(_MSC_VER)
45+
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
46+
#if defined(_MSC_VER) || !defined(UTILS_SYSTEM_X86)
4647
#if defined(UTILS_SYSTEM_64_BIT)
4748
extern void __chkstk();
4849
#else
4950
extern void _chkstk();
50-
#endif
51-
#endif // _MSC_VER
52-
53-
#if defined(__MINGW32__) || defined(__MINGW64__)
51+
#endif // UTILS_SYSTEM_64_BIT
52+
#else // _MSC_VER || !UTILS_SYSTEM_X86
5453
#if defined(UTILS_SYSTEM_64_BIT)
5554
extern void ___chkstk_ms();
5655
#else
5756
extern void(_alloca)();
58-
#endif
59-
#endif
57+
#endif // UTILS_SYSTEM_64_BIT
58+
#endif // _MSC_VER || !UTILS_SYSTEM_X86
59+
#endif // _MSC_VER || __MINGW32__ || __MINGW64__
6060

6161
#if defined(UTILS_SYSTEM_32_BIT)
6262
// On 32-bit (both x86 and Arm) long division is done in software.
@@ -165,21 +165,21 @@ std::vector<std::pair<std::string, uint64_t>> getRelocations() {
165165
#endif // NDEBUG
166166
{"memmove", reinterpret_cast<uint64_t>(&memmove)},
167167

168-
#if defined(_MSC_VER)
168+
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
169+
#if defined(_MSC_VER) || !defined(UTILS_SYSTEM_X86)
169170
#if defined(UTILS_SYSTEM_64_BIT)
170171
{"__chkstk", reinterpret_cast<uint64_t>(&__chkstk)},
171172
#else
172173
{"_chkstk", reinterpret_cast<uint64_t>(&_chkstk)},
173174
#endif // UTILS_SYSTEM_64_BIT
174-
#endif // _MSC_VER
175-
176-
#if defined(__MINGW32__) || defined(__MINGW64__)
175+
#else // _MSC_VER || !UTILS_SYSTEM_X86
177176
#if defined(UTILS_SYSTEM_64_BIT)
178177
{"___chkstk_ms", reinterpret_cast<uint64_t>(&___chkstk_ms)},
179178
#else
180179
{"_alloca", reinterpret_cast<uint64_t>(&_alloca)},
181180
#endif // UTILS_SYSTEM_64_BIT
182-
#endif // _MSC_VER
181+
#endif // _MSC_VER || !UTILS_SYSTEM_X86
182+
#endif // _MSC_VER || __MINGW32__ || __MINGW64__
183183

184184
#if defined(UTILS_SYSTEM_32_BIT)
185185
{"__divdi3", reinterpret_cast<uint64_t>(&__divdi3)},

0 commit comments

Comments
 (0)