r326648 - OpenBSD Driver basic sanitiser support

Kamil Rytarowski via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 3 03:52:54 PST 2018


Author: kamil
Date: Sat Mar  3 03:52:52 2018
New Revision: 326648

URL: http://llvm.org/viewvc/llvm-project?rev=326648&view=rev
Log:
OpenBSD Driver basic sanitiser support

Summary:
Basic support of Sanitiser to follow-up ubsan support in compiler-rt.
Needs to use lld instead of base ld to be fully workable.

Patch by: David CARLIER

Reviewers: krytarowski, vitalybuka, kettenis

Reviewed By: vitalybuka

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D43961

Modified:
    cfe/trunk/lib/Driver/ToolChains/OpenBSD.cpp
    cfe/trunk/lib/Driver/ToolChains/OpenBSD.h

Modified: cfe/trunk/lib/Driver/ToolChains/OpenBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/OpenBSD.cpp?rev=326648&r1=326647&r2=326648&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/OpenBSD.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/OpenBSD.cpp Sat Mar  3 03:52:52 2018
@@ -13,6 +13,7 @@
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 
 using namespace clang::driver;
@@ -97,6 +98,8 @@ void openbsd::Linker::ConstructJob(Compi
                                    const InputInfoList &Inputs,
                                    const ArgList &Args,
                                    const char *LinkingOutput) const {
+  const toolchains::OpenBSD &ToolChain =
+      static_cast<const toolchains::OpenBSD &>(getToolChain());
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
 
@@ -170,11 +173,13 @@ void openbsd::Linker::ConstructJob(Compi
     Triple.replace(0, 6, "amd64");
   CmdArgs.push_back(
       Args.MakeArgString("-L/usr/lib/gcc-lib/" + Triple + "/4.2.1"));
+  CmdArgs.push_back(Args.MakeArgString("-L/usr/lib"));
 
   Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
                             options::OPT_e, options::OPT_s, options::OPT_t,
                             options::OPT_Z_Flag, options::OPT_r});
 
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -186,7 +191,10 @@ void openbsd::Linker::ConstructJob(Compi
       else
         CmdArgs.push_back("-lm");
     }
-
+    if (NeedsSanitizerDeps) {
+      CmdArgs.push_back(ToolChain.getCompilerRTArgString(Args, "builtins", false));
+      linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
+    }
     // FIXME: For some reason GCC passes -lgcc before adding
     // the default system libraries. Just mimic this for now.
     CmdArgs.push_back("-lgcc");
@@ -221,6 +229,19 @@ void openbsd::Linker::ConstructJob(Compi
   C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
 }
 
+SanitizerMask OpenBSD::getSupportedSanitizers() const {
+  const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+  const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
+
+  // For future use, only UBsan at the moment
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+
+  if (IsX86 || IsX86_64)
+    Res |= SanitizerKind::Vptr;
+
+  return Res;
+}
+
 /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
 
 OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple,

Modified: cfe/trunk/lib/Driver/ToolChains/OpenBSD.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/OpenBSD.h?rev=326648&r1=326647&r2=326648&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/OpenBSD.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/OpenBSD.h Sat Mar  3 03:52:52 2018
@@ -64,6 +64,8 @@ public:
   }
   unsigned GetDefaultDwarfVersion() const override { return 2; }
 
+  SanitizerMask getSupportedSanitizers() const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;




More information about the cfe-commits mailing list