Created
August 15, 2020 03:37
-
-
Save tinaun/743c56dcd1722d301e10788fff2e4d0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source_filename = "1tyt6immxwy9a8vn" | |
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-pc-windows-msvc" | |
%.win32.image_import_desc = type { i32, i32, i32, i32, i32 } | |
@__ImageBase = external global i8 | |
@import.mydll.1.dll.dll_name = private constant [11 x i8] c"mydll.1.dll", section ".idata$7" | |
@import.mydll.1.dll.fn.add = private constant [6 x i8] c"\00\00add\00", section ".idata$6" | |
@import.mydll.1.dll.fn.sub = private constant [6 x i8] c"\00\00sub\00", section ".idata$6" | |
@import.mydll.1.dll.desc = private global [3 x i8*] [ | |
i8* getelementptr inbounds ([6 x i8], [6 x i8]* @import.mydll.1.dll.fn.add, i32 0, i32 0), | |
i8* getelementptr inbounds ([6 x i8], [6 x i8]* @import.mydll.1.dll.fn.sub, i32 0, i32 0), | |
i8* null | |
], section ".idata$4" | |
@import.mydll.1.dll.ptr = private global [3 x i8*] [ | |
i8* getelementptr inbounds ([6 x i8], [6 x i8]* @import.mydll.1.dll.fn.add, i32 0, i32 0), | |
i8* getelementptr inbounds ([6 x i8], [6 x i8]* @import.mydll.1.dll.fn.sub, i32 0, i32 0), | |
i8* null | |
], section ".idata$3" | |
@.dllimport = constant [2 x %.win32.image_import_desc] [ | |
%.win32.image_import_desc { | |
i32 sub (i32 ptrtoint ([3 x i8*]* @import.mydll.1.dll.desc to i32), i32 ptrtoint (i8* @__ImageBase to i32)), | |
i32 0, | |
i32 0, | |
i32 sub (i32 ptrtoint ([11 x i8]* @import.mydll.1.dll.dll_name to i32), i32 ptrtoint (i8* @__ImageBase to i32)), | |
i32 sub (i32 ptrtoint ([3 x i8*]* @import.mydll.1.dll.ptr to i32), i32 ptrtoint (i8* @__ImageBase to i32)) | |
}, | |
%.win32.image_import_desc zeroinitializer | |
], section ".idata$2" | |
!llvm.module.flags = !{!0, !1} | |
!0 = !{i32 7, !"PIC Level", i32 2} | |
!1 = !{i32 7, !"PIE Level", i32 2} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(raw_dylib)] | |
mod mydll { | |
#[link(kind="raw-dylib", name="mydll.1.dll")] | |
extern "C" { | |
pub fn add(a: i32, b: i32) -> i32; | |
pub fn sub(a: i32, b: i32) -> i32; | |
} | |
} | |
pub fn call_external_functions(a: i32, b: i32, c: i32) -> i32 { | |
unsafe { | |
let x = mydll::add(a, b); | |
mydll::sub(x, c) | |
} | |
} | |
fn main() { | |
std::process::exit(call_external_functions(3, 4, 5)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment