[cfe-dev] [PATCH] driver improvements for freebsd-*-mips*

Brooks Davis brooks at freebsd.org
Wed Sep 5 11:23:10 PDT 2012


On Tue, Aug 28, 2012 at 09:25:11AM -0700, Eric Christopher wrote:
> 
> On Aug 28, 2012, at 3:31 AM, Brooks Davis <brooks at freebsd.org> wrote:
> 
> > On Mon, Aug 27, 2012 at 09:52:40AM -0700, Eric Christopher wrote:
> >> On Aug 27, 2012, at 9:48 AM, Brooks Davis <brooks at freebsd.org> wrote:
> >> 
> >>> Any chance I could persuade someone to commit this change?
> >> 
> >> Looks fairly reasonable. Didn't see a test though if you don't mind?
> > 
> > Here you go.  The following diff assumes that mips-as.c is copied to
> > freebsd-mips-as.c before being applied.
> 
> You'll want to attach diffs as attachments and also run svn diff with -uNp
> for unified diffs that include new files.

Here is an updated diff.  I'd prefer that mips-as.c be svn cp'd to
freebsd-mips-as.c so the repository reflects who created the majority of
the contents but I don't know what llvm project policy is and have
attached a diff created with -x -up --show-copies-as-adds.

-- Brooks
-------------- next part --------------
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 163226)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -5131,18 +5131,49 @@ void freebsd::Assemble::ConstructJob(Compilation &
 
   // When building 32-bit code on FreeBSD/amd64, we have to explicitly
   // instruct as in the base system to assemble 32-bit code.
-  if (getToolChain().getArchName() == "i386")
+  if (getToolChain().getArch() == llvm::Triple::x86)
     CmdArgs.push_back("--32");
-
-  if (getToolChain().getArchName() == "powerpc")
+  else if (getToolChain().getArch() == llvm::Triple::ppc)
     CmdArgs.push_back("-a32");
+  else if (getToolChain().getArch() == llvm::Triple::mips ||
+           getToolChain().getArch() == llvm::Triple::mipsel ||
+           getToolChain().getArch() == llvm::Triple::mips64 ||
+           getToolChain().getArch() == llvm::Triple::mips64el) {
+    StringRef CPUName;
+    StringRef ABIName;
+    getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName);
 
-  // Set byte order explicitly
-  if (getToolChain().getArchName() == "mips")
-    CmdArgs.push_back("-EB");
-  else if (getToolChain().getArchName() == "mipsel")
-    CmdArgs.push_back("-EL");
+    CmdArgs.push_back("-march");
+    CmdArgs.push_back(CPUName.data());
 
+    // Convert ABI name to the GNU tools acceptable variant.
+    if (ABIName == "o32")
+      ABIName = "32";
+    else if (ABIName == "n64")
+      ABIName = "64";
+
+    CmdArgs.push_back("-mabi");
+    CmdArgs.push_back(ABIName.data());
+
+    if (getToolChain().getArch() == llvm::Triple::mips ||
+        getToolChain().getArch() == llvm::Triple::mips64)
+      CmdArgs.push_back("-EB");
+    else
+      CmdArgs.push_back("-EL");
+
+    Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
+                                      options::OPT_fpic, options::OPT_fno_pic,
+                                      options::OPT_fPIE, options::OPT_fno_PIE,
+                                      options::OPT_fpie, options::OPT_fno_pie);
+    if (LastPICArg &&
+        (LastPICArg->getOption().matches(options::OPT_fPIC) ||
+         LastPICArg->getOption().matches(options::OPT_fpic) ||
+         LastPICArg->getOption().matches(options::OPT_fPIE) ||
+         LastPICArg->getOption().matches(options::OPT_fpie))) {
+      CmdArgs.push_back("-KPIC");
+    }
+  }
+
   Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
                        options::OPT_Xassembler);
 
Index: test/Driver/freebsd.c
===================================================================
--- test/Driver/freebsd.c	(revision 163139)
+++ test/Driver/freebsd.c	(working copy)
@@ -1,4 +1,4 @@
-// REQUIRES: ppc32-registered-target,ppc64-registered-target
+// REQUIRES: ppc32-registered-target,ppc64-registered-target,mips-registered-target
 // RUN: %clang -ccc-clang-archs powerpc -no-canonical-prefixes \
 // RUN:   -target powerpc-pc-freebsd8 %s    \
 // RUN:   --sysroot=%S/Inputs/basic_freebsd_tree -### 2>&1 \
