about summary refs log tree commit diff
path: root/src/boot
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2010-07-18 07:35:25 +0800
committerGraydon Hoare <graydon@pobox.com>2010-07-18 14:25:19 +0800
commit22eca31d98ce3e1bc5690799e669911e4d06a5aa (patch)
treec964fb3ca34ec34f4b9685d711c5097f7c7d0a22 /src/boot
parent8ebf72ed29f7f6cb35051d766ba9900509f4aaa1 (diff)
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.
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/llvm/llabi.ml15
-rw-r--r--src/boot/llvm/llfinal.ml3
2 files changed, 9 insertions, 9 deletions
diff --git a/src/boot/llvm/llabi.ml b/src/boot/llvm/llabi.ml
index 6a2c6a05f69..09340c53645 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 fd65fa6b089..7241d1ab33e 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)