Index: lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- lib/Driver/ToolChains/CommonArgs.cpp +++ lib/Driver/ToolChains/CommonArgs.cpp @@ -973,12 +973,25 @@ if ((ROPI || RWPI) && (PIC || PIE)) ToolChain.getDriver().Diag(diag::err_drv_ropi_rwpi_incompatible_with_pic); - // When targettng MIPS64 with N64, the default is PIC, unless -mno-abicalls is - // used. - if ((Triple.getArch() == llvm::Triple::mips64 || - Triple.getArch() == llvm::Triple::mips64el) && - Args.hasArg(options::OPT_mno_abicalls)) - return std::make_tuple(llvm::Reloc::Static, 0U, false); + if (Triple.getArch() == llvm::Triple::mips || + Triple.getArch() == llvm::Triple::mipsel || + Triple.getArch() == llvm::Triple::mips64 || + Triple.getArch() == llvm::Triple::mips64el) { + + StringRef CPUName; + StringRef ABIName; + mips::getMipsCPUAndABI(Args, Triple, CPUName, ABIName); + // For n64 ABI, PIC is always true, except in case when -mno-abicalls + // option is used. And we exit at next check if that's true, + // regardless of PIC being set below. + if (ABIName == "n64") + PIC = true; + // When targettng MIPS with -mno-abicalls, it's always static. + if(Args.hasArg(options::OPT_mno_abicalls)) + return std::make_tuple(llvm::Reloc::Static, 0U, false); + // It's never PIC level 2 for mips. + IsPICLevelTwo = false; + } if (PIC) return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE); Index: test/Driver/mips-as.c =================================================================== --- test/Driver/mips-as.c +++ test/Driver/mips-as.c @@ -21,7 +21,7 @@ // MIPS32R2-DEF-EL-AS: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EL" // // RUN: %clang -target mips64-linux-gnu -### \ -// RUN: -no-integrated-as -fno-pic -c %s 2>&1 \ +// RUN: -no-integrated-as -fno-pic -mno-abicalls -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS64R2-EB-AS %s // MIPS64R2-EB-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-EB" // @@ -31,7 +31,7 @@ // MIPS64R2-EB-AS-PIC: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EB" "-KPIC" // // RUN: %clang -target mips64el-linux-gnu -### \ -// RUN: -no-integrated-as -c -fno-pic %s 2>&1 \ +// RUN: -no-integrated-as -c -fno-pic -mno-abicalls %s 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS64R2-DEF-EL-AS %s // MIPS64R2-DEF-EL-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-EL" // @@ -64,7 +64,7 @@ // MIPS64R2-EL-AS-PIC: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EL" "-KPIC" // // RUN: %clang -target mips64el-linux-gnu -mabi=64 -### \ -// RUN: -no-integrated-as -c %s -fno-pic 2>&1 \ +// RUN: -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS64R2-EL-AS %s // MIPS64R2-EL-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-EL" // @@ -84,7 +84,7 @@ // MIPS-OCTEON-PIC: as{{(.exe)?}}" "-march" "octeon" "-mabi" "64" "-EB" "-KPIC" // // RUN: %clang -target mips64-linux-gnu -march=octeon -### \ -// RUN: -no-integrated-as -c %s -fno-pic 2>&1 \ +// RUN: -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS-OCTEON %s // MIPS-OCTEON: as{{(.exe)?}}" "-march" "octeon" "-mabi" "64" "-mno-shared" "-EB" // @@ -144,7 +144,7 @@ // MIPS-ALIAS-64-PIC: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-EB" "-KPIC" // // RUN: %clang -target mips64-linux-gnu -mips64 -### \ -// RUN: -no-integrated-as -c -fno-pic %s 2>&1 \ +// RUN: -no-integrated-as -c -fno-pic -mno-abicalls %s 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS-ALIAS-64 %s // MIPS-ALIAS-64: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-mno-shared" "-EB" // @@ -159,7 +159,7 @@ // MIPS-ALIAS-64R3-PIC: as{{(.exe)?}}" "-march" "mips64r3" "-mabi" "64" "-EB" "-KPIC" // // RUN: %clang -target mips64-linux-gnu -mips64r3 -### \ -// RUN: -no-integrated-as -c %s -fno-pic 2>&1 \ +// RUN: -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS-ALIAS-64R3 %s // MIPS-ALIAS-64R3: as{{(.exe)?}}" "-march" "mips64r3" "-mabi" "64" "-mno-shared" "-EB" // @@ -169,7 +169,7 @@ // MIPS-ALIAS-64R5-PIC: as{{(.exe)?}}" "-march" "mips64r5" "-mabi" "64" "-EB" "-KPIC" // // RUN: %clang -target mips64-linux-gnu -mips64r5 -### \ -// RUN: -no-integrated-as -c %s -fno-pic 2>&1 \ +// RUN: -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS-ALIAS-64R5 %s // MIPS-ALIAS-64R5: as{{(.exe)?}}" "-march" "mips64r5" "-mabi" "64" "-mno-shared" "-EB" // @@ -179,7 +179,7 @@ // MIPS-ALIAS-64R6-PIC: as{{(.exe)?}}" "-march" "mips64r6" "-mabi" "64" "-EB" "-KPIC" // // RUN: %clang -target mips64-linux-gnu -mips64r6 -### \ -// RUN: -no-integrated-as -c %s -fno-pic 2>&1 \ +// RUN: -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \ // RUN: | FileCheck -check-prefix=MIPS-ALIAS-64R6 %s // MIPS-ALIAS-64R6: as{{(.exe)?}}" "-march" "mips64r6" "-mabi" "64" "-mno-shared" "-EB" // Index: test/Driver/mips-features.c =================================================================== --- test/Driver/mips-features.c +++ test/Driver/mips-features.c @@ -11,7 +11,7 @@ // CHECK-MNOABICALLS: "-target-feature" "+noabicalls" // // -mno-abicalls non-PIC N64 -// RUN: %clang -target mips64-linux-gnu -### -c -fno-PIC %s 2>&1 \ +// RUN: %clang -target mips64-linux-gnu -### -c -fno-PIC -mno-abicalls %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-MNOABICALLS-N64NPIC %s // CHECK-MNOABICALLS-N64NPIC: "-target-feature" "+noabicalls" // @@ -86,13 +86,13 @@ // CHECK-MEMBEDDEDDATADEF-NOT: "-mllvm" "-membedded-data" // // MIPS64 + N64: -fno-pic -> -mno-abicalls -mgpopt -// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic 2>&1 \ +// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic -mno-abicalls 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-N64-GPOPT %s // CHECK-N64-GPOPT: "-target-feature" "+noabicalls" // CHECK-N64-GPOPT: "-mllvm" "-mgpopt" // // MIPS64 + N64: -fno-pic -mno-gpopt -// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic -mno-gpopt 2>&1 \ +// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic -mno-abicalls -mno-gpopt 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-N64-MNO-GPOPT %s // CHECK-N64-MNO-GPOPT: "-target-feature" "+noabicalls" // CHECK-N64-MNO-GPOPT-NOT: "-mllvm" "-mgpopt" Index: test/Driver/pic.c =================================================================== --- test/Driver/pic.c +++ test/Driver/pic.c @@ -292,9 +292,9 @@ // RUN: %clang -c %s -target mipsel-linux-android14 -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-PIC1 // RUN: %clang -c %s -target mipsel-linux-android16 -### 2>&1 \ -// RUN: | FileCheck %s --check-prefix=CHECK-PIE2 +// RUN: | FileCheck %s --check-prefix=CHECK-PIE1 // RUN: %clang -c %s -target mipsel-linux-android24 -### 2>&1 \ -// RUN: | FileCheck %s --check-prefix=CHECK-PIE2 +// RUN: | FileCheck %s --check-prefix=CHECK-PIE1 // // 64-bit Android targets are always PIE. // RUN: %clang -c %s -target aarch64-linux-android -### 2>&1 \