On Mon, Jan 26, 2015 at 03:16:31PM -0800, Tim Northover wrote:
> > Well, my optimistic assumption is/was that all systems that care are
> > already supported NetBSD was just missing. So (a) which systems run on
> > ARM-EB at all (b) do they care about BE8 vs BE32 (c) what link flags do
> > they need.
> 
> I think it affects anyone using ld.bfd for big-endian ARM code. The
> ideal behaviour is probably:
> 
> 1. >=v7 (& v6m) code must pass --be8  (CPU only understands BE8 output)
> 2. <=v5 code mustn't pass --be8 (CPU does not understand BE8 output)
> 3. v6 code may or may not. (it's configurable in SCTLR) It probably
> should for neatness, but unfortunately compatibility with GCC probably
> requires us not to.

Well, attached patch implements the above for NetBSD and refactores it
into a function other toolchains can call.

Joerg
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 227088)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -5439,6 +5439,20 @@
     .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<const char *>(Suffix)
+    .Cases("v6m", "v7", "v7r", "v7m", "--be8")
+    .Cases("v7em", "v7s", "v8", "--be8")
+    .Default(nullptr);
+
+  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));
@@ -6902,8 +6916,7 @@
     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:
Index: lib/Driver/Tools.h
===================================================================
--- lib/Driver/Tools.h	(revision 227085)
+++ lib/Driver/Tools.h	(working copy)
@@ -228,6 +228,8 @@
   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 {
Index: test/Driver/netbsd.c
===================================================================
--- test/Driver/netbsd.c	(revision 227088)
+++ test/Driver/netbsd.c	(working copy)
@@ -19,6 +19,9 @@
 // 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 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 +138,13 @@
 // 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: "--be" "-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"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to