Skip to content

Commit 7a8cf95

Browse files
committed
AArch64-Darwin: allow -mcmodel=large with (default) PIC
Darwin targets implement -mcmodel=large by forcing all global accesses to use the GOT, instead of the ELF movz/movk sequence. That means it's compatible with PIC so the Clang driver shouldn't reject the option.
1 parent 708ce85 commit 7a8cf95

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5882,7 +5882,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
58825882
CM = "large";
58835883
if (Triple.isAArch64(64)) {
58845884
Ok = CM == "tiny" || CM == "small" || CM == "large";
5885-
if (CM == "large" && RelocationModel != llvm::Reloc::Static)
5885+
if (CM == "large" && !Triple.isOSBinFormatMachO() &&
5886+
RelocationModel != llvm::Reloc::Static)
58865887
D.Diag(diag::err_drv_argument_only_allowed_with)
58875888
<< A->getAsString(Args) << "-fno-pic";
58885889
} else if (Triple.isLoongArch()) {

clang/test/Driver/mcmodel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// RUN: FileCheck --check-prefix=AIX-MCMEDIUM-OVERRIDE %s < %t.log
1212
// RUN: not %clang -### -c -mcmodel=lager %s 2>&1 | FileCheck --check-prefix=INVALID %s
1313
// RUN: %clang --target=aarch64 -### -S -mcmodel=large -fno-pic %s 2>&1 | FileCheck --check-prefix=LARGE %s
14+
// RUN: %clang --target=aarch64-apple-macosx -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
1415
// RUN: not %clang --target=aarch64 -### -S -mcmodel=large -fpic %s 2>&1 | FileCheck --check-prefix=AARCH64-PIC-LARGE %s
1516
// RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s
1617
// RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s

0 commit comments

Comments
 (0)