diff --git a/0018-Driver-Support-mcmodel-for-LoongArch-72514.patch b/0018-Driver-Support-mcmodel-for-LoongArch-72514.patch new file mode 100644 index 0000000000000000000000000000000000000000..35647eddf7abeecd91f4d1a800e3b8cad73128bd --- /dev/null +++ b/0018-Driver-Support-mcmodel-for-LoongArch-72514.patch @@ -0,0 +1,111 @@ +From 2cdfabe66e345304bf05e54a0127b65bc26ce8f5 Mon Sep 17 00:00:00 2001 +From: Lu Weining +Date: Thu, 30 Nov 2023 14:08:45 +0800 +Subject: [PATCH] [Driver] Support -mcmodel= for LoongArch (#72514) + +7e42545 rejects unsupported mcmodel options, but normal/medium/extreme +should be supported models for LoongArch according to [gcc +document](https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html). + +The mappings among `gcc`, `clang driver`, `clang cc1` and `LLVM (i.e. +llc --code-model=)` are: + +| gcc | clang driver | clang cc1 | LLVM | +| ------------- | ------------------ | ----------------- | -------------- | +| normal | normal | small | small | +| medium | medium | medium | medium | +| extreme | extreme | large | large | + +(cherry picked from commit 1296d20adfb0978afe38d67efab9818079d870ca) + +Change-Id: I45837ad55bfedaf33a7fc9bc40a654a37694ced0 +--- + clang/lib/Driver/ToolChains/Clang.cpp | 38 ++++++++++++++++++++------- + clang/test/Driver/mcmodel.c | 15 +++++++++++ + 2 files changed, 44 insertions(+), 9 deletions(-) + +diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp +index 777e21af98df..dd989c25567e 100644 +--- a/clang/lib/Driver/ToolChains/Clang.cpp ++++ b/clang/lib/Driver/ToolChains/Clang.cpp +@@ -5663,18 +5663,38 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, + + if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { + StringRef CM = A->getValue(); +- if (CM == "small" || CM == "kernel" || CM == "medium" || CM == "large" || +- CM == "tiny") { +- if (Triple.isOSAIX() && CM == "medium") +- CmdArgs.push_back("-mcmodel=large"); +- else if (Triple.isAArch64() && (CM == "kernel" || CM == "medium")) ++ if (Triple.isLoongArch()) { ++ bool Ok = false; ++ if (CM == "extreme" && ++ Args.hasFlagNoClaim(options::OPT_fplt, options::OPT_fno_plt, false)) ++ D.Diag(diag::err_drv_argument_not_allowed_with) ++ << A->getAsString(Args) << "-fplt"; ++ Ok = CM == "normal" || CM == "medium" || CM == "extreme"; ++ // Convert to LLVM recognizable names. ++ if (Ok) { ++ CM = llvm::StringSwitch(CM) ++ .Case("normal", "small") ++ .Case("extreme", "large") ++ .Default(CM); ++ CmdArgs.push_back(Args.MakeArgString("-mcmodel=" + CM)); ++ } else { + D.Diag(diag::err_drv_invalid_argument_to_option) + << CM << A->getOption().getName(); +- else +- A->render(Args, CmdArgs); ++ } + } else { +- D.Diag(diag::err_drv_invalid_argument_to_option) +- << CM << A->getOption().getName(); ++ if (CM == "small" || CM == "kernel" || CM == "medium" || CM == "large" || ++ CM == "tiny") { ++ if (Triple.isOSAIX() && CM == "medium") ++ CmdArgs.push_back("-mcmodel=large"); ++ else if (Triple.isAArch64() && (CM == "kernel" || CM == "medium")) ++ D.Diag(diag::err_drv_invalid_argument_to_option) ++ << CM << A->getOption().getName(); ++ else ++ A->render(Args, CmdArgs); ++ } else { ++ D.Diag(diag::err_drv_invalid_argument_to_option) ++ << CM << A->getOption().getName(); ++ } + } + } + +diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c +index 63b432036159..4aada126cf06 100644 +--- a/clang/test/Driver/mcmodel.c ++++ b/clang/test/Driver/mcmodel.c +@@ -8,6 +8,14 @@ + // RUN: not %clang -c -mcmodel=lager %s 2>&1 | FileCheck --check-prefix=INVALID %s + // RUN: not %clang -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AARCH64-MEDIUM %s + // RUN: not %clang -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AARCH64-KERNEL %s ++// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s ++// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s ++// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-TINY %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-SMALL %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-KERNEL %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=large %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-LARGE %s ++// RUN: not %clang -c --target=loongarch64 -mcmodel=extreme -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s + + // TINY: "-mcmodel=tiny" + // SMALL: "-mcmodel=small" +@@ -20,3 +28,10 @@ + + // AARCH64-MEDIUM: error: invalid argument 'medium' to -mcmodel= + // AARCH64-KERNEL: error: invalid argument 'kernel' to -mcmodel= ++ ++// ERR-LOONGARCH64-TINY: error: invalid argument 'tiny' to -mcmodel= ++// ERR-LOONGARCH64-SMALL: error: invalid argument 'small' to -mcmodel= ++// ERR-LOONGARCH64-KERNEL: error: invalid argument 'kernel' to -mcmodel= ++// ERR-LOONGARCH64-LARGE: error: invalid argument 'large' to -mcmodel= ++ ++// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt' +-- +2.20.1 + diff --git a/clang.spec b/clang.spec index fbfeac9525bc5ee66be4118097d336657a1a01b4..95c1def2f9a7c212c07860e34e093e4249e52d37 100644 --- a/clang.spec +++ b/clang.spec @@ -1,4 +1,4 @@ -%define anolis_release 4 +%define anolis_release 5 %global toolchain clang @@ -70,6 +70,7 @@ Patch27: 0014-LoongArch-Fix-ABI-mismatch-with-g-when-handling-empt.patch Patch28: 0015-Driver-Default-LoongArch-to-fno-direct-access-extern.patch Patch29: 0016-Clang-LoongArch-Precommit-test-for-fix-wrong-return-.patch Patch30: 0017-Clang-LoongArch-Fix-wrong-return-value-type-of-__ioc.patch +Patch31: 0018-Driver-Support-mcmodel-for-LoongArch-72514.patch # Patches for clang-tools-extra # See https://reviews.llvm.org/D120301 @@ -492,6 +493,9 @@ LD_LIBRARY_PATH=%{buildroot}/%{_libdir} %{__ninja} check-all -C %{__cmake_buildd %{python3_sitelib}/clang/ %changelog +* Wed Oct 23 2024 Chen Li - 17.0.6-5 +- LoongArch Backport: Modify -mcmodel options to be consistent with GCC + * Tue Apr 9 2024 Chen Li - 17.0.6-4 - LoongArch Backport: Add the support for vector(LSX/LASX) - LoongArch Backport: Support -fsanitize=cfi-icall