mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Ivan Trofimov <i.trofimow@yandex.ru>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] x86_64: Generate an eh-frame entry for syscall_cp
Date: Mon, 24 Feb 2025 16:35:54 +0300	[thread overview]
Message-ID: <4d2f1ada-2f31-4b44-a30d-dbccb97feba1@yandex.ru> (raw)

Some eBPF-based profilers (open-telemetry/opentelemetry-ebpf-profiler, 
yandex/perforator, parca-dev/parca etc. at github.com) leverage eh-frame 
section to unwind the stacks of native executables in kernel context.

This approach works pretty well most of the time, but sometimes fails to 
unwind through hand-written assembly due to it missing cfi-* directives.
Usually it's not that big of a deal and doesn't change the whole picture 
much, however with musl things are different, since these unwinders fail 
to unwind syscalls back to userspace, as musl doesn't generate an 
eh-frame entry for __syscall_cp function.

Imagine a flamegraph, where all (or most) of the syscalls are completely 
out of place: this is the problem this patch aims to fix for x86-64.

Signed-off-by: Ivan Trofimov <i.trofimow@yandex.ru>

---
  src/thread/x86_64/syscall_cp.s | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/src/thread/x86_64/syscall_cp.s b/src/thread/x86_64/syscall_cp.s
index 4f101716..296415d7 100644
--- a/src/thread/x86_64/syscall_cp.s
+++ b/src/thread/x86_64/syscall_cp.s
@@ -10,6 +10,7 @@
  .hidden __syscall_cp_asm
  .type   __syscall_cp_asm,@function
  __syscall_cp_asm:
+.cfi_startproc

  __cp_begin:
         mov (%rdi),%eax
@@ -29,3 +30,5 @@ __cp_end:
         ret
  __cp_cancel:
         jmp __cancel
+
+.cfi_endproc
--


             reply	other threads:[~2025-02-24 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24 13:35 Ivan Trofimov [this message]
2025-02-24 14:02 ` Timo Teras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d2f1ada-2f31-4b44-a30d-dbccb97feba1@yandex.ru \
    --to=i.trofimow@yandex.ru \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).