@@ -43,6 +43,34 @@
 // CHECK-LDFLAGS8: --enable-new-dtags
 // CHECK-LDFLAGS9: --hash-style=both
 // CHECK-LDFLAGS9: --enable-new-dtags
+//
+// Check that we do not pass --hash-style=gnu and --hash-style=both to linker
+// and provide correct path to the dynamic linker for MIPS platforms.
+// Also verify that we tell the assembler to target the right ISA and ABI.
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN:     -target mips-unknown-freebsd10.0 -ccc-clang-archs mips \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS %s
+// CHECK-MIPS: "{{.*}}ld"
+// CHECK-MIPS: "-dynamic-linker" "{{.*}}/libexec/ld-elf.so.1"
+// CHECK-MIPS-NOT: "--hash-style={{gnu|both}}"
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN:     -target mipsel-unknown-freebsd10.0 -ccc-clang-archs mipsel \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPSEL %s
+// CHECK-MIPSEL: "{{.*}}ld"
+// CHECK-MIPSEL: "-dynamic-linker" "{{.*}}/libexec/ld-elf.so.1"
+// CHECK-MIPSEL-NOT: "--hash-style={{gnu|both}}"
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN:     -target mips64-unknown-freebsd10.0 -ccc-clang-archs mips64 \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS64 %s
+// CHECK-MIPS64: "{{.*}}ld"
+// CHECK-MIPS64: "-dynamic-linker" "{{.*}}/libexec/ld-elf.so.1"
+// CHECK-MIPS64-NOT: "--hash-style={{gnu|both}}"
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN:     -target mips64el-unknown-freebsd10.0 -ccc-clang-archs mips64el \
+// RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL %s
+// CHECK-MIPS64EL: "{{.*}}ld"
+// CHECK-MIPS64EL: "-dynamic-linker" "{{.*}}/libexec/ld-elf.so.1"
+// CHECK-MIPS64EL-NOT: "--hash-style={{gnu|both}}"
 
 // RUN: %clang -no-canonical-prefixes -target x86_64-pc-freebsd8 -static %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
Index: test/Driver/freebsd-mips-as.c
===================================================================
--- test/Driver/freebsd-mips-as.c	(revision 0)
+++ test/Driver/freebsd-mips-as.c	(working copy)
@@ -0,0 +1,56 @@
+// Check passing options to the assembler for MIPS targets.
+//
+// RUN: %clang -target mips-unknown-freebsd -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS32-EB-AS %s
+// MIPS32-EB-AS: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EB"
+// MIPS32-EB-AS-NOT: "-KPIC"
+//
+// RUN: %clang -target mips-unknown-freebsd -### \
+// RUN:   -no-integrated-as -fPIC -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS32-EB-PIC %s
+// MIPS32-EB-PIC: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EB"
+// MIPS32-EB-PIC: "-KPIC"
+//
+// RUN: %clang -target mips-unknown-freebsd -### \
+// RUN:   -no-integrated-as -fpic -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS32-EB-PIC-SMALL %s
+// MIPS32-EB-PIC-SMALL: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EB"
+// MIPS32-EB-PIC-SMALL: "-KPIC"
+//
+// RUN: %clang -target mips-unknown-freebsd -### \
+// RUN:   -no-integrated-as -fPIE -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS32-EB-PIE %s
+// MIPS32-EB-PIE: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EB"
+// MIPS32-EB-PIE: "-KPIC"
+//
+// RUN: %clang -target mips-unknown-freebsd -### \
+// RUN:   -no-integrated-as -fpie -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS32-EB-PIE-SMALL %s
+// MIPS32-EB-PIE-SMALL: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EB"
+// MIPS32-EB-PIE-SMALL: "-KPIC"
+//
+// RUN: %clang -target mipsel-unknown-freebsd -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS32-EL-AS %s
+// MIPS32-EL-AS: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-EL"
+//
+// RUN: %clang -target mips64-unknown-freebsd -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS64-EB-AS %s
+// MIPS64-EB-AS: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-EB"
+//
+// RUN: %clang -target mips64el-unknown-freebsd -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS64-EL-AS %s
+// MIPS64-EL-AS: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-EL"
+//
+// RUN: %clang -target mips-unknown-freebsd -mabi=eabi -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-EABI %s
+// MIPS-EABI: as{{(.exe)?}}" "-march" "mips32" "-mabi" "eabi" "-EB"
+//
+// RUN: %clang -target mips64-unknown-freebsd -mabi=n32 -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-N32 %s
+// MIPS-N32: as{{(.exe)?}}" "-march" "mips64" "-mabi" "n32" "-EB"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120905/8bb21c75/attachment.sig>


More information about the cfe-dev mailing list