Index: lib/Target/AArch64/AArch64ISelLowering.cpp =================================================================== --- lib/Target/AArch64/AArch64ISelLowering.cpp +++ lib/Target/AArch64/AArch64ISelLowering.cpp @@ -4245,7 +4245,8 @@ SDLoc DL(Op); if (getTargetMachine().getCodeModel() == CodeModel::Large && - !Subtarget->isTargetMachO()) { + !Subtarget->isTargetMachO() && + getTargetMachine().getRelocationModel() != Reloc::PIC_) { const unsigned char MO_NC = AArch64II::MO_NC; return DAG.getNode( AArch64ISD::WrapperLarge, DL, PtrVT, @@ -4271,8 +4272,9 @@ SDLoc DL(Op); if (getTargetMachine().getCodeModel() == CodeModel::Large) { - // Use the GOT for the large code model on iOS. - if (Subtarget->isTargetMachO()) { + // Use the GOT for the large code model on iOS and when doing PIC. + if (Subtarget->isTargetMachO() || + getTargetMachine().getRelocationModel() != Reloc::PIC_) { SDValue GotAddr = DAG.getTargetConstantPool( CP->getConstVal(), PtrVT, CP->getAlignment(), CP->getOffset(), AArch64II::MO_GOT); @@ -4311,7 +4313,8 @@ EVT PtrVT = getPointerTy(DAG.getDataLayout()); SDLoc DL(Op); if (getTargetMachine().getCodeModel() == CodeModel::Large && - !Subtarget->isTargetMachO()) { + !Subtarget->isTargetMachO() && + getTargetMachine().getRelocationModel() != Reloc::PIC_) { const unsigned char MO_NC = AArch64II::MO_NC; return DAG.getNode( AArch64ISD::WrapperLarge, DL, PtrVT, Index: lib/Target/AArch64/AArch64Subtarget.cpp =================================================================== --- lib/Target/AArch64/AArch64Subtarget.cpp +++ lib/Target/AArch64/AArch64Subtarget.cpp @@ -125,6 +125,11 @@ unsigned char AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const { + // Large model would otherwise result in text relocations + if (TM.getCodeModel() == CodeModel::Large + && TM.getRelocationModel() == Reloc::PIC_) + return AArch64II::MO_GOT; + // MachO large model always goes via a GOT, simply to get a single 8-byte // absolute relocation on all global addresses. if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())