diff options
| author | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2021-10-07 20:26:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-07 20:26:11 -0700 |
| commit | 6c17601a2e6fa55e5d2ec7284359bee931c0c61a (patch) | |
| tree | cb4a16d19fd744ee5bf6bd608b59b5b1c822044b /compiler/rustc_codegen_llvm/src | |
| parent | 2b6d7f75f7f5ac0bce2265b0e33256356441ccba (diff) | |
| parent | 142f6c0b078ceef1dc817c418f628d350551f6e4 (diff) | |
| download | rust-6c17601a2e6fa55e5d2ec7284359bee931c0c61a.tar.gz rust-6c17601a2e6fa55e5d2ec7284359bee931c0c61a.zip | |
Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoerister
Implement `#[link_ordinal(n)]` Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name. As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL. Part of #58713.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/back/archive.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 11 |
2 files changed, 14 insertions, 7 deletions
diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index ebc3b704158..2fb5a0f9faf 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -163,13 +163,13 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> { // All import names are Rust identifiers and therefore cannot contain \0 characters. // FIXME: when support for #[link_name] implemented, ensure that import.name values don't // have any \0 characters - let import_name_vector: Vec<CString> = dll_imports + let import_name_and_ordinal_vector: Vec<(CString, Option<u16>)> = dll_imports .iter() .map(|import: &DllImport| { if self.config.sess.target.arch == "x86" { - LlvmArchiveBuilder::i686_decorated_name(import) + (LlvmArchiveBuilder::i686_decorated_name(import), import.ordinal) } else { - CString::new(import.name.to_string()).unwrap() + (CString::new(import.name.to_string()).unwrap(), import.ordinal) } }) .collect(); @@ -184,9 +184,9 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> { dll_imports.iter().map(|import| import.name.to_string()).collect::<Vec<_>>().join(", "), ); - let ffi_exports: Vec<LLVMRustCOFFShortExport> = import_name_vector + let ffi_exports: Vec<LLVMRustCOFFShortExport> = import_name_and_ordinal_vector .iter() - .map(|name_z| LLVMRustCOFFShortExport::from_name(name_z.as_ptr())) + .map(|(name_z, ordinal)| LLVMRustCOFFShortExport::new(name_z.as_ptr(), *ordinal)) .collect(); let result = unsafe { crate::llvm::LLVMRustWriteImportLibrary( diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 5d437b2a068..63eca00de2a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -34,11 +34,18 @@ pub enum LLVMRustResult { #[repr(C)] pub struct LLVMRustCOFFShortExport { pub name: *const c_char, + pub ordinal_present: bool, + // value of `ordinal` only important when `ordinal_present` is true + pub ordinal: u16, } impl LLVMRustCOFFShortExport { - pub fn from_name(name: *const c_char) -> LLVMRustCOFFShortExport { - LLVMRustCOFFShortExport { name } + pub fn new(name: *const c_char, ordinal: Option<u16>) -> LLVMRustCOFFShortExport { + LLVMRustCOFFShortExport { + name, + ordinal_present: ordinal.is_some(), + ordinal: ordinal.unwrap_or(0), + } } } |
