Skip to content

Commit 203a324

Browse files
authored
Merge pull request #1634 from philipc/macho-arm64
Fix __eh_frame for AArch64 on macOS
2 parents e6e77ab + a0871ed commit 203a324

6 files changed

Lines changed: 103 additions & 92 deletions

File tree

Cargo.lock

Lines changed: 51 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ crate-type = ["dylib"]
88

99
[dependencies]
1010
# These have to be in sync with each other
11-
cranelift-codegen = { version = "0.130.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] }
12-
cranelift-frontend = { version = "0.130.0" }
13-
cranelift-module = { version = "0.130.0" }
14-
cranelift-native = { version = "0.130.0" }
15-
cranelift-jit = { version = "0.130.0", optional = true }
16-
cranelift-object = { version = "0.130.0" }
11+
cranelift-codegen = { version = "0.131.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] }
12+
cranelift-frontend = { version = "0.131.0" }
13+
cranelift-module = { version = "0.131.0" }
14+
cranelift-native = { version = "0.131.0" }
15+
cranelift-jit = { version = "0.131.0", optional = true }
16+
cranelift-object = { version = "0.131.0" }
1717
target-lexicon = "0.13"
1818
gimli = { version = "0.33", default-features = false, features = ["write"] }
19-
object = { version = "0.38.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
19+
object = { version = "0.39.1", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
2020

2121
indexmap = "2.0.0"
2222
libloading = { version = "0.9.0", optional = true }
2323
smallvec = "1.8.1"
2424

2525
[patch.crates-io]
2626
# Uncomment to use an unreleased version of cranelift
27-
#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-43.0.0" }
28-
#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-43.0.0" }
29-
#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-43.0.0" }
30-
#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-43.0.0" }
31-
#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-43.0.0" }
32-
#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-43.0.0" }
27+
#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-44.0.0" }
28+
#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-44.0.0" }
29+
#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-44.0.0" }
30+
#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-44.0.0" }
31+
#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-44.0.0" }
32+
#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-44.0.0" }
3333

3434
# Uncomment to use local checkout of cranelift
3535
#cranelift-codegen = { path = "../wasmtime/cranelift/codegen" }

src/debuginfo/emit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl DebugContext {
4343
let _: Result<()> = sections.for_each(|id, section| {
4444
if let Some(section_id) = section_map.get(&id) {
4545
for reloc in &section.relocs {
46-
product.add_debug_reloc(&section_map, section_id, reloc);
46+
product.add_debug_reloc(&section_map, section_id, reloc, true);
4747
}
4848
}
4949
Ok(())

src/debuginfo/object.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cranelift_module::{DataId, FuncId};
22
use cranelift_object::ObjectProduct;
33
use gimli::SectionId;
4-
use object::write::{Relocation, StandardSegment};
4+
use object::write::{Relocation, StandardSection, StandardSegment};
55
use object::{RelocationEncoding, RelocationFlags, SectionKind};
66
use rustc_data_structures::fx::FxHashMap;
77

@@ -16,6 +16,7 @@ pub(super) trait WriteDebugInfo {
1616
section_map: &FxHashMap<SectionId, Self::SectionId>,
1717
from: &Self::SectionId,
1818
reloc: &DebugReloc,
19+
use_section_symbol: bool,
1920
);
2021
}
2122

@@ -27,29 +28,31 @@ impl WriteDebugInfo for ObjectProduct {
2728
id: SectionId,
2829
data: Vec<u8>,
2930
) -> (object::write::SectionId, object::write::SymbolId) {
30-
let name = if self.object.format() == object::BinaryFormat::MachO {
31-
id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info
31+
let (section_id, align);
32+
if id == SectionId::EhFrame {
33+
section_id = self.object.section_id(StandardSection::EhFrame);
34+
align = 8;
3235
} else {
33-
id.name().to_string()
34-
}
35-
.into_bytes();
36-
37-
let segment = self.object.segment_name(StandardSegment::Debug).to_vec();
38-
// FIXME use SHT_X86_64_UNWIND for .eh_frame
39-
let section_id = self.object.add_section(
40-
segment,
41-
name,
42-
if id == SectionId::DebugStr || id == SectionId::DebugLineStr {
43-
SectionKind::DebugString
44-
} else if id == SectionId::EhFrame {
45-
SectionKind::ReadOnlyData
36+
let name = if self.object.format() == object::BinaryFormat::MachO {
37+
id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info
4638
} else {
47-
SectionKind::Debug
48-
},
49-
);
50-
self.object
51-
.section_mut(section_id)
52-
.set_data(data, if id == SectionId::EhFrame { 8 } else { 1 });
39+
id.name().to_string()
40+
}
41+
.into_bytes();
42+
43+
let segment = self.object.segment_name(StandardSegment::Debug).to_vec();
44+
section_id = self.object.add_section(
45+
segment,
46+
name,
47+
if id == SectionId::DebugStr || id == SectionId::DebugLineStr {
48+
SectionKind::DebugString
49+
} else {
50+
SectionKind::Debug
51+
},
52+
);
53+
align = 1;
54+
}
55+
self.object.section_mut(section_id).set_data(data, align);
5356
let symbol_id = self.object.section_symbol(section_id);
5457
(section_id, symbol_id)
5558
}
@@ -59,6 +62,7 @@ impl WriteDebugInfo for ObjectProduct {
5962
section_map: &FxHashMap<SectionId, Self::SectionId>,
6063
from: &Self::SectionId,
6164
reloc: &DebugReloc,
65+
use_section_symbol: bool,
6266
) {
6367
let (symbol, symbol_offset) = match reloc.name {
6468
DebugRelocName::Section(id) => (section_map.get(&id).unwrap().1, 0),
@@ -69,7 +73,11 @@ impl WriteDebugInfo for ObjectProduct {
6973
} else {
7074
self.data_symbol(DataId::from_u32(id & !(1 << 31)))
7175
};
72-
self.object.symbol_section_and_offset(symbol_id).unwrap_or((symbol_id, 0))
76+
if use_section_symbol {
77+
self.object.symbol_section_and_offset(symbol_id).unwrap_or((symbol_id, 0))
78+
} else {
79+
(symbol_id, 0)
80+
}
7381
}
7482
};
7583
self.object

0 commit comments

Comments
 (0)