From 47c6c9f9f086fcb3107bae8df68e78246e1820e4 Mon Sep 17 00:00:00 2001 From: Christof Douma Date: Tue, 28 Feb 2017 09:09:53 +0000 Subject: [PATCH] [ARM] Don't pass -arm-execute-only to cc1as The option -mexecute-only is translated into the backend option -arm-execute-only. But this option only makes sense for the compiler and the assembler does not recognize it. This patch stops clang from passing this option to the assembler. Change-Id: I4f4cb1162c13cfd50a0a36702a4ecab1bc0324ba Review: https://reviews.llvm.org/D30414 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296454 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Arch/ARM.cpp | 37 ++++++++++++++++++---------------- test/Driver/arm-execute-only.c | 4 ++++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/Driver/Arch/ARM.cpp b/lib/Driver/Arch/ARM.cpp index 29adbedecf..d7d58c1f69 100644 --- a/lib/Driver/Arch/ARM.cpp +++ b/lib/Driver/Arch/ARM.cpp @@ -374,25 +374,28 @@ void arm::getARMTargetFeatures(const ToolChain &TC, } // Generate execute-only output (no data access to code sections). - // Supported only on ARMv6T2 and ARMv7 and above. - // Cannot be combined with -mno-movt or -mlong-calls - if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, options::OPT_mno_execute_only)) { - if (A->getOption().matches(options::OPT_mexecute_only)) { - if (getARMSubArchVersionNumber(Triple) < 7 && - llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::AK_ARMV6T2) - D.Diag(diag::err_target_unsupported_execute_only) << Triple.getArchName(); - else if (Arg *B = Args.getLastArg(options::OPT_mno_movt)) - D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args); - // Long calls create constant pool entries and have not yet been fixed up - // to play nicely with execute-only. Hence, they cannot be used in - // execute-only code for now - else if (Arg *B = Args.getLastArg(options::OPT_mlong_calls, options::OPT_mno_long_calls)) { - if (B->getOption().matches(options::OPT_mlong_calls)) + // This only makes sense for the compiler, not for the assembler. + if (!ForAS) { + // Supported only on ARMv6T2 and ARMv7 and above. + // Cannot be combined with -mno-movt or -mlong-calls + if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, options::OPT_mno_execute_only)) { + if (A->getOption().matches(options::OPT_mexecute_only)) { + if (getARMSubArchVersionNumber(Triple) < 7 && + llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::AK_ARMV6T2) + D.Diag(diag::err_target_unsupported_execute_only) << Triple.getArchName(); + else if (Arg *B = Args.getLastArg(options::OPT_mno_movt)) D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args); + // Long calls create constant pool entries and have not yet been fixed up + // to play nicely with execute-only. Hence, they cannot be used in + // execute-only code for now + else if (Arg *B = Args.getLastArg(options::OPT_mlong_calls, options::OPT_mno_long_calls)) { + if (B->getOption().matches(options::OPT_mlong_calls)) + D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args); + } + + CmdArgs.push_back("-backend-option"); + CmdArgs.push_back("-arm-execute-only"); } - - CmdArgs.push_back("-backend-option"); - CmdArgs.push_back("-arm-execute-only"); } } diff --git a/test/Driver/arm-execute-only.c b/test/Driver/arm-execute-only.c index 7010bbc837..a4854485e1 100644 --- a/test/Driver/arm-execute-only.c +++ b/test/Driver/arm-execute-only.c @@ -90,6 +90,9 @@ // RUN: not %clang -target armv8m.main-eabi -mpure-code -mlong-calls %s 2>&1 \ // RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY-LONG-CALLS +// RUN: %clang -target armv7m-eabi -x assembler -mexecute-only %s -c -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY -check-prefix CHECK-NO-EXECUTE-ONLY-ASM + // // CHECK-NO-EXECUTE-ONLY-NOT: "-backend-option" "-arm-execute-only" // CHECK-EXECUTE-ONLY: "-backend-option" "-arm-execute-only" @@ -97,3 +100,4 @@ // CHECK-EXECUTE-ONLY-NOT-SUPPORTED: error: execute only is not supported for the thumbv6m sub-architecture // CHECK-EXECUTE-ONLY-NO-MOVT: error: option '-mexecute-only' cannot be specified with '-mno-movt' // CHECK-EXECUTE-ONLY-LONG-CALLS: error: option '-mexecute-only' cannot be specified with '-mlong-calls' +// CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: '-mexecute-only' -- 2.40.0