Skip to content

Disable libunwind cross-architecture unwinding #141375

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kraj
Copy link
Contributor

@kraj kraj commented May 22, 2025

Building with _LIBUNWIND_IS_NATIVE_ONLY disables code for cross-architecture unwinding It also enables some additional code that handles PAC-specific unwind info it helps compiling with the -mbranch-protection=pac or -mbranch-protection=standard flags

This fixes build with clang/musl on aarch64

Building with _LIBUNWIND_IS_NATIVE_ONLY disables code for cross-architecture unwinding
It also enables some additional code that handles PAC-specific unwind info
it helps compiling with the -mbranch-protection=pac or -mbranch-protection=standard flags

This fixes build with clang/musl on aarch64

Signed-off-by: Khem Raj <raj.khem@gmail.com>
@rustbot
Copy link
Collaborator

rustbot commented May 22, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels May 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 22, 2025

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

@kraj
Copy link
Contributor Author

kraj commented May 22, 2025

This is the error that happens when compiling rust for aarch64/musl using clang compiler with -mbranch-protection=standard turned on.

cargo:warning=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src/src/llvm-project/libunwind/src/UnwindLevel1.c:313:9: error: invalid input constraint 'D' in asm
cargo:warning=  313 |         __unw_phase2_resume(cursor, framesWalked);
cargo:warning=      |         ^
cargo:warning=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src/src/llvm-project/libunwind/src/UnwindLevel1.c:62:42: note: expanded from macro '__unw_phase2_resume'
cargo:warning=   62 |                      "jmp *%%edx\n\t" :: "D"(cetRegContext),                   \
cargo:warning=      |                                          ^
cargo:warning=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src/src/llvm-project/libunwind/src/UnwindLevel1.c:415:9: error: invalid input constraint 'D' in asm
cargo:warning=  415 |         __unw_phase2_resume(cursor, framesWalked);
cargo:warning=      |         ^
cargo:warning=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src/src/llvm-project/libunwind/src/UnwindLevel1.c:62:42: note: expanded from macro '__unw_phase2_resume'
cargo:warning=   62 |                      "jmp *%%edx\n\t" :: "D"(cetRegContext),                   \
cargo:warning=      |                                          ^
cargo:warning=2 errors generated.


error occurred: Command "/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/wrapper/target-rust-cc" "-I" "/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src/src/llvm-project/libunwind/include" "-O2" "-g" "-ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src=/usr/src/debug/rust/1.85.1" "-ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src=/usr/src/debug/rust/1.85.1" "-ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/recipe-sysroot=" "-ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/recipe-sysroot-native=" "-pipe" "-fstrict-aliasing" "-funwind-tables" "-fvisibility=hidden" "-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS" "-o" "/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src/build/aarch64-poky-linux-musl/native/libunwind/d440502555900257-UnwindLevel1.o" "-c" "/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src/src/llvm-project/libunwind/src/UnwindLevel1.c" with args target-rust-cc did not execute successfully (status code exit status: 1).

/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/wrapper/target-rust-cc

is

#!/usr/bin/env python3
import os, sys
orig_binary = "aarch64-poky-linux-musl-clang  -mcpu=cortex-a57+crc -mbranch-protection=standard  --dyld-prefix=/usr -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/recipe-sysroot -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed  -ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src=/usr/src/debug/rust/1.85.1  -ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/rustc-1.85.1-src=/usr/src/debug/rust/1.85.1  -ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/recipe-sysroot=  -ffile-prefix-map=/mnt/b/yoe/master/sources/poky/build/tmp/work/cortexa57-poky-linux-musl/rust/1.85.1/recipe-sysroot-native=  -Wl,-z,relro,-z,now"
extras = "-lssp_nonshared"

# Apply a required subset of CC crate compiler flags
# when we build a target recipe for a non-bare-metal target.
# https://github.com/rust-lang/cc-rs/blob/main/src/lib.rs#L1614
if "CRATE_CC_NO_DEFAULTS" in os.environ.keys() and         "TARGET" in os.environ.keys() and not "-none-" in os.environ["TARGET"]:
    orig_binary += " -ffunction-sections -fdata-sections -fPIC"

binary = orig_binary.split()[0]
args = orig_binary.split() + sys.argv[1:]
if extras:
    args.append(extras)
os.execvp(binary, args)

@kraj
Copy link
Contributor Author

kraj commented May 22, 2025

Gentoo has a similar bug report - https://bugs.gentoo.org/950171

@@ -1454,6 +1454,9 @@ impl Step for Libunwind {
cfg.define("_LIBUNWIND_HIDE_SYMBOLS", "1");
cfg.define("_LIBUNWIND_IS_NATIVE_ONLY", "1");
}
if self.target.starts_with("aarch64") && self.target.contains("musl") {
cfg.define("_LIBUNWIND_IS_NATIVE_ONLY", "1");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be enabled on all targets except fortanix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants