From 22eca31d98ce3e1bc5690799e669911e4d06a5aa Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Sun, 18 Jul 2010 07:35:25 +0800 Subject: Fix argv.rs under the LLVM compiler. The call to rust_start was assuming that all rust main() functions have the same signature, but the compiler doesn't actually canonicalize them. So instead just match the C signature of rust_start, and cast. --- src/boot/llvm/llabi.ml | 15 +++++++-------- src/boot/llvm/llfinal.ml | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/boot') diff --git a/src/boot/llvm/llabi.ml b/src/boot/llvm/llabi.ml index 6a2c6a05..09340c53 100644 --- a/src/boot/llvm/llabi.ml +++ b/src/boot/llvm/llabi.ml @@ -11,6 +11,8 @@ type abi = { let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi = let i32 = Llvm.i32_type llctx in + (* FIXME: Use Llvm_target.intptr_type for more platform support. *) + let word_ty = i32 in let crate_ty = (* TODO: other architectures besides x86 *) @@ -51,19 +53,16 @@ let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi = ignore (Llvm.define_type_name "rust_task" task_ty llmod); let rust_start_ty = - let task_ptr_ty = Llvm.pointer_type task_ty in - let llnilty = Llvm.array_type (Llvm.i1_type llctx) 0 in - let main_ty = Llvm.function_type (Llvm.void_type llctx) - [| Llvm.pointer_type llnilty; task_ptr_ty; |] - in - let args_ty = Array.map Llvm.pointer_type [| main_ty; crate_ty; |] in - let args_ty = Array.append args_ty [| i32; i32 |] in + (* Rust's main function can have several types, so we cast them + all to uintptr_t. *) + let main_ty = word_ty in + let args_ty = [| main_ty; Llvm.pointer_type crate_ty; i32; i32 |] in Llvm.function_type i32 args_ty in { crate_ty = crate_ty; task_ty = task_ty; - word_ty = i32; + word_ty = word_ty; rust_start = Llvm.declare_function "rust_start" rust_start_ty llmod } ;; diff --git a/src/boot/llvm/llfinal.ml b/src/boot/llvm/llfinal.ml index fd65fa6b..7241d1ab 100644 --- a/src/boot/llvm/llfinal.ml +++ b/src/boot/llvm/llfinal.ml @@ -79,7 +79,8 @@ let finalize_module | Some fn -> fn in let rust_start = abi.Llabi.rust_start in - let rust_start_args = [| rust_main_fn; crate_ptr; argc; argv |] in + let rust_start_args = [| Llvm.const_ptrtoint rust_main_fn abi.Llabi.word_ty; + crate_ptr; argc; argv |] in ignore (Llvm.build_call rust_start rust_start_args "start_rust" main_builder); ignore (Llvm.build_ret (Llvm.const_int i32 0) main_builder) -- cgit v1.2.3