Skip to content

Commit 30508fa

Browse files
committedMar 1, 2025
Auto merge of rust-lang#137796 - jieyouxu:rollup-qt9yr1g, r=jieyouxu
Rollup of 10 pull requests Successful merges: - rust-lang#134943 (Add FileCheck annotations to mir-opt/issues) - rust-lang#137017 (Don't error when adding a staticlib with bitcode files compiled by newer LLVM) - rust-lang#137197 (Update some comparison codegen tests now that they pass in LLVM20) - rust-lang#137540 (Fix (more) test directives that were accidentally ignored) - rust-lang#137551 (import `simd_` intrinsics) - rust-lang#137599 (tests: use minicore more) - rust-lang#137673 (Fix Windows `Command` search path bug) - rust-lang#137676 (linker: Fix escaping style for response files on Windows) - rust-lang#137693 (Re-enable `--generate-link-to-defintion` for tools internal rustdoc) - rust-lang#137770 (Fix sized constraint for unsafe binder) r? `@ghost` `@rustbot` modify labels: rollup
2 parents aa3c2d7 + 0cb9827 commit 30508fa

File tree

300 files changed

+1614
-2162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+1614
-2162
lines changed
 

‎compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,33 @@ fn get_llvm_object_symbols(
132132
if err.is_null() {
133133
return Ok(true);
134134
} else {
135-
return Err(unsafe { *Box::from_raw(err as *mut io::Error) });
135+
let error = unsafe { *Box::from_raw(err as *mut io::Error) };
136+
// These are the magic constants for LLVM bitcode files:
137+
// https://github.com/llvm/llvm-project/blob/7eadc1960d199676f04add402bb0aa6f65b7b234/llvm/lib/BinaryFormat/Magic.cpp#L90-L97
138+
if buf.starts_with(&[0xDE, 0xCE, 0x17, 0x0B]) || buf.starts_with(&[b'B', b'C', 0xC0, 0xDE])
139+
{
140+
// For LLVM bitcode, failure to read the symbols is not fatal. The bitcode may have been
141+
// produced by a newer LLVM version that the one linked to rustc. This is fine provided
142+
// that the linker does use said newer LLVM version. We skip writing the symbols for the
143+
// bitcode to the symbol table of the archive. Traditional linkers don't like this, but
144+
// newer linkers like lld, mold and wild ignore the symbol table anyway, so if they link
145+
// against a new enough LLVM it will work out in the end.
146+
// LLVM's archive writer also has this same behavior of only warning about invalid
147+
// bitcode since https://github.com/llvm/llvm-project/pull/96848
148+
149+
// We don't have access to the DiagCtxt here to produce a nice warning in the correct format.
150+
eprintln!("warning: Failed to read symbol table from LLVM bitcode: {}", error);
151+
return Ok(true);
152+
} else {
153+
return Err(error);
154+
}
136155
}
137156

138157
unsafe extern "C" fn callback(state: *mut c_void, symbol_name: *const c_char) -> *mut c_void {
139158
let f = unsafe { &mut *(state as *mut &mut dyn FnMut(&[u8]) -> io::Result<()>) };
140159
match f(unsafe { CStr::from_ptr(symbol_name) }.to_bytes()) {
141160
Ok(()) => std::ptr::null_mut(),
142-
Err(err) => Box::into_raw(Box::new(err)) as *mut c_void,
161+
Err(err) => Box::into_raw(Box::new(err) as Box<io::Error>) as *mut c_void,
143162
}
144163
}
145164

@@ -148,7 +167,7 @@ fn get_llvm_object_symbols(
148167
Box::into_raw(Box::new(io::Error::new(
149168
io::ErrorKind::Other,
150169
format!("LLVM error: {}", error.to_string_lossy()),
151-
))) as *mut c_void
170+
)) as Box<io::Error>) as *mut c_void
152171
}
153172
}
154173

‎compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,8 +1726,12 @@ fn exec_linker(
17261726
args.push_str(
17271727
&Escape {
17281728
arg: arg.to_str().unwrap(),
1729-
// LLD also uses MSVC-like parsing for @-files by default when running on windows hosts
1730-
is_like_msvc: sess.target.is_like_msvc || (cfg!(windows) && flavor.uses_lld()),
1729+
// Windows-style escaping for @-files is used by
1730+
// - all linkers targeting MSVC-like targets, including LLD
1731+
// - all LLD flavors running on Windows hosts
1732+
// С/С++ compilers use Posix-style escaping (except clang-cl, which we do not use).
1733+
is_like_msvc: sess.target.is_like_msvc
1734+
|| (cfg!(windows) && flavor.uses_lld() && !flavor.uses_cc()),
17311735
}
17321736
.to_string(),
17331737
);

0 commit comments

Comments
 (0)
Please sign in to comment.