Skip to content

Commit a1cc5ac

Browse files
robarnoldgraydon
authored andcommitted
Adapt elf.ml to handle differences between Linux and FreeBSD.
1 parent 6466795 commit a1cc5ac

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/boot/be/elf.ml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type ei_data =
4444
;;
4545

4646

47-
let elf_identification ei_class ei_data =
47+
let elf_identification sess ei_class ei_data =
4848
SEQ
4949
[|
5050
STRING "\x7fELF";
@@ -58,9 +58,17 @@ let elf_identification ei_class ei_data =
5858
ELFDATANONE -> 0
5959
| ELFDATA2LSB -> 1
6060
| ELFDATA2MSB -> 2);
61+
6162
1; (* EI_VERSION = EV_CURRENT *)
62-
0; (* EI_PAD #7 *)
63-
0; (* EI_PAD #8 *)
63+
64+
(* EI_OSABI *)
65+
(match sess.Session.sess_targ with
66+
FreeBSD_x86_elf -> 9
67+
| Linux_x86_elf -> 3
68+
| _ -> 0);
69+
70+
0; (* EI_ABIVERSION *)
71+
6472
0; (* EI_PAD #9 *)
6573
0; (* EI_PAD #A *)
6674
0; (* EI_PAD #B *)
@@ -117,7 +125,7 @@ let elf32_header
117125
in
118126
DEF
119127
(elf_header_fixup,
120-
SEQ [| elf_identification ELFCLASS32 ei_data;
128+
SEQ [| elf_identification sess ELFCLASS32 ei_data;
121129
WORD (TY_u16, (IMM (match e_type with
122130
ET_NONE -> 0L
123131
| ET_REL -> 1L
@@ -1290,7 +1298,11 @@ let elf32_linux_x86_file
12901298
in
12911299

12921300
let interp_section =
1293-
DEF (interp_section_fixup, ZSTRING "/lib/ld-linux.so.2")
1301+
1302+
DEF (interp_section_fixup, ZSTRING
1303+
(if sess.Session.sess_targ = FreeBSD_x86_elf
1304+
then "/libexec/ld-elf.so.1"
1305+
else "/lib/ld-linux.so.2"))
12941306
in
12951307

12961308
let text_section =
@@ -1584,7 +1596,9 @@ let emit_file
15841596

15851597
let needed_libs =
15861598
[|
1587-
"libc.so.6";
1599+
if sess.Session.sess_targ = FreeBSD_x86_elf
1600+
then "libc.so.7"
1601+
else "libc.so.6";
15881602
"librustrt.so"
15891603
|]
15901604
in

0 commit comments

Comments
 (0)