lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 6 Dec 2016 07:13:45 +0000
From:   Wang Nan <wangnan0@...wei.com>
To:     <acme@...nel.org>
CC:     <linux-kernel@...r.kernel.org>, <joe@....org>,
        Wang Nan <wangnan0@...wei.com>,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        He Kuang <hekuang@...wei.com>, Jiri Olsa <jolsa@...nel.org>,
        Zefan Li <lizefan@...wei.com>, <pi3orama@....com>
Subject: [PATCH v4 07/18] perf clang jit: Insignt BPF and JIT functions in a Module

Identify BPF functions, JIT functions and maps during init. Functions in
section starting with "perfhook:" are JIT functions. They will be JIT
compiled and hooked at perfhooks.

During init of PerfModule, mark JIT functions as AvailableExternallyLinkage.
LLVM skips functions with linkage like this so they won't be compiled
into BPF objects.

Signed-off-by: Wang Nan <wangnan0@...wei.com>
Acked-by: Alexei Starovoitov <ast@...com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: He Kuang <hekuang@...wei.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Zefan Li <lizefan@...wei.com>
Cc: pi3orama@....com
---
 tools/perf/util/c++/clang.cpp | 38 ++++++++++++++++++++++++++++++++++++++
 tools/perf/util/c++/clang.h   |  7 +++++++
 2 files changed, 45 insertions(+)

diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
index 042db68..8a0f818 100644
--- a/tools/perf/util/c++/clang.cpp
+++ b/tools/perf/util/c++/clang.cpp
@@ -112,15 +112,53 @@ getModuleFromSource(llvm::opt::ArgStringList CFlags, StringRef Path)
 
 PerfModule::PerfModule(std::unique_ptr<llvm::Module>&& M) : Module(std::move(M))
 {
+	for (llvm::Function& F : *Module) {
+		if (F.getLinkage() != llvm::GlobalValue::ExternalLinkage)
+			continue;
+
+		if (StringRef(F.getSection()).startswith("perfhook:"))
+			JITFunctions.insert(&F);
+		else
+			BPFFunctions.insert(&F);
+	}
 
+	for (auto V = Module->global_begin(); V != Module->global_end(); V++) {
+		llvm::GlobalVariable *GV = &*V;
+		if (StringRef(GV->getSection()) == llvm::StringRef("maps"))
+			Maps.insert(GV);
+	}
 }
 
+void PerfModule::prepareBPF(void)
+{
+	/*
+	 * setLinkage(AvailableExternallyLinkage) causes LLVM
+	 * blindly skip the function. They still exist in Module
+	 * so we can bring them back by resetting linkage to
+	 * ExternalLinkage.
+	 */
+	for (llvm::Function *F : JITFunctions)
+		F->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
+	for (llvm::Function *F : BPFFunctions)
+		F->setLinkage(llvm::GlobalValue::ExternalLinkage);
+
+}
+
+void PerfModule::prepareJIT(void)
+{
+	for (llvm::Function *F : BPFFunctions)
+		F->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
+	for (llvm::Function *F : JITFunctions)
+		F->setLinkage(llvm::GlobalValue::ExternalLinkage);
+
+}
 
 std::unique_ptr<llvm::SmallVectorImpl<char>>
 PerfModule::toBPFObject(void)
 {
 	using namespace llvm;
 
+	prepareBPF();
 	std::string TargetTriple("bpf-pc-linux");
 	std::string Error;
 	const Target* Target = TargetRegistry::lookupTarget(TargetTriple, Error);
diff --git a/tools/perf/util/c++/clang.h b/tools/perf/util/c++/clang.h
index cbb291b..1eb71a6 100644
--- a/tools/perf/util/c++/clang.h
+++ b/tools/perf/util/c++/clang.h
@@ -6,6 +6,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Option/Option.h"
 #include <memory>
+#include <set>
 
 namespace perf {
 
@@ -14,6 +15,12 @@ using namespace llvm;
 class PerfModule {
 private:
 	std::unique_ptr<llvm::Module> Module;
+
+	std::set<llvm::GlobalVariable *> Maps;
+	std::set<llvm::Function *> BPFFunctions;
+	std::set<llvm::Function *> JITFunctions;
+	void prepareBPF(void);
+	void prepareJIT(void);
 public:
 	inline llvm::Module *getModule(void)
 	{
-- 
2.10.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