Skip to content

Commit cbfbbd7

Browse files
boomanaiden154tru
authored andcommitted
[llvm-exegesis] Use correct rseq struct size (#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. (cherry picked from commit 1e8df9e)
1 parent 5d9f460 commit cbfbbd7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,20 @@ class SubProcessFunctionExecutorImpl
466466
// segfaults in the program. Unregister the rseq region so that we can safely
467467
// unmap it later
468468
#ifdef GLIBC_INITS_RSEQ
469+
unsigned int RseqStructSize = __rseq_size;
470+
471+
// Glibc v2.40 (the change is also expected to be backported to v2.35)
472+
// changes the definition of __rseq_size to be the usable area of the struct
473+
// rather than the actual size of the struct. v2.35 uses only 20 bytes of
474+
// the 32 byte struct. For now, it should be safe to assume that if the
475+
// usable size is less than 32, the actual size of the struct will be 32
476+
// bytes given alignment requirements.
477+
if (__rseq_size < 32)
478+
RseqStructSize = 32;
479+
469480
long RseqDisableOutput =
470481
syscall(SYS_rseq, (intptr_t)__builtin_thread_pointer() + __rseq_offset,
471-
__rseq_size, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
482+
RseqStructSize, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
472483
if (RseqDisableOutput != 0)
473484
exit(ChildProcessExitCodeE::RSeqDisableFailed);
474485
#endif // GLIBC_INITS_RSEQ

0 commit comments

Comments
 (0)