Skip to content

Commit 34e3230

Browse files
authored
Merge pull request #3478 from kinke/darwin_asm
Fix naked DMD-style asm emission for non-Mac x86 Darwin targets & add prebuilt druntime/Phobos for iOS/x86_64 to macOS package
2 parents c20ed9a + e8ddb14 commit 34e3230

File tree

7 files changed

+107
-55
lines changed

7 files changed

+107
-55
lines changed

.azure-pipelines/posix.yml

+44-12
Original file line numberDiff line numberDiff line change
@@ -267,35 +267,48 @@ steps:
267267
displayName: 'Android: Cross-compile x86 libraries and copy to install dir'
268268
condition: and(succeeded(), eq(variables['CI_OS'], 'android'))
269269

270-
# Mac: add iOS/arm64 libraries
270+
# Mac: add iOS libraries (arm64 and x86_64)
271271
- script: |
272272
set -ex
273273
cd ..
274274
export PATH="$PWD/ninja:$PATH"
275-
triple="arm64-apple-ios$IOS_DEPLOYMENT_TARGET"
276-
# TODO: shared libs too, and look into `-fvisibility=hidden` requirement
275+
triple_arm64="arm64-apple-ios$IOS_DEPLOYMENT_TARGET"
276+
triple_x64="x86_64-apple-ios$IOS_DEPLOYMENT_TARGET"
277+
# TODO: build shared libs too, and look into `-fvisibility=hidden` requirement
277278
build/bin/ldc-build-runtime --ninja -j $PARALLEL_JOBS \
278279
--buildDir=build-libs-arm64 \
279-
--cFlags="-target;$triple" \
280-
--dFlags="-mtriple=$triple;-fvisibility=hidden" \
280+
--cFlags="-target;$triple_arm64" \
281+
--dFlags="-mtriple=$triple_arm64;-fvisibility=hidden" \
281282
--ldcSrcDir=$BUILD_SOURCESDIRECTORY \
282283
CMAKE_SYSTEM_NAME=iOS \
283284
CMAKE_OSX_ARCHITECTURES=arm64 \
284285
CMAKE_OSX_DEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
285286
BUILD_SHARED_LIBS=OFF \
286287
BUILD_LTO_LIBS=ON
287-
mkdir installed/lib-ios-arm64
288+
build/bin/ldc-build-runtime --ninja -j $PARALLEL_JOBS \
289+
--buildDir=build-libs-x86_64 \
290+
--cFlags="-target;$triple_x64" \
291+
--dFlags="-mtriple=$triple_x64;-fvisibility=hidden" \
292+
--ldcSrcDir=$BUILD_SOURCESDIRECTORY \
293+
CMAKE_SYSTEM_NAME=iOS \
294+
CMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \
295+
CMAKE_OSX_ARCHITECTURES=x86_64 \
296+
CMAKE_OSX_DEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
297+
BUILD_SHARED_LIBS=OFF \
298+
BUILD_LTO_LIBS=ON
299+
mkdir installed/lib-ios-{arm64,x86_64}
288300
cp build-libs-arm64/lib/*.a installed/lib-ios-arm64
289-
rm installed/lib-ios-arm64/*-lto-debug.a
290-
section="
301+
cp build-libs-x86_64/lib/*.a installed/lib-ios-x86_64
302+
rm installed/lib-ios-{arm64,x86_64}/*-lto-debug.a
303+
sections="
291304
\"arm64-apple-ios\":
292305
{
293306
switches = [
294307
\"-defaultlib=phobos2-ldc,druntime-ldc\",
295308
\"-link-defaultlib-shared=false\",
296309
\"-fvisibility=hidden\",
297310
\"-Xcc=-target\",
298-
\"-Xcc=$triple\",
311+
\"-Xcc=$triple_arm64\",
299312
\"-Xcc=-miphoneos-version-min=$IOS_DEPLOYMENT_TARGET\",
300313
\"-Xcc=-isysroot\",
301314
\"-Xcc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk\",
@@ -304,10 +317,28 @@ steps:
304317
\"%%ldcbinarypath%%/../lib-ios-arm64\",
305318
];
306319
rpath = \"%%ldcbinarypath%%/../lib-ios-arm64\";
320+
};
321+
322+
\"x86_64-apple-ios\":
323+
{
324+
switches = [
325+
\"-defaultlib=phobos2-ldc,druntime-ldc\",
326+
\"-link-defaultlib-shared=false\",
327+
\"-fvisibility=hidden\",
328+
\"-Xcc=-target\",
329+
\"-Xcc=$triple_x64\",
330+
\"-Xcc=-miphoneos-version-min=$IOS_DEPLOYMENT_TARGET\",
331+
\"-Xcc=-isysroot\",
332+
\"-Xcc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk\",
333+
];
334+
lib-dirs = [
335+
\"%%ldcbinarypath%%/../lib-ios-x86_64\",
336+
];
337+
rpath = \"%%ldcbinarypath%%/../lib-ios-x86_64\";
307338
};"
308-
echo "$section" >> installed/etc/ldc2.conf
339+
echo "$sections" >> installed/etc/ldc2.conf
309340
cat installed/etc/ldc2.conf
310-
displayName: 'Mac: Cross-compile iOS/arm64 libraries, copy to install dir and extend ldc2.conf'
341+
displayName: 'Mac: Cross-compile iOS libraries (arm64 and x86_64), copy to install dir and extend ldc2.conf'
311342
condition: and(succeeded(), eq(variables['CI_OS'], 'osx'))
312343

313344
# Integration tests
@@ -326,7 +357,8 @@ steps:
326357
- script: |
327358
set -ex
328359
cd ..
329-
installed/bin/ldc2 -mtriple="arm64-apple-ios$IOS_DEPLOYMENT_TARGET" hello.d -of=hello_ios
360+
installed/bin/ldc2 -mtriple="arm64-apple-ios$IOS_DEPLOYMENT_TARGET" hello.d -of=hello_ios_arm64
361+
installed/bin/ldc2 -mtriple="x86_64-apple-ios$IOS_DEPLOYMENT_TARGET" hello.d -of=hello_ios_x86_64
330362
displayName: 'Mac: Cross-compile & -link hello-world for iOS'
331363
condition: and(succeeded(), eq(variables['CI_OS'], 'osx'))
332364
- script: |

bitrise.yml

+25-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,30 @@ workflows:
5858
envman add --key LDC_BINARY --value "$(pwd)/bin/ldc2"
5959
6060
- script@1.1.6:
61-
title: Build Runtime
61+
title: Cross-compile (iOS/x86_64) druntime & Phobos
62+
deps:
63+
brew:
64+
- name: cmake
65+
- name: ninja
66+
inputs:
67+
- content: |-
68+
#!/bin/bash
69+
set -ex
70+
build/bin/ldc-build-runtime \
71+
--buildDir="ldc-build-runtime.x86_64" \
72+
--cFlags="-target;x86_64-apple-ios${IOS_VERSION}" \
73+
--dFlags="-mtriple=x86_64-apple-ios${IOS_VERSION};-fvisibility=hidden" \
74+
--ldcSrcDir=. \
75+
--ninja \
76+
-j 2 \
77+
CMAKE_SYSTEM_NAME=iOS \
78+
CMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \
79+
CMAKE_OSX_ARCHITECTURES=x86_64 \
80+
CMAKE_OSX_DEPLOYMENT_TARGET="${IOS_VERSION}" \
81+
BUILD_SHARED_LIBS=OFF
82+
83+
- script@1.1.6:
84+
title: Cross-compile (iOS/arm64) druntime & Phobos, incl. debug unittest runners
6285
deps:
6386
brew:
6487
- name: cmake
@@ -86,7 +109,7 @@ workflows:
86109
run_if: not .IsPR
87110

88111
- virtual-device-testing-for-ios@0.9.10:
89-
title: Run Tests on Device
112+
title: Run druntime & Phobos debug unittests on iPhone
90113
run_if: not .IsPR
91114
inputs:
92115
- test_devices: iphone6s,12.0,en,portrait

driver/linker-gcc.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ void ArgsBuilder::addCppStdlibLinkFlags(const llvm::Triple &triple) {
418418
break;
419419
case llvm::Triple::Darwin:
420420
case llvm::Triple::MacOSX:
421+
case llvm::Triple::IOS:
422+
case llvm::Triple::WatchOS:
423+
case llvm::Triple::TvOS:
421424
case llvm::Triple::FreeBSD:
422425
args.push_back("-lc++");
423426
break;

driver/targetmachine.cpp

+24-28
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,7 @@ static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU) {
248248

249249
static FloatABI::Type getARMFloatABI(const llvm::Triple &triple,
250250
const char *llvmArchSuffix) {
251-
switch (triple.getOS()) {
252-
case llvm::Triple::Darwin:
253-
case llvm::Triple::MacOSX:
254-
case llvm::Triple::IOS: {
251+
if (triple.isOSDarwin()) {
255252
// Darwin defaults to "softfp" for v6 and v7.
256253
if (llvm::StringRef(llvmArchSuffix).startswith("v6") ||
257254
llvm::StringRef(llvmArchSuffix).startswith("v7")) {
@@ -260,35 +257,34 @@ static FloatABI::Type getARMFloatABI(const llvm::Triple &triple,
260257
return FloatABI::Soft;
261258
}
262259

263-
case llvm::Triple::FreeBSD:
260+
if (triple.isOSFreeBSD()) {
264261
// FreeBSD defaults to soft float
265262
return FloatABI::Soft;
263+
}
266264

267-
default:
268-
if (triple.getVendorName().startswith("hardfloat"))
269-
return FloatABI::Hard;
270-
if (triple.getVendorName().startswith("softfloat"))
271-
return FloatABI::SoftFP;
272-
273-
switch (triple.getEnvironment()) {
274-
case llvm::Triple::GNUEABIHF:
275-
return FloatABI::Hard;
276-
case llvm::Triple::GNUEABI:
277-
return FloatABI::SoftFP;
278-
case llvm::Triple::EABI:
279-
// EABI is always AAPCS, and if it was not marked 'hard', it's softfp
265+
if (triple.getVendorName().startswith("hardfloat"))
266+
return FloatABI::Hard;
267+
if (triple.getVendorName().startswith("softfloat"))
268+
return FloatABI::SoftFP;
269+
270+
switch (triple.getEnvironment()) {
271+
case llvm::Triple::GNUEABIHF:
272+
return FloatABI::Hard;
273+
case llvm::Triple::GNUEABI:
274+
return FloatABI::SoftFP;
275+
case llvm::Triple::EABI:
276+
// EABI is always AAPCS, and if it was not marked 'hard', it's softfp
277+
return FloatABI::SoftFP;
278+
case llvm::Triple::Android: {
279+
if (llvm::StringRef(llvmArchSuffix).startswith("v7")) {
280280
return FloatABI::SoftFP;
281-
case llvm::Triple::Android: {
282-
if (llvm::StringRef(llvmArchSuffix).startswith("v7")) {
283-
return FloatABI::SoftFP;
284-
}
285-
return FloatABI::Soft;
286-
}
287-
default:
288-
// Assume "soft".
289-
// TODO: Warn the user we are guessing.
290-
return FloatABI::Soft;
291281
}
282+
return FloatABI::Soft;
283+
}
284+
default:
285+
// Assume "soft".
286+
// TODO: Warn the user we are guessing.
287+
return FloatABI::Soft;
292288
}
293289
}
294290

gen/abi-x86.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
#include "ir/irfuncty.h"
2020

2121
struct X86TargetABI : TargetABI {
22-
const bool isOSX;
22+
const bool isDarwin;
2323
const bool isMSVC;
2424
bool returnStructsInRegs;
2525
IntegerRewrite integerRewrite;
2626
IndirectByvalRewrite indirectByvalRewrite;
2727

2828
X86TargetABI()
29-
: isOSX(global.params.targetTriple->isMacOSX()),
29+
: isDarwin(global.params.targetTriple->isOSDarwin()),
3030
isMSVC(global.params.targetTriple->isWindowsMSVCEnvironment()) {
3131
using llvm::Triple;
3232
auto os = global.params.targetTriple->getOS();
@@ -206,8 +206,8 @@ struct X86TargetABI : TargetABI {
206206

207207
// Clang does not pass empty structs, while it seems that GCC does,
208208
// at least on Linux x86. We don't know whether the C compiler will
209-
// be Clang or GCC, so just assume Clang on OS X and G++ on Linux.
210-
if (externD || !isOSX)
209+
// be Clang or GCC, so just assume Clang on Darwin and G++ on Linux.
210+
if (externD || !isDarwin)
211211
return;
212212

213213
size_t i = 0;
@@ -247,7 +247,7 @@ struct X86TargetABI : TargetABI {
247247

248248
const char *objcMsgSendFunc(Type *ret, IrFuncTy &fty) override {
249249
// see objc/message.h for objc_msgSend selection rules
250-
assert(isOSX);
250+
assert(isDarwin);
251251
if (fty.arg_sret) {
252252
return "objc_msgSend_stret";
253253
}

gen/asm-x86.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -2322,11 +2322,10 @@ struct AsmProcessor {
23222322
// OSX and 32-bit Windows need an extra leading underscore when mangling a
23232323
// symbol name.
23242324
static bool prependExtraUnderscore(LINK link) {
2325-
return global.params.targetTriple->getOS() == llvm::Triple::MacOSX ||
2326-
global.params.targetTriple->getOS() == llvm::Triple::Darwin ||
2325+
const auto &triple = *global.params.targetTriple;
2326+
return triple.isOSDarwin() ||
23272327
// Win32: all symbols except for MSVC++ ones
2328-
(global.params.targetTriple->isOSWindows() &&
2329-
global.params.targetTriple->isArch32Bit() && link != LINKcpp);
2328+
(triple.isOSWindows() && triple.isArch32Bit() && link != LINKcpp);
23302329
}
23312330

23322331
void addOperand(const char *fmt, AsmArgType type, Expression *e,

gen/naked.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,11 @@ void DtoDefineNakedFunction(FuncDeclaration *fd) {
158158

159159
const auto &triple = *global.params.targetTriple;
160160
bool const isWin = triple.isOSWindows();
161-
bool const isOSX = (triple.getOS() == llvm::Triple::Darwin ||
162-
triple.getOS() == llvm::Triple::MacOSX);
161+
bool const isDarwin = triple.isOSDarwin();
163162

164163
// osx is different
165164
// also mangling has an extra underscore prefixed
166-
if (isOSX) {
165+
if (isDarwin) {
167166
fullmangle += '_';
168167
fullmangle += mangle;
169168
mangle = fullmangle.c_str();
@@ -233,7 +232,7 @@ void DtoDefineNakedFunction(FuncDeclaration *fd) {
233232

234233
// emit size after body
235234
// llvm does this on linux, but not on osx or Win
236-
if (!(isWin || isOSX)) {
235+
if (!(isWin || isDarwin)) {
237236
asmstr << "\t.size\t" << mangle << ", .-" << mangle << std::endl
238237
<< std::endl;
239238
}

0 commit comments

Comments
 (0)