Skip to content

feat: complete ARM64 support and add test case#34

Open
wkpark wants to merge 3 commits into
linux-usdt:mainfrom
wkpark:support-arm64
Open

feat: complete ARM64 support and add test case#34
wkpark wants to merge 3 commits into
linux-usdt:mainfrom
wkpark:support-arm64

Conversation

@wkpark

@wkpark wkpark commented Mar 7, 2026

Copy link
Copy Markdown

Based on #29

  • Add AArch64 assembly template for probe generation
  • Update Makefile to detect architecture automatically via uname
  • Set EM_AARCH64 in ELF header for ARM64 systems
  • Add test-regmap to verify register mapping for arm64 and x86_64

Overview

This PR introduces full support for the ARM64 (AArch64) architecture
These changes were implemented and verified with the assistance of Gemini CLI.

Key Changes

  • ARM64 Support:

    • Added a dedicated AArch64 assembly template (src/asm/libstapsdt-aarch64.s) for runtime probe generation.
    • Updated the Makefile to automatically detect the architecture using uname -m.
    • Configured the ELF header to use EM_AARCH64 on ARM64 systems.
  • Code Quality & Testing:

    • Added tests/test-regmap.c to verify register mapping across different architectures.
    • Verified the implementation using valgrind on an ARM64 environment to ensure zero memory leaks.

Note

This contribution was developed in collaboration with Gemini CLI, ensuring adherence to the project's standards and providing comprehensive validation on real ARM64 hardware.

Test script with the pystapsdt

import os
import stapsdt
from time import sleep

# 1. Provider and probe setup
provider = stapsdt.Provider("pythonapp")
# First argument is a pointer (uint64), second is a 32-bit integer (int32)
probe = provider.add_probe(
    "firstProbe", stapsdt.ArgTypes.uint64, stapsdt.ArgTypes.int32)
provider.load()

# 2. Extract info for bpftrace
pid = os.getpid()
lib_path = ""

# Find the temporary .so path generated by libstapsdt in /proc/self/maps
try:
    with open("/proc/self/maps", "r") as f:
        for line in f:
            if "pythonapp" in line and ".so" in line:
                lib_path = line.split()[-1]
                break
except Exception:
    pass

# 3. Print bpftrace command to user
print("\n" + "="*60)
print(f"[*] Python App PID: {pid}")
if lib_path:
    print("[*] Trace Command (Noise-free):")
    print(f"sudo bpftrace -p {pid} -e 'usdt:{lib_path}:pythonapp:firstProbe {{ printf(\"%s - %d\\n\", str(arg0), arg1); }}'")
else:
    # Fallback if path not found
    print("[*] Trace Command (Fallback):")
    print(f"sudo bpftrace -p {pid} -e 'usdt::pythonapp:firstProbe {{ printf(\"%s - %d\\n\", str(arg0), arg1); }}'")
print("="*60 + "\n")

# 4. Wait for user before starting loop
print("\n>>> Copy the command above and run it in another terminal.")
input(">>> Press Enter to start firing probes...")

# 5. Main loop
while True:
    print("Firing probe...")
    # stapsdt handles string to uint64 pointer conversion
    if probe.fire("My little probe", 42):
        print("Probe fired!")
    sleep(1)

on arm64

$ uv run python
Python 3.13.5 (main, Jun 12 2025, 12:28:08) [GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ uv run app.py

============================================================
[*] Python App PID: 2894852
[*] Trace Command (Noise-free):
sudo bpftrace -p 2894852 -e 'usdt::pythonapp:firstProbe { printf("%s - %d\n", str(arg0), arg1); }'
============================================================


>>> Copy the command above and run it in another terminal.
>>> Press Enter to start firing probes...
Firing probe...
Probe fired!
Firing probe...
Probe fired!
.....
$ sudo bpftrace -p 2894852 -e 'usdt::pythonapp:firstProbe { printf("%s - %d\n", str(arg0), arg1); }'
Parse error:
    8@x0 8@[x2, #:lo12:.LANCHOR2]
---------------^
Parse error:
    8@x20 8@[x21, #:lo12:.LANCHOR2]
-----------------^
Parse error:
    8@x0 8@[x2, #:lo12:.LANCHOR2]
---------------^
Parse error:
    8@x20 8@[x21, #:lo12:.LANCHOR2]
-----------------^
Parse error:
    8@x0 8@[x2, #:lo12:.LANCHOR2]
---------------^
Parse error:
    8@x20 8@[x21, #:lo12:.LANCHOR2]
-----------------^
Attaching 1 probe...
Parse error:
    8@x0 8@[x2, #:lo12:.LANCHOR2]
---------------^
Parse error:
    8@x20 8@[x21, #:lo12:.LANCHOR2]
-----------------^
My little probe - 42
My little probe - 42
My little probe - 42
My little probe - 42
...

jstasiak and others added 2 commits March 7, 2026 03:02
- Add AArch64 assembly template for probe generation
- Update Makefile to detect architecture automatically via uname
- Set EM_AARCH64 in ELF header for ARM64 systems
- Add test-regmap to verify register mapping for arm64 and x86_64
@wkpark wkpark mentioned this pull request Mar 7, 2026
7 tasks
 - Correctly detect AArch64 NOP instructions (0xd503201f) in probeIsEnabled

 References: Commit shandowc@e0c98fc9 by Zhang Xiaodong <zhangxiaodong1@sensetime.com>
 Assisted-by: Gemini CLI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants