Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7aef4be

Browse files
committed
Auto merge of #145721 - dpaoliello:ar050, r=bjorn3
Update to ar_archive_writer 0.5 This updates `ar_archive_writer` to 0.5, which in turn was updated to match LLVM 20.1.8: <rust-lang/ar_archive_writer#24> As part of this, I refactored part of `SymbolWrapper.cpp` to pull common code that I was about to duplicate again into a new function. NOTE: `ar_archive_writer` does include a breaking change where it no longer supports mangling C++ mangled names for Arm64EC. Since we don't need the mangled name (it's not the "exported name" which we're trying to load from the external dll), I'm setting the `import_name` when building for Arm64EC to prevent error when failing to mangle. r? `@bjorn3`
2 parents 154037f + 4daae65 commit 7aef4be

File tree

6 files changed

+82
-56
lines changed

6 files changed

+82
-56
lines changed

‎Cargo.lock‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
158158

159159
[[package]]
160160
name = "ar_archive_writer"
161-
version = "0.4.2"
161+
version = "0.5.1"
162162
source = "registry+https://github.com/rust-lang/crates.io-index"
163-
checksum = "01667f6f40216b9a0b2945e05fed5f1ad0ab6470e69cb9378001e37b1c0668e4"
163+
checksum = "7eb93bbb63b9c227414f6eb3a0adfddca591a8ce1e9b60661bb08969b87e340b"
164164
dependencies = [
165-
"object 0.36.7",
165+
"object 0.37.3",
166166
]
167167

168168
[[package]]

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static LLVM_OBJECT_READER: ObjectReader = ObjectReader {
2626
get_symbols: get_llvm_object_symbols,
2727
is_64_bit_object_file: llvm_is_64_bit_object_file,
2828
is_ec_object_file: llvm_is_ec_object_file,
29+
is_any_arm64_coff: llvm_is_any_arm64_coff,
2930
get_xcoff_member_alignment: DEFAULT_OBJECT_READER.get_xcoff_member_alignment,
3031
};
3132

@@ -95,3 +96,7 @@ fn llvm_is_64_bit_object_file(buf: &[u8]) -> bool {
9596
fn llvm_is_ec_object_file(buf: &[u8]) -> bool {
9697
unsafe { llvm::LLVMRustIsECObject(buf.as_ptr(), buf.len()) }
9798
}
99+
100+
fn llvm_is_any_arm64_coff(buf: &[u8]) -> bool {
101+
unsafe { llvm::LLVMRustIsAnyArm64Coff(buf.as_ptr(), buf.len()) }
102+
}

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,6 +2686,8 @@ unsafe extern "C" {
26862686

26872687
pub(crate) fn LLVMRustIsECObject(buf_ptr: *const u8, buf_len: usize) -> bool;
26882688

2689+
pub(crate) fn LLVMRustIsAnyArm64Coff(buf_ptr: *const u8, buf_len: usize) -> bool;
2690+
26892691
pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value);
26902692
pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value);
26912693
}

‎compiler/rustc_codegen_ssa/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
ar_archive_writer = "0.4.2"
8+
ar_archive_writer = "0.5"
99
bitflags.workspace = true
1010
bstr = "1.11.3"
1111
# `cc` updates often break things, so we pin it here. Cargo enforces "max 1 semver-compat version

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ pub struct ImportLibraryItem {
4040
pub is_data: bool,
4141
}
4242

