Skip to content

Commit e7e15de

Browse files
authored
Merge pull request #245 from zanieb/zb/i686-win-ii
Fix i686 MSVC linking by handling name mangling
2 parents d390e92 + 7df767f commit e7e15de

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

cargo-auditable/src/object_file.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,28 @@ windows
322322
assert_eq!(result.architecture(), Architecture::X86_64);
323323
}
324324

325+
#[test]
326+
fn test_create_object_file_windows_msvc_i686() {
327+
let rustc_output = br#"debug_assertions
328+
target_arch="x86"
329+
target_endian="little"
330+
target_env="msvc"
331+
target_family="windows"
332+
target_feature="fxsr"
333+
target_feature="sse"
334+
target_feature="sse2"
335+
target_os="windows"
336+
target_pointer_width="32"
337+
target_vendor="pc"
338+
windows
339+
"#;
340+
let target_triple = "i686-pc-windows-msvc";
341+
let target_info = parse_rustc_target_info(rustc_output);
342+
let result = create_object_file(&target_info, target_triple).unwrap();
343+
assert_eq!(result.format(), BinaryFormat::Coff);
344+
assert_eq!(result.architecture(), Architecture::I386);
345+
}
346+
325347
#[test]
326348
fn test_create_object_file_windows_gnu() {
327349
let rustc_output = br#"debug_assertions

cargo-auditable/src/platform_detection.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pub fn is_32bit(target_info: &RustcTargetInfo) -> bool {
2222
key_equals(target_info, "target_pointer_width", "32")
2323
}
2424

25+
pub fn is_32bit_x86(target_info: &RustcTargetInfo) -> bool {
26+
key_equals(target_info, "target_arch", "x86")
27+
}
28+
2529
fn key_equals(target_info: &RustcTargetInfo, key: &str, value: &str) -> bool {
2630
target_info.get(key).map(|s| s.as_str()) == Some(value)
2731
}

cargo-auditable/src/rustc_wrapper.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66

77
use crate::{
88
binary_file, collect_audit_data,
9-
platform_detection::{is_apple, is_msvc, is_wasm},
9+
platform_detection::{is_32bit_x86, is_apple, is_msvc, is_wasm},
1010
rustc_arguments::{self, should_embed_audit_data},
1111
target_info,
1212
};
@@ -134,7 +134,14 @@ fn rustc_command_with_audit_data(rustc_path: &OsStr) -> Option<Command> {
134134
command.arg("-Clink-arg=-Wl,-u,_AUDITABLE_VERSION_INFO");
135135
}
136136
} else if is_msvc(&target_info) {
137-
command.arg("-Clink-arg=/INCLUDE:AUDITABLE_VERSION_INFO");
137+
// On x86 MSVC, the `object` crate's CoffI386 mangling adds a `_`
138+
// prefix to global symbols, so the linker must reference the
139+
// decorated name.
140+
if is_32bit_x86(&target_info) {
141+
command.arg("-Clink-arg=/INCLUDE:_AUDITABLE_VERSION_INFO");
142+
} else {
143+
command.arg("-Clink-arg=/INCLUDE:AUDITABLE_VERSION_INFO");
144+
}
138145
} else if is_wasm(&target_info) {
139146
// We don't emit the symbol name in WASM, so nothing to do
140147
} else {

0 commit comments

Comments
 (0)