Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable per thread register state cache on libunwind #55049

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions deps/patches/libunwind-disable-initial-exec-tls.patch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to upstream this patch?

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/include/libunwind-common.h.in b/include/libunwind-common.h.in
index 893fdd69..80ab9648 100644
--- a/include/libunwind-common.h.in
+++ b/include/libunwind-common.h.in
@@ -340,5 +340,6 @@ extern int unw_get_elf_filename_by_ip (unw_addr_space_t, unw_word_t, char *,
extern const char *unw_strerror (int);
extern int unw_backtrace (void **, int);
extern int unw_backtrace2 (void **, int, unw_context_t*, int);
+extern int unw_ensure_tls (void);

extern unw_addr_space_t unw_local_addr_space;
diff --git a/src/dwarf/Gparser.c b/src/dwarf/Gparser.c
index 7a5d7e1f..8453ffb0 100644
--- a/src/dwarf/Gparser.c
+++ b/src/dwarf/Gparser.c
@@ -623,7 +623,7 @@ get_rs_cache (unw_addr_space_t as, intrmask_t *saved_maskp)
#if defined(HAVE___CACHE_PER_THREAD) && HAVE___CACHE_PER_THREAD
if (likely (caching == UNW_CACHE_PER_THREAD))
{
- static _Thread_local struct dwarf_rs_cache tls_cache __attribute__((tls_model("initial-exec")));
+ static _Thread_local struct dwarf_rs_cache tls_cache;
Debug (16, "using TLS cache\n");
cache = &tls_cache;
}
diff --git a/src/mi/init.c b/src/mi/init.c
index e4431eeb..07cae852 100644
--- a/src/mi/init.c
+++ b/src/mi/init.c
@@ -82,3 +82,15 @@ mi_init (void)
unw_init_page_size();
assert(sizeof(struct cursor) <= sizeof(unw_cursor_t));
}
+
+int
+unw_ensure_tls (void)
+{
+#if defined(HAVE___CACHE_PER_THREAD) && HAVE___CACHE_PER_THREAD
+ static _Thread_local int alloc_trigger;
+ alloc_trigger = 1;
+ return alloc_trigger;
+#else
+ return 0;
+#endif
+}
8 changes: 6 additions & 2 deletions deps/unwind.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-aarch64-inline-asm.patch-applied:
cd $(SRCCACHE)/libunwind-$(UNWIND_VER) && patch -p1 -f -u -l < $(SRCDIR)/patches/libunwind-aarch64-inline-asm.patch
echo 1 > $@

$(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-disable-initial-exec-tls.patch-applied: $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-aarch64-inline-asm.patch-applied
cd $(SRCCACHE)/libunwind-$(UNWIND_VER) && patch -p1 -f -u -l < $(SRCDIR)/patches/libunwind-disable-initial-exec-tls.patch
echo 1 > $@

# note minidebuginfo requires liblzma, which we do not have a source build for
# (it will be enabled in BinaryBuilder-based downloads however)
# since https://github.com/JuliaPackaging/Yggdrasil/commit/0149e021be9badcb331007c62442a4f554f3003c
$(BUILDDIR)/libunwind-$(UNWIND_VER)/build-configured: $(SRCCACHE)/libunwind-$(UNWIND_VER)/source-extracted $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-aarch64-inline-asm.patch-applied
$(BUILDDIR)/libunwind-$(UNWIND_VER)/build-configured: $(SRCCACHE)/libunwind-$(UNWIND_VER)/source-extracted $(SRCCACHE)/libunwind-$(UNWIND_VER)/libunwind-disable-initial-exec-tls.patch-applied
mkdir -p $(dir $@)
cd $(dir $@) && \
$(dir $<)/configure $(CONFIGURE_COMMON) CPPFLAGS="$(CPPFLAGS) $(LIBUNWIND_CPPFLAGS)" CFLAGS="$(CFLAGS) $(LIBUNWIND_CFLAGS)" --enable-shared --disable-minidebuginfo --disable-tests --enable-zlibdebuginfo --disable-conservative-checks
$(dir $<)/configure $(CONFIGURE_COMMON) CPPFLAGS="$(CPPFLAGS) $(LIBUNWIND_CPPFLAGS)" CFLAGS="$(CFLAGS) $(LIBUNWIND_CFLAGS)" --enable-shared --disable-minidebuginfo --disable-tests --enable-zlibdebuginfo --disable-conservative-checks --enable-per-thread-cache
echo 1 > $@

$(BUILDDIR)/libunwind-$(UNWIND_VER)/build-compiled: $(BUILDDIR)/libunwind-$(UNWIND_VER)/build-configured
Expand Down
6 changes: 6 additions & 0 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ jl_ptls_t jl_init_threadtls(int16_t tid)
jl_fence();
uv_mutex_unlock(&tls_lock);

#if !defined(JL_DISABLE_LIBUNWIND)
// ensures libunwind TLS space for this thread is allocated eagerly
// to make unwinding async-signal-safe even when using thread local caches.
unw_ensure_tls();
#endif

return ptls;
}

Expand Down