[PATCH] Use dwarf-2 by default on OpenBSD and FreeBSD

Brad Smith brad at comstyle.com
Wed Jun 11 22:30:57 PDT 2014


Here is a patch inspired by a patch I noticed in the FreeBSD LLVM tree to
utilize dwarf-2 by default on OpenBSD and FreeBSD.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-------------- next part --------------
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 210749)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -2885,8 +2885,10 @@
       // FIXME: we should support specifying dwarf version with
       // -gline-tables-only.
       CmdArgs.push_back("-gline-tables-only");
-      // Default is dwarf-2 for darwin.
-      if (getToolChain().getTriple().isOSDarwin())
+      // Default is dwarf-2 for Darwin, OpenBSD and FreeBSD.
+      const llvm::Triple &Triple = getToolChain().getTriple();
+      if (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::OpenBSD ||
+          Triple.getOS() == llvm::Triple::FreeBSD)
         CmdArgs.push_back("-gdwarf-2");
     } else if (A->getOption().matches(options::OPT_gdwarf_2))
       CmdArgs.push_back("-gdwarf-2");
@@ -2896,8 +2898,10 @@
       CmdArgs.push_back("-gdwarf-4");
     else if (!A->getOption().matches(options::OPT_g0) &&
              !A->getOption().matches(options::OPT_ggdb0)) {
-      // Default is dwarf-2 for darwin.
-      if (getToolChain().getTriple().isOSDarwin())
+      // Default is dwarf-2 for Darwin, OpenBSD and FreeBSD.
+      const llvm::Triple &Triple = getToolChain().getTriple();
+      if (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::OpenBSD ||
+          Triple.getOS() == llvm::Triple::FreeBSD)
         CmdArgs.push_back("-gdwarf-2");
       else
         CmdArgs.push_back("-g");
Index: test/CodeGen/dwarf-version.c
===================================================================
--- test/CodeGen/dwarf-version.c	(revision 210749)
+++ test/CodeGen/dwarf-version.c	(working copy)
@@ -1,14 +1,14 @@
-// RUN: %clang -target x86_64-linux-gnu -gdwarf-2 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu -gdwarf-2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER2
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-3 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER3
 // RUN: %clang -target x86_64-linux-gnu -gdwarf-4 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER4
-// RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LINUX
-// RUN: %clang -target x86_64-apple-darwin -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=DARWIN
+// RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER4
+// RUN: %clang -target x86_64-apple-darwin -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER2
+// RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER2
+// RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER2
 int main (void) {
   return 0;
 }
 
-// CHECK: metadata !{i32 2, metadata !"Dwarf Version", i32 2}
+// VER2: metadata !{i32 2, metadata !"Dwarf Version", i32 2}
 // VER3: metadata !{i32 2, metadata !"Dwarf Version", i32 3}
 // VER4: metadata !{i32 2, metadata !"Dwarf Version", i32 4}
-// LINUX: metadata !{i32 2, metadata !"Dwarf Version", i32 4}
-// DARWIN: metadata !{i32 2, metadata !"Dwarf Version", i32 2}
Index: test/Driver/clang-g-opts.c
===================================================================
--- test/Driver/clang-g-opts.c	(revision 210749)
+++ test/Driver/clang-g-opts.c	(working copy)
@@ -2,15 +2,23 @@
 // RUN: %clang -### -S %s -g -target x86_64-linux-gnu 2>&1 \
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G %s
 // RUN: %clang -### -S %s -g -target x86_64-apple-darwin 2>&1 \
-// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DARWIN %s
+// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g -target i686-pc-openbsd 2>&1 \
+// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g -target x86_64-pc-freebsd10.0 2>&1 \
+// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g0    2>&1 | FileCheck --check-prefix=CHECK-WITHOUT-G %s
 // RUN: %clang -### -S %s -g -g0 2>&1 | FileCheck --check-prefix=CHECK-WITHOUT-G %s
 // RUN: %clang -### -S %s -g0 -g -target x86_64-linux-gnu 2>&1 \
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G %s
 // RUN: %clang -### -S %s -g0 -g -target x86_64-apple-darwin 2>&1 \
-// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DARWIN %s
+// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g0 -g -target i686-pc-openbsd 2>&1 \
+// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.02>&1 \
+// RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 
 // CHECK-WITHOUT-G-NOT: "-g"
 // CHECK-WITH-G: "-g"
-// CHECK-WITH-G-DARWIN: "-gdwarf-2"
+// CHECK-WITH-G-DWARF2: "-gdwarf-2"
 
Index: test/Driver/debug-options.c
===================================================================
--- test/Driver/debug-options.c	(revision 210749)
+++ test/Driver/debug-options.c	(working copy)
@@ -38,11 +38,19 @@
 // RUN: %clang -### -c -gline-tables-only %s 2>&1 \
 // RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
 // RUN: %clang -### -c -gline-tables-only %s -target x86_64-apple-darwin 2>&1 \
-// RUN:             | FileCheck -check-prefix=GLTO_ONLY_DARWIN %s
+// RUN:             | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-tables-only %s -target i686-pc-openbsd 2>&1 \
+// RUN:             | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-tables-only %s -target x86_64-pc-freebsd10.0 2>&1 \
+// RUN:             | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-linux-gnu 2>&1 \
 // RUN:             | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-apple-darwin 2>&1 \
-// RUN:             | FileCheck -check-prefix=G_ONLY_DARWIN %s
+// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-tables-only -g %s -target i686-pc-openbsd 2>&1 \
+// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 2>&1 \
+// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
 // RUN:             | FileCheck -check-prefix=GLTO_NO %s
 //
@@ -78,11 +86,11 @@
 // GLTO_ONLY: "-gline-tables-only"
 // GLTO_ONLY-NOT: "-g"
 //
-// GLTO_ONLY_DARWIN: "-cc1"
-// GLTO_ONLY_DARWIN-NOT: "-g"
-// GLTO_ONLY_DARWIN: "-gline-tables-only"
-// GLTO_ONLY_DARWIN: "-gdwarf-2"
-// GLTO_ONLY_DARWIN-NOT: "-g"
+// GLTO_ONLY_DWARF2: "-cc1"
+// GLTO_ONLY_DWARF2-NOT: "-g"
+// GLTO_ONLY_DWARF2: "-gline-tables-only"
+// GLTO_ONLY_DWARF2: "-gdwarf-2"
+// GLTO_ONLY_DWARF2-NOT: "-g"
 //
 // G_ONLY: "-cc1"
 // G_ONLY-NOT: "-gline-tables-only"
@@ -89,10 +97,10 @@
 // G_ONLY: "-g"
 // G_ONLY-NOT: "-gline-tables-only"
 //
-// G_ONLY_DARWIN: "-cc1"
-// G_ONLY_DARWIN-NOT: "-gline-tables-only"
-// G_ONLY_DARWIN: "-gdwarf-2"
-// G_ONLY_DARWIN-NOT: "-gline-tables-only"
+// G_ONLY_DWARF2: "-cc1"
+// G_ONLY_DWARF2-NOT: "-gline-tables-only"
+// G_ONLY_DWARF2: "-gdwarf-2"
+// G_ONLY_DWARF2-NOT: "-gline-tables-only"
 //
 // GLTO_NO: "-cc1"
 // GLTO_NO-NOT: "-gline-tables-only"


More information about the llvm-commits mailing list