Skip to content

Commit 48199e0

Browse files
authored
Rollup merge of rust-lang#96523 - nbdd0121:windows, r=petrochenkov
Add `@feat.00` symbol to symbols.o for COFF Fix rust-lang#96498 This is based on top of rust-lang#96444. r? ``@petrochenkov``
2 parents 109008a + 0fce0db commit 48199e0

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,29 @@ fn add_linked_symbol_object(
17001700
// We handle the name decoration of COFF targets in `symbol_export.rs`, so disable the
17011701
// default mangler in `object` crate.
17021702
file.set_mangling(object::write::Mangling::None);
1703+
1704+
// Add feature flags to the object file. On MSVC this is optional but LLD will complain if
1705+
// not present.
1706+
let mut feature = 0;
1707+
1708+
if file.architecture() == object::Architecture::I386 {
1709+
// Indicate that all SEH handlers are registered in .sxdata section.
1710+
// We don't have generate any code, so we don't need .sxdata section but LLD still
1711+
// expects us to set this bit (see #96498).
1712+
// Reference: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
1713+
feature |= 1;
1714+
}
1715+
1716+
file.add_symbol(object::write::Symbol {
1717+
name: "@feat.00".into(),
1718+
value: feature,
1719+
size: 0,
1720+
kind: object::SymbolKind::Data,
1721+
scope: object::SymbolScope::Compilation,
1722+
weak: false,
1723+
section: object::write::SymbolSection::Absolute,
1724+
flags: object::SymbolFlags::None,
1725+
});
17031726
}
17041727

17051728
for (sym, kind) in symbols.iter() {
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# only-windows
2+
# needs-rust-lld
3+
4+
-include ../../run-make-fulldeps/tools.mk
5+
6+
# Ensure that LLD can link
7+
all:
8+
$(RUSTC) -C linker=rust-lld foo.rs

src/test/run-make/issue-96498/foo.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![crate_type = "cdylib"]
2+
3+
#[no_mangle]
4+
extern "C" fn foo() {}

0 commit comments

Comments
 (0)