43-
impl From<ImportLibraryItem> for COFFShortExport {
44-
fn from(item: ImportLibraryItem) -> Self {
43+
impl ImportLibraryItem {
44+
fn into_coff_short_export(self, sess: &Session) -> COFFShortExport {
45+
let import_name = (sess.target.arch == "arm64ec").then(|| self.name.clone());
4546
COFFShortExport {
46-
name: item.name,
47+
name: self.name,
4748
ext_name: None,
48-
symbol_name: item.symbol_name,
49-
alias_target: None,
50-
ordinal: item.ordinal.unwrap_or(0),
51-
noname: item.ordinal.is_some(),
52-
data: item.is_data,
49+
symbol_name: self.symbol_name,
50+
import_name,
51+
export_as: None,
52+
ordinal: self.ordinal.unwrap_or(0),
53+
noname: self.ordinal.is_some(),
54+
data: self.is_data,
5355
private: false,
5456
constant: false,
5557
}
@@ -113,7 +115,8 @@ pub trait ArchiveBuilderBuilder {
113115
.emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() }),
114116
};
115117

116-
let exports = items.into_iter().map(Into::into).collect::<Vec<_>>();
118+
let exports =
119+
items.into_iter().map(|item| item.into_coff_short_export(sess)).collect::<Vec<_>>();
117120
let machine = match &*sess.target.arch {
118121
"x86_64" => MachineTypes::AMD64,
119122
"x86" => MachineTypes::I386,
@@ -134,6 +137,7 @@ pub trait ArchiveBuilderBuilder {
134137
// when linking a rust staticlib using `/WHOLEARCHIVE`.
135138
// See #129020
136139
true,
140+
&[],
137141
) {
138142
sess.dcx()
139143
.emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() });
@@ -527,7 +531,7 @@ impl<'a> ArArchiveBuilder<'a> {
527531
&entries,
528532
archive_kind,
529533
false,
530-
/* is_ec = */ self.sess.target.arch == "arm64ec",
534+
/* is_ec = */ Some(self.sess.target.arch == "arm64ec"),
531535
)?;
532536
archive_tmpfile.flush()?;
533537
drop(archive_tmpfile);

‎compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp‎

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ LLVMRustGetSymbols(char *BufPtr, size_t BufLen, void *State,
103103
#define TRUE_PTR (void *)1
104104
#define FALSE_PTR (void *)0
105105

106-
extern "C" bool LLVMRustIs64BitSymbolicFile(char *BufPtr, size_t BufLen) {
106+
bool withBufferAsSymbolicFile(
107+
char *BufPtr, size_t BufLen,
108+
std::function<bool(object::SymbolicFile &)> Callback) {
107109
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(
108110
StringRef(BufPtr, BufLen), StringRef("LLVMRustGetSymbolsObject"), false);
109111
SmallString<0> SymNameBuf;
110112
auto SymName = raw_svector_ostream(SymNameBuf);
111113

112-
// Code starting from this line is copied from s64BitSymbolicFile in
113-
// ArchiveWriter.cpp.
114114
// In the scenario when LLVMContext is populated SymbolicFile will contain a
115115
// reference to it, thus SymbolicFile should be destroyed first.
116116
LLVMContext Context;
@@ -120,48 +120,63 @@ extern "C" bool LLVMRustIs64BitSymbolicFile(char *BufPtr, size_t BufLen) {
120120
return false;
121121
}
122122
std::unique_ptr<object::SymbolicFile> Obj = std::move(*ObjOrErr);
123-
124-
return Obj != nullptr ? Obj->is64Bit() : false;
125-
}
126-
127-
extern "C" bool LLVMRustIsECObject(char *BufPtr, size_t BufLen) {
128-
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(
129-
StringRef(BufPtr, BufLen), StringRef("LLVMRustGetSymbolsObject"), false);
130-
SmallString<0> SymNameBuf;
131-
auto SymName = raw_svector_ostream(SymNameBuf);
132-
133-
// In the scenario when LLVMContext is populated SymbolicFile will contain a
134-
// reference to it, thus SymbolicFile should be destroyed first.
135-
LLVMContext Context;
136-
Expected<std::unique_ptr<object::SymbolicFile>> ObjOrErr =
137-
getSymbolicFile(Buf->getMemBufferRef(), Context);
138-
if (!ObjOrErr) {
139-
return false;
140-
}
141-
std::unique_ptr<object::SymbolicFile> Obj = std::move(*ObjOrErr);
142-
143123
if (Obj == nullptr) {
144124
return false;
145125
}
126+
return Callback(*Obj);
127+
}
146128

147-
// Code starting from this line is copied from isECObject in
148-
// ArchiveWriter.cpp with an extra #if to work with LLVM 17.
149-
if (Obj->isCOFF())
150-
return cast<llvm::object::COFFObjectFile>(&*Obj)->getMachine() !=
151-
COFF::IMAGE_FILE_MACHINE_ARM64;
152-
153-
if (Obj->isCOFFImportFile())
154-
return cast<llvm::object::COFFImportFile>(&*Obj)->getMachine() !=
155-
COFF::IMAGE_FILE_MACHINE_ARM64;
156-
157-
if (Obj->isIR()) {
158-
Expected<std::string> TripleStr =
159-
getBitcodeTargetTriple(Obj->getMemoryBufferRef());
160-
if (!TripleStr)
161-
return false;
162-
Triple T(*TripleStr);
163-
return T.isWindowsArm64EC() || T.getArch() == Triple::x86_64;
164-
}
129+
extern "C" bool LLVMRustIs64BitSymbolicFile(char *BufPtr, size_t BufLen) {
130+
return withBufferAsSymbolicFile(
131+
BufPtr, BufLen, [](object::SymbolicFile &Obj) { return Obj.is64Bit(); });
132+
}
133+
134+
extern "C" bool LLVMRustIsECObject(char *BufPtr, size_t BufLen) {
135+
return withBufferAsSymbolicFile(
136+
BufPtr, BufLen, [](object::SymbolicFile &Obj) {
137+
// Code starting from this line is copied from isECObject in
138+
// ArchiveWriter.cpp with an extra #if to work with LLVM 17.
139+
if (Obj.isCOFF())
140+
return cast<llvm::object::COFFObjectFile>(&Obj)->getMachine() !=
141+
COFF::IMAGE_FILE_MACHINE_ARM64;
142+
143+
if (Obj.isCOFFImportFile())
144+
return cast<llvm::object::COFFImportFile>(&Obj)->getMachine() !=
145+
COFF::IMAGE_FILE_MACHINE_ARM64;
146+
147+
if (Obj.isIR()) {
148+
Expected<std::string> TripleStr =
149+
getBitcodeTargetTriple(Obj.getMemoryBufferRef());
150+
if (!TripleStr)
151+
return false;
152+
Triple T(*TripleStr);
153+
return T.isWindowsArm64EC() || T.getArch() == Triple::x86_64;
154+
}
155+
156+
return false;
157+
});
158+
}
165159

166-
return false;
160+
extern "C" bool LLVMRustIsAnyArm64Coff(char *BufPtr, size_t BufLen) {
161+
return withBufferAsSymbolicFile(
162+
BufPtr, BufLen, [](object::SymbolicFile &Obj) {
163+
// Code starting from this line is copied from isAnyArm64COFF in
164+
// ArchiveWriter.cpp.
165+
if (Obj.isCOFF())
166+
return COFF::isAnyArm64(cast<COFFObjectFile>(&Obj)->getMachine());
167+
168+
if (Obj.isCOFFImportFile())
169+
return COFF::isAnyArm64(cast<COFFImportFile>(&Obj)->getMachine());
170+
171+
if (Obj.isIR()) {
172+
Expected<std::string> TripleStr =
173+
getBitcodeTargetTriple(Obj.getMemoryBufferRef());
174+
if (!TripleStr)
175+
return false;
176+
Triple T(*TripleStr);
177+
return T.isOSWindows() && T.getArch() == Triple::aarch64;
178+
}
179+
180+
return false;
181+
});
167182
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /