about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRob Arnold <robarnold@cs.cmu.edu>2011-02-05 01:09:35 -0800
committerGraydon Hoare <graydon@mozilla.com>2011-02-09 11:37:20 -0800
commita1cc5ac63c7d2b7da595cbc31253389a991824bd (patch)
treec41fc35812483fd062e2b3c6f58d5c93c863a425
parent6466795a70df56f89405df1ed438c8f8b58fed3a (diff)
Adapt elf.ml to handle differences between Linux and FreeBSD.
-rw-r--r--src/boot/be/elf.ml26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/boot/be/elf.ml b/src/boot/be/elf.ml
index 406508e4b5e..a1706082f5a 100644
--- a/src/boot/be/elf.ml
+++ b/src/boot/be/elf.ml
@@ -44,7 +44,7 @@ type ei_data =
 ;;
 
 
-let elf_identification ei_class ei_data =
+let elf_identification sess ei_class ei_data =
   SEQ
     [|
       STRING "\x7fELF";
@@ -58,9 +58,17 @@ let elf_identification ei_class ei_data =
                ELFDATANONE -> 0
              | ELFDATA2LSB -> 1
              | ELFDATA2MSB -> 2);
+
           1;                    (* EI_VERSION = EV_CURRENT *)
-          0;                    (* EI_PAD #7 *)
-          0;                    (* EI_PAD #8 *)
+
+                                (* EI_OSABI *)
+          (match sess.Session.sess_targ with
+               FreeBSD_x86_elf -> 9
+             | Linux_x86_elf -> 3
+             | _ -> 0);
+
+          0;                    (* EI_ABIVERSION *)
+
           0;                    (* EI_PAD #9 *)
           0;                    (* EI_PAD #A *)
           0;                    (* EI_PAD #B *)
@@ -117,7 +125,7 @@ let elf32_header
   in
     DEF
       (elf_header_fixup,
-       SEQ [| elf_identification ELFCLASS32 ei_data;
+       SEQ [| elf_identification sess ELFCLASS32 ei_data;
               WORD (TY_u16, (IMM (match e_type with
                                       ET_NONE -> 0L
                                     | ET_REL -> 1L
@@ -1290,7 +1298,11 @@ let elf32_linux_x86_file
   in
 
   let interp_section =
-    DEF (interp_section_fixup, ZSTRING "/lib/ld-linux.so.2")
+
+    DEF (interp_section_fixup, ZSTRING
+           (if sess.Session.sess_targ = FreeBSD_x86_elf
+            then "/libexec/ld-elf.so.1"
+            else "/lib/ld-linux.so.2"))
   in
 
   let text_section =
@@ -1584,7 +1596,9 @@ let emit_file
 
   let needed_libs =
     [|
-      "libc.so.6";
+      if sess.Session.sess_targ = FreeBSD_x86_elf
+      then "libc.so.7"
+      else "libc.so.6";
       "librustrt.so"
     |]
   in