From 1689d3f732a410dd6a09961f0e8a9fbe0d62c4ac Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Wed, 28 Jan 2015 23:30:39 +0000 Subject: [PATCH] For the --be8 flag, check explicitly for pre-v7 / pre-v6m cores. Those used the old Big Endian support on ARM and don't need flags. Refactor the logic in a separate common function, which also looks at -march. Add corresponding logic for the Linux toolchain. llvm-svn: 227393 --- clang/lib/Driver/Tools.cpp | 21 +++++++++++++++++++-- clang/lib/Driver/Tools.h | 2 ++ clang/test/Driver/linux-ld.c | 18 ++++++++++++++++++ clang/test/Driver/netbsd.c | 11 ++++++++++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 27ebc8ae5732..a2b494de74c3 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -5445,6 +5445,20 @@ const char *arm::getLLVMArchSuffixForARM(StringRef CPU) { .Default(""); } +void arm::appendEBLinkFlags(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple) { + if (Args.hasArg(options::OPT_r)) + return; + + StringRef Suffix = getLLVMArchSuffixForARM(getARMCPUForMArch(Args, Triple)); + const char *LinkFlag = llvm::StringSwitch(Suffix) + .Cases("v4", "v4t", "v5", "v5e", nullptr) + .Cases("v6", "v6t2", nullptr) + .Default("--be8"); + + if (LinkFlag) + CmdArgs.push_back(LinkFlag); +} + bool mips::hasMipsAbiArg(const ArgList &Args, const char *Value) { Arg *A = Args.getLastArg(options::OPT_mabi_EQ); return A && (A->getValue() == StringRef(Value)); @@ -6908,8 +6922,7 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, break; case llvm::Triple::armeb: case llvm::Triple::thumbeb: - if (!Args.hasArg(options::OPT_r)) - CmdArgs.push_back("--be8"); + arm::appendEBLinkFlags(Args, CmdArgs, getToolChain().getTriple()); CmdArgs.push_back("-m"); switch (getToolChain().getTriple().getEnvironment()) { case llvm::Triple::EABI: @@ -7460,6 +7473,10 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_s)) CmdArgs.push_back("-s"); + if (ToolChain.getArch() == llvm::Triple::armeb || + ToolChain.getArch() == llvm::Triple::thumbeb) + arm::appendEBLinkFlags(Args, CmdArgs, getToolChain().getTriple()); + for (const auto &Opt : ToolChain.ExtraOpts) CmdArgs.push_back(Opt.c_str()); diff --git a/clang/lib/Driver/Tools.h b/clang/lib/Driver/Tools.h index 6647f39ce817..5aea8258d251 100644 --- a/clang/lib/Driver/Tools.h +++ b/clang/lib/Driver/Tools.h @@ -228,6 +228,8 @@ namespace arm { const char* getARMCPUForMArch(const llvm::opt::ArgList &Args, const llvm::Triple &Triple); const char* getLLVMArchSuffixForARM(StringRef CPU); + + void appendEBLinkFlags(const llvm::opt::ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple); } namespace mips { diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index bde682976e81..b431b1c7489c 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -1412,3 +1412,21 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>& 1 \ // RUN: | FileCheck --check-prefix=CHECK-u %s // CHECK-u: "-u" "asdf" + +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=armeb-unknown-linux \ +// RUN: --gcc-toolchain="" \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-ARMEB %s +// CHECK-ARMEB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" +// CHECK-ARMEB-NOT: "--be8" +// CHECK-ARMEB: "-m" "armebelf_linux_eabi" + +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=armebv7-unknown-linux \ +// RUN: --gcc-toolchain="" \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-ARMV7EB %s +// CHECK-ARMV7EB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" +// CHECK-ARMV7EB: "--be8" +// CHECK-ARMV7EB: "-m" "armebelf_linux_eabi" diff --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c index 26d6483c057f..612935d9819e 100644 --- a/clang/test/Driver/netbsd.c +++ b/clang/test/Driver/netbsd.c @@ -19,6 +19,12 @@ // RUN: %clang -no-canonical-prefixes -target armeb--netbsd-eabi \ // RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=ARMEB %s +// RUN: %clang -no-canonical-prefixes -target armeb--netbsd-eabi -march=armv7 \ +// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=ARMV7EB %s +// RUN: %clang -no-canonical-prefixes -target armv7eb--netbsd-eabi \ +// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=ARMV7EB %s // RUN: %clang -r -no-canonical-prefixes -target armeb--netbsd-eabi \ // RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=ARMEB-R %s @@ -135,11 +141,14 @@ // ARMEB: clang{{.*}}" "-cc1" "-triple" "armebv5e--netbsd-eabi" // ARMEB: as{{.*}}" "-mcpu=arm926ej-s" "-o" // ARMEB: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so" -// ARMEB: "--be8" "-m" "armelfb_nbsd_eabi" +// ARMEB-NOT: "--be8" +// ARMEB: "-m" "armelfb_nbsd_eabi" // ARMEB: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" // ARMEB: "{{.*}}/usr/lib{{/|\\\\}}eabi{{/|\\\\}}crti.o" // ARMEB: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc" // ARMEB: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o" +// ARMV7EB: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so" +// ARMV7EB: "--be8" "-m" "armelfb_nbsd_eabi" // ARMEB-R: ld{{.*}}" // ARMEB-R-NOT: "--be8"