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.
This commit is contained in:
commit
6c17601a2e
20 changed files with 201 additions and 23 deletions
|
@ -1753,10 +1753,11 @@ LLVMRustBuildMaxNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {
|
|||
}
|
||||
|
||||
// This struct contains all necessary info about a symbol exported from a DLL.
|
||||
// At the moment, it's just the symbol's name, but we use a separate struct to
|
||||
// make it easier to add other information like ordinal later.
|
||||
struct LLVMRustCOFFShortExport {
|
||||
const char* name;
|
||||
bool ordinal_present;
|
||||
// The value of `ordinal` is only meaningful if `ordinal_present` is true.
|
||||
uint16_t ordinal;
|
||||
};
|
||||
|
||||
// Machine must be a COFF machine type, as defined in PE specs.
|
||||
|
@ -1772,13 +1773,15 @@ extern "C" LLVMRustResult LLVMRustWriteImportLibrary(
|
|||
ConvertedExports.reserve(NumExports);
|
||||
|
||||
for (size_t i = 0; i < NumExports; ++i) {
|
||||
bool ordinal_present = Exports[i].ordinal_present;
|
||||
uint16_t ordinal = ordinal_present ? Exports[i].ordinal : 0;
|
||||
ConvertedExports.push_back(llvm::object::COFFShortExport{
|
||||
Exports[i].name, // Name
|
||||
std::string{}, // ExtName
|
||||
std::string{}, // SymbolName
|
||||
std::string{}, // AliasTarget
|
||||
0, // Ordinal
|
||||
false, // Noname
|
||||
ordinal, // Ordinal
|
||||
ordinal_present, // Noname
|
||||
false, // Data
|
||||
false, // Private
|
||||
false // Constant
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue