about summary refs log tree commit diff
path: root/instrumentation/afl-llvm-lto-instrumentation.so.cc
diff options
context:
space:
mode:
Diffstat (limited to 'instrumentation/afl-llvm-lto-instrumentation.so.cc')
-rw-r--r--instrumentation/afl-llvm-lto-instrumentation.so.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/instrumentation/afl-llvm-lto-instrumentation.so.cc b/instrumentation/afl-llvm-lto-instrumentation.so.cc
index 4a5738de..c2f61d34 100644
--- a/instrumentation/afl-llvm-lto-instrumentation.so.cc
+++ b/instrumentation/afl-llvm-lto-instrumentation.so.cc
@@ -108,8 +108,8 @@ bool AFLLTOPass::runOnModule(Module &M) {
   //  std::vector<CallInst *>          calls;
   DenseMap<Value *, std::string *> valueMap;
   std::vector<BasicBlock *>        BlockList;
+  std::ofstream                    dFile;
   char *                           ptr;
-  FILE *                           documentFile = NULL;
   size_t                           found = 0;
 
   srand((unsigned int)time(NULL));
@@ -137,8 +137,8 @@ bool AFLLTOPass::runOnModule(Module &M) {
 
   if ((ptr = getenv("AFL_LLVM_DOCUMENT_IDS")) != NULL) {
 
-    if ((documentFile = fopen(ptr, "a")) == NULL)
-      WARNF("Cannot access document file %s", ptr);
+    dFile.open(ptr, std::ofstream::out | std::ofstream::app);
+    if (!dFile.is_open()) WARNF("Cannot access document file %s", ptr);
 
   }
 
@@ -243,8 +243,14 @@ bool AFLLTOPass::runOnModule(Module &M) {
 
     // the instrument file list check
     AttributeList Attrs = F.getAttributes();
+#if LLVM_VERSION_MAJOR < 14
     if (Attrs.hasAttribute(-1, StringRef("skipinstrument"))) {
 
+#else
+    if (Attrs.hasFnAttr(StringRef("skipinstrument"))) {
+
+#endif
+
       if (debug)
         fprintf(stderr,
                 "DEBUG: Function %s is not in a source file that was specified "
@@ -845,10 +851,11 @@ bool AFLLTOPass::runOnModule(Module &M) {
 
           }
 
-          if (documentFile) {
+          if (dFile.is_open()) {
 
-            fprintf(documentFile, "ModuleID=%llu Function=%s edgeID=%u\n",
-                    moduleID, F.getName().str().c_str(), afl_global_id);
+            dFile << "ModuleID=" << moduleID
+                  << " Function=" << F.getName().str()
+                  << " edgeID=" << afl_global_id << "\n";
 
           }
 
@@ -920,8 +927,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
 
   }
 
-  if (documentFile) fclose(documentFile);
-  documentFile = NULL;
+  if (dFile.is_open()) dFile.close();
 
   // save highest location ID to global variable
   // do this after each function to fail faster
@@ -1016,7 +1022,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
 
       if (count) {
 
-        auto ptrhld = std::unique_ptr<char []>(new char[memlen + count]);
+        auto ptrhld = std::unique_ptr<char[]>(new char[memlen + count]);
 
         count = 0;