Skip to content

Commit e9e4836

Browse files
Vojtech Kralvojtechkral
Vojtech Kral
authored andcommitted
Fix libunwind build: Define __LITTLE_ENDIAN__ for LE targets
If __LITTLE_ENDIAN__ is missing, libunwind assumes big endian and reads unwinding instructions wrong on ARM EHABI. Fix rust-lang#65765
1 parent c553e8e commit e9e4836

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libunwind/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ mod llvm_libunwind {
5656
pub fn compile() {
5757
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
5858
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
59+
let target_endian_little = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap() != "big";
5960
let cfg = &mut cc::Build::new();
6061

6162
cfg.cpp(true);
6263
cfg.cpp_set_stdlib(None);
6364
cfg.warnings(false);
6465

66+
// libunwind expects a __LITTLE_ENDIAN__ macro to be set for LE archs, cf. #65765
67+
if target_endian_little {
68+
cfg.define("__LITTLE_ENDIAN__", Some("1"));
69+
}
70+
6571
if target_env == "msvc" {
6672
// Don't pull in extra libraries on MSVC
6773
cfg.flag("/Zl");

0 commit comments

Comments
 (0)