[llvm] [llvm-exegesis] Use correct rseq struct size (PR #100804)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 12:33:49 PDT 2024


https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/100804

Glibc v2.40 changes the definition of __rseq_size to the usable area of the struct rather than the actual size of the struct to accommodate users trying to figure out what features can be used. This change breaks llvm-exegesis trying to disable rseq as the size registered in the kernel is no longer equal to __rseq_size. This patch adds a check to see if __rseq_size is less than 32 bytes and uses 32 as a value if it is given alignment requirements.

Fixes #100791.

>From 84837e3cc1cf17ed71580e3ea38299ed2bfaa5f6 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Fri, 26 Jul 2024 19:20:41 +0000
Subject: [PATCH] [llvm-exegesis] Use correct rseq struct size

Glibc v2.40 changes the definition of __rseq_size to the usable area of
the struct rather than the actual size of the struct to accommodate
users trying to figure out what features can be used. This change breaks
llvm-exegesis trying to disable rseq as the size registered in the
kernel is no longer equal to __rseq_size. This patch adds a check to see
if __rseq_size is less than 32 bytes and uses 32 as a value if it is
given alignment requirements.

Fixes #100791.
---
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index ed53f8fabb175..adee869967d98 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -466,9 +466,20 @@ class SubProcessFunctionExecutorImpl
 // segfaults in the program. Unregister the rseq region so that we can safely
 // unmap it later
 #ifdef GLIBC_INITS_RSEQ
+    unsigned int RseqStructSize = __rseq_size;
+
+    // Glibc v2.40 (the change is also expected to be backported to v2.35)
+    // changes the definition of __rseq_size to be the usable area of the struct
+    // rather than the actual size of the struct. v2.35 uses only 20 bytes of
+    // the 32 byte struct. For now, it should be safe to assume that if the
+    // usable size is less than 32, the actual size of the struct will be 32
+    // bytes given alignment requirements.
+    if (__rseq_size < 32)
+      RseqStructSize = 32;
+
     long RseqDisableOutput =
         syscall(SYS_rseq, (intptr_t)__builtin_thread_pointer() + __rseq_offset,
-                __rseq_size, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
+                RseqStructSize, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
     if (RseqDisableOutput != 0)
       exit(ChildProcessExitCodeE::RSeqDisableFailed);
 #endif // GLIBC_INITS_RSEQ



More information about the llvm-commits mailing list