Skip to content

Commit 36094d3

Browse files
committed
Android: Default to cortex-a8 CPU for ARMv7-A
Hardcoded instead of pre-setting ldc2.conf for the prebuilt Android packages, and thus simplifying cross-compilation (e.g., issue ldc-developers#3437). Also use `core2` instead of `x86-64` for Android x86_64.
1 parent 4eaa2fd commit 36094d3

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

.azure-pipelines/posix.yml

-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ steps:
137137
chmod 755 llvm-$ARCH/bin/llvm-config
138138
# Set up DFLAGS for cross-compiling/linking with host ldmd2
139139
DFLAGS="-mtriple=$LLVM_TRIPLE -L-L$PWD/ldc-build-runtime.tmp/lib -gcc=$PWD/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/$ARCH-linux-${androidEnv}21-clang"
140-
if [ "$ARCH" = "armv7a" ]; then DFLAGS="$DFLAGS -mcpu=cortex-a8"; fi
141140
set +x
142141
echo "##vso[task.setvariable variable=DFLAGS]$DFLAGS"
143142
displayName: 'Android: Set up cross-compilation'
@@ -159,8 +158,6 @@ steps:
159158
installDir=$PWD/install
160159
mkdir build-$ARCH
161160
cd build-$ARCH
162-
DEFAULT_LDC_SWITCHES=''
163-
if [ "$ARCH" = "armv7a" ]; then DEFAULT_LDC_SWITCHES=" \"-mcpu=cortex-a8\","; fi
164161
IFS=$'\n' extraFlags=( $(xargs -n1 <<<"$EXTRA_CMAKE_FLAGS $EXTRA_CMAKE_FLAGS_ANDROID") )
165162
cmake -G Ninja $BUILD_SOURCESDIRECTORY \
166163
-DCMAKE_BUILD_TYPE=Release \
@@ -169,7 +166,6 @@ steps:
169166
-DCMAKE_INSTALL_PREFIX=$installDir \
170167
-DINCLUDE_INSTALL_DIR=$installDir/import \
171168
-DD_LINKER_ARGS="-L$PWD/../ldc-build-runtime.tmp/lib;-lphobos2-ldc;-ldruntime-ldc" \
172-
-DADDITIONAL_DEFAULT_LDC_SWITCHES="$DEFAULT_LDC_SWITCHES" \
173169
"${extraFlags[@]}"
174170
ninja -j$PARALLEL_JOBS -v ldc2 ldmd2 ldc-build-runtime ldc-profdata ldc-prune-cache
175171
displayName: 'Android: Cross-compile LDC executables'

driver/targetmachine.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ static std::string getX86TargetCPU(const llvm::Triple &triple) {
124124
if (triple.isOSDarwin()) {
125125
return triple.isArch64Bit() ? "core2" : "yonah";
126126
}
127+
128+
// All x86 devices running Android have core2 as their common
129+
// denominator.
130+
if (triple.getEnvironment() == llvm::Triple::Android) {
131+
return "core2";
132+
}
133+
127134
// Everything else goes to x86-64 in 64-bit mode.
128135
if (triple.isArch64Bit()) {
129136
return "x86-64";
@@ -149,18 +156,20 @@ static std::string getX86TargetCPU(const llvm::Triple &triple) {
149156
if (triple.getOSName().startswith("dragonfly")) {
150157
return "i486";
151158
}
152-
// All x86 devices running Android have core2 as their common
153-
// denominator. This makes a better choice than pentium4.
154-
if (triple.getEnvironment() == llvm::Triple::Android) {
155-
return "core2";
156159

157-
// Fallback to p4.
158-
}
160+
// Fallback to p4.
159161
return "pentium4";
160162
}
161163

162164
static std::string getARMTargetCPU(const llvm::Triple &triple) {
163165
auto defaultCPU = llvm::ARM::getDefaultCPU(triple.getArchName());
166+
167+
// 32-bit Android: default to cortex-a8
168+
if (defaultCPU == "generic" &&
169+
triple.getEnvironment() == llvm::Triple::Android) {
170+
return "cortex-a8";
171+
}
172+
164173
if (!defaultCPU.empty())
165174
return std::string(defaultCPU);
166175

@@ -294,8 +303,7 @@ const llvm::Target *lookupTarget(const std::string &arch, llvm::Triple &triple,
294303

295304
if (!target) {
296305
errorMsg = "invalid target architecture '" + arch +
297-
"', see "
298-
"-version for a list of supported targets.";
306+
"', see -version for a list of supported targets.";
299307
return nullptr;
300308
}
301309

0 commit comments

Comments
 (0)