[llvm-exegesis] Switch to using PTRACE_ATTACH instead of PTRACE_SEIZE
authorAiden Grossman <agrossman154@yahoo.com>
Fri, 7 Jul 2023 02:40:19 +0000 (19:40 -0700)
committerAiden Grossman <agrossman154@yahoo.com>
Fri, 7 Jul 2023 02:40:19 +0000 (19:40 -0700)
This patch switches from using PTRACE_SEIZE within the subprocess
benchmark runner for llvm-exegesis as PTRACE_SEIZE was introduced in
Linux kernel 3.4. Some LLVM users were reporting build failures as they
are using Kernel versions older than 3.4 (such as on CentOS/RHEL 6),
hence the patch.

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

index 6d0b754..ba91f5d 100644 (file)
@@ -7,6 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include <array>
+#include <cerrno>
+#include <iostream>
 #include <memory>
 #include <string>
 
@@ -249,10 +251,21 @@ private:
                                  "to child process failed: " +
                                  Twine(strerror(errno)));
 
-    if (ptrace(PTRACE_SEIZE, ParentOrChildPID, NULL, NULL) != 0)
-      return make_error<Failure>("Failed to seize the child process: " +
+    if (ptrace(PTRACE_ATTACH, ParentOrChildPID, NULL, NULL) != 0)
+      return make_error<Failure>("Failed to attach to the child process: " +
                                  Twine(strerror(errno)));
 
+    if (wait(NULL) == -1) {
+      return make_error<Failure>(
+          "Failed to wait for child process to stop after attaching: " +
+          Twine(strerror(errno)));
+    }
+
+    if (ptrace(PTRACE_CONT, ParentOrChildPID, NULL, NULL) != 0)
+      return make_error<Failure>(
+          "Failed to continue execution of the child process: " +
+          Twine(strerror(errno)));
+
     int ChildStatus;
     if (wait(&ChildStatus) == -1) {
       return make_error<Failure>(