aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2022-09-15 09:58:03 +0200
committerGitHub <noreply@github.com>2022-09-15 09:58:03 +0200
commit061bd75953db392aca601b33db6712de0e08f2c6 (patch)
tree00ec67b6ec3ed5927cabff76fb1b09229d661458
parenta194a82bcd2693c32b242adad2db4716292e1e80 (diff)
parentb27a4a3689983390bbfc48c1bd1ba04e1b1aa935 (diff)
downloadafl++-061bd75953db392aca601b33db6712de0e08f2c6.tar.gz
Merge pull request #1518 from nikic/fix-lto
Fix LTO with LLVM 15
-rw-r--r--GNUmakefile.llvm8
-rw-r--r--instrumentation/SanitizerCoverageLTO.so.cc36
-rw-r--r--instrumentation/SanitizerCoveragePCGUARD.so.cc74
-rw-r--r--src/afl-cc.c12
4 files changed, 28 insertions, 102 deletions
diff --git a/GNUmakefile.llvm b/GNUmakefile.llvm
index 83330ddc..c37c4a51 100644
--- a/GNUmakefile.llvm
+++ b/GNUmakefile.llvm
@@ -86,12 +86,6 @@ ifeq "$(LLVM_TOO_OLD)" "1"
$(shell sleep 1)
endif
-ifeq "$(LLVM_MAJOR)" "15"
- $(info [!] llvm_mode detected llvm 15, which is currently broken for LTO plugins.)
- LLVM_LTO = 0
- LLVM_HAVE_LTO = 0
-endif
-
ifeq "$(LLVM_HAVE_LTO)" "1"
$(info [+] llvm_mode detected llvm 11+, enabling afl-lto LTO implementation)
LLVM_LTO = 1
@@ -99,7 +93,7 @@ ifeq "$(LLVM_HAVE_LTO)" "1"
endif
ifeq "$(LLVM_LTO)" "0"
- $(info [+] llvm_mode detected llvm < 11 or llvm 15, afl-lto LTO will not be build.)
+ $(info [+] llvm_mode detected llvm < 11, afl-lto LTO will not be build.)
endif
ifeq "$(LLVM_APPLE_XCODE)" "1"
diff --git a/instrumentation/SanitizerCoverageLTO.so.cc b/instrumentation/SanitizerCoverageLTO.so.cc
index 721bc487..231151f5 100644
--- a/instrumentation/SanitizerCoverageLTO.so.cc
+++ b/instrumentation/SanitizerCoverageLTO.so.cc
@@ -111,6 +111,12 @@ static cl::opt<bool> ClPruneBlocks(
cl::desc("Reduce the number of instrumented blocks"), cl::Hidden,
cl::init(true));
+namespace llvm {
+
+void initializeModuleSanitizerCoverageLTOLegacyPassPass(PassRegistry &PB);
+
+}
+
namespace {
SanitizerCoverageOptions getOptions(int LegacyCoverageLevel) {
@@ -255,13 +261,13 @@ class ModuleSanitizerCoverageLTO
};
-class ModuleSanitizerCoverageLegacyPass : public ModulePass {
+class ModuleSanitizerCoverageLTOLegacyPass : public ModulePass {
public:
static char ID;
StringRef getPassName() const override {
- return "sancov";
+ return "sancov-lto";
}
@@ -272,11 +278,11 @@ class ModuleSanitizerCoverageLegacyPass : public ModulePass {
}
- ModuleSanitizerCoverageLegacyPass(
+ ModuleSanitizerCoverageLTOLegacyPass(
const SanitizerCoverageOptions &Options = SanitizerCoverageOptions())
: ModulePass(ID), Options(Options) {
- initializeModuleSanitizerCoverageLegacyPassPass(
+ initializeModuleSanitizerCoverageLTOLegacyPassPass(
*PassRegistry::getPassRegistry());
}
@@ -318,8 +324,11 @@ llvmGetPassPluginInfo() {
#if LLVM_VERSION_MAJOR <= 13
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
#endif
- // PB.registerFullLinkTimeOptimizationLastEPCallback(
+#if LLVM_VERSION_MAJOR >= 15
+ PB.registerFullLinkTimeOptimizationLastEPCallback(
+#else
PB.registerOptimizerLastEPCallback(
+#endif
[](ModulePassManager &MPM, OptimizationLevel OL) {
MPM.addPass(ModuleSanitizerCoverageLTO());
@@ -1750,30 +1759,21 @@ std::string ModuleSanitizerCoverageLTO::getSectionName(
}
-char ModuleSanitizerCoverageLegacyPass::ID = 0;
+char ModuleSanitizerCoverageLTOLegacyPass::ID = 0;
-INITIALIZE_PASS_BEGIN(ModuleSanitizerCoverageLegacyPass, "sancov",
+INITIALIZE_PASS_BEGIN(ModuleSanitizerCoverageLTOLegacyPass, "sancov-lto",
"Pass for instrumenting coverage on functions", false,
false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
-INITIALIZE_PASS_END(ModuleSanitizerCoverageLegacyPass, "sancov",
+INITIALIZE_PASS_END(ModuleSanitizerCoverageLTOLegacyPass, "sancov-lto",
"Pass for instrumenting coverage on functions", false,
false)
-ModulePass *llvm::createModuleSanitizerCoverageLegacyPassPass(
- const SanitizerCoverageOptions &Options,
- const std::vector<std::string> &AllowlistFiles,
- const std::vector<std::string> &BlocklistFiles) {
-
- return new ModuleSanitizerCoverageLegacyPass(Options);
-
-}
-
static void registerLTOPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
- auto p = new ModuleSanitizerCoverageLegacyPass();
+ auto p = new ModuleSanitizerCoverageLTOLegacyPass();
PM.add(p);
}
diff --git a/instrumentation/SanitizerCoveragePCGUARD.so.cc b/instrumentation/SanitizerCoveragePCGUARD.so.cc
index faad0bf6..ef2d3b9c 100644
--- a/instrumentation/SanitizerCoveragePCGUARD.so.cc
+++ b/instrumentation/SanitizerCoveragePCGUARD.so.cc
@@ -209,57 +209,6 @@ class ModuleSanitizerCoverageAFL
};
-class ModuleSanitizerCoverageLegacyPass : public ModulePass {
-
- public:
- ModuleSanitizerCoverageLegacyPass(
- const SanitizerCoverageOptions &Options = SanitizerCoverageOptions())
- : ModulePass(ID), Options(Options) {
-
- initializeModuleSanitizerCoverageLegacyPassPass(
- *PassRegistry::getPassRegistry());
-
- }
-
- bool runOnModule(Module &M) override {
-
- ModuleSanitizerCoverageAFL ModuleSancov(Options);
- auto DTCallback = [this](Function &F) -> const DominatorTree * {
-
- return &this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
-
- };
-
- auto PDTCallback = [this](Function &F) -> const PostDominatorTree * {
-
- return &this->getAnalysis<PostDominatorTreeWrapperPass>(F)
- .getPostDomTree();
-
- };
-
- return ModuleSancov.instrumentModule(M, DTCallback, PDTCallback);
-
- }
-
- /*static*/ char ID; // Pass identification, replacement for typeid
- StringRef getPassName() const override {
-
- return "ModuleSanitizerCoverage";
-
- }
-
- void getAnalysisUsage(AnalysisUsage &AU) const override {
-
- AU.addRequired<DominatorTreeWrapperPass>();
- AU.addRequired<PostDominatorTreeWrapperPass>();
-
- }
-
- private:
- SanitizerCoverageOptions Options;
-
-};
-
} // namespace
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
@@ -1530,26 +1479,3 @@ std::string ModuleSanitizerCoverageAFL::getSectionEnd(
}
-#if 0
-
-char ModuleSanitizerCoverageLegacyPass::ID = 0;
-INITIALIZE_PASS_BEGIN(ModuleSanitizerCoverageLegacyPass, "sancov",
- "Pass for instrumenting coverage on functions", false,
- false)
-INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
-INITIALIZE_PASS_END(ModuleSanitizerCoverageLegacyPass, "sancov",
- "Pass for instrumenting coverage on functions", false,
- false)
-ModulePass *llvm::createModuleSanitizerCoverageLegacyPassPass(
- const SanitizerCoverageOptions &Options,
- const std::vector<std::string> &AllowlistFiles,
- const std::vector<std::string> &BlocklistFiles) {
-
- return new ModuleSanitizerCoverageLegacyPass(Options, AllowlistFiles,
- BlocklistFiles);
-
-}
-
-#endif
-
diff --git a/src/afl-cc.c b/src/afl-cc.c
index c0449e64..5e7a9c9e 100644
--- a/src/afl-cc.c
+++ b/src/afl-cc.c
@@ -666,15 +666,21 @@ static void edit_params(u32 argc, char **argv, char **envp) {
#endif
free(ld_path);
-#if defined(AFL_CLANG_LDPATH) && LLVM_MAJOR >= 13
+#if defined(AFL_CLANG_LDPATH) && LLVM_MAJOR >= 15
+ // The NewPM implementation only works fully since LLVM 15.
+ cc_params[cc_par_cnt++] =
+ alloc_printf("-Wl,--load-pass-plugin=%s/SanitizerCoverageLTO.so", obj_path);
+#elif defined(AFL_CLANG_LDPATH) && LLVM_MAJOR >= 13
cc_params[cc_par_cnt++] = "-Wl,--lto-legacy-pass-manager";
+ cc_params[cc_par_cnt++] =
+ alloc_printf("-Wl,-mllvm=-load=%s/SanitizerCoverageLTO.so", obj_path);
#else
cc_params[cc_par_cnt++] = "-fno-experimental-new-pass-manager";
+ cc_params[cc_par_cnt++] =
+ alloc_printf("-Wl,-mllvm=-load=%s/SanitizerCoverageLTO.so", obj_path);
#endif
cc_params[cc_par_cnt++] = "-Wl,--allow-multiple-definition";
- cc_params[cc_par_cnt++] =
- alloc_printf("-Wl,-mllvm=-load=%s/SanitizerCoverageLTO.so", obj_path);
cc_params[cc_par_cnt++] = lto_flag;
} else {