Skip to content

Commit 9f363bf

Browse files
sean-jcgregkh
authored andcommitted
rseq/selftests: Use weak symbol reference, not definition, to link with glibc
commit a001cd2 upstream. Add "extern" to the glibc-defined weak rseq symbols to convert the rseq selftest's usage from weak symbol definitions to weak symbol _references_. Effectively re-defining the glibc symbols wreaks havoc when building with -fno-common, e.g. generates segfaults when running multi-threaded programs, as dynamically linked applications end up with multiple versions of the symbols. Building with -fcommon, which until recently has the been the default for GCC and clang, papers over the bug by allowing the linker to resolve the weak/tentative definition to glibc's "real" definition. Note, the symbol itself (or rather its address), not the value of the symbol, is set to 0/NULL for unresolved weak symbol references, as the symbol doesn't exist and thus can't have a value. Check for a NULL rseq size pointer to handle the scenario where the test is statically linked against a libc that doesn't support rseq in any capacity. Fixes: 3bcbc20 ("selftests/rseq: Play nice with binaries statically linked against glibc 2.35+") Reported-by: Thomas Gleixner <[email protected]> Suggested-by: Florian Weimer <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Mathieu Desnoyers <[email protected]> Cc: [email protected] Closes: https://lore.kernel.org/all/87frdoybk4.ffs@tglx Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 524e37f commit 9f363bf

File tree

1 file changed

+4
-4
lines changed
  • tools/testing/selftests/rseq

1 file changed

+4
-4
lines changed

tools/testing/selftests/rseq/rseq.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
* Define weak versions to play nice with binaries that are statically linked
3939
* against a libc that doesn't support registering its own rseq.
4040
*/
41-
__weak ptrdiff_t __rseq_offset;
42-
__weak unsigned int __rseq_size;
43-
__weak unsigned int __rseq_flags;
41+
extern __weak ptrdiff_t __rseq_offset;
42+
extern __weak unsigned int __rseq_size;
43+
extern __weak unsigned int __rseq_flags;
4444

4545
static const ptrdiff_t *libc_rseq_offset_p = &__rseq_offset;
4646
static const unsigned int *libc_rseq_size_p = &__rseq_size;
@@ -124,7 +124,7 @@ void rseq_init(void)
124124
* libc not having registered a restartable sequence. Try to find the
125125
* symbols if that's the case.
126126
*/
127-
if (!*libc_rseq_size_p) {
127+
if (!libc_rseq_size_p || !*libc_rseq_size_p) {
128128
libc_rseq_offset_p = dlsym(RTLD_NEXT, "__rseq_offset");
129129
libc_rseq_size_p = dlsym(RTLD_NEXT, "__rseq_size");
130130
libc_rseq_flags_p = dlsym(RTLD_NEXT, "__rseq_flags");

0 commit comments

Comments
 (0)