Skip to content

Commit 1181879

Browse files
XVilkagitoleg
authored andcommitted
Try to build with OCaml 4.08 version (#957)
* Try to build with OCaml 4.08 version * Add OCaml 4.08 into the CI script * Try to build with JaneStreet 0.12 libs version * changes for compilation with core_kernel.v0.12.0 - added dependencies from core_kernel.rope and core_kernel.binary_packing - used `Caml.Filename`, because `temp_file` wasn't exposed in `Core_kernel.Filename` - used `Mmap.V1.map_file` instead of `Bigarray.Genarray.memmap`. Althoug it's a temporary change because most likely we'll drop the support of 4.04.1, 4.05, 4.06 compilers, and can use just `Unix.map_file` instead there are lot's of warnings that should be fixed, so it's work in progress * List.equal doesn't take labeled argument anymore * merged with master, updated set of compilers * List.zip now uses Or_unequal_lengths * cleaned up oasis * a couple of minor fixes 1) no global build dependency from core_kernel 2) removed Self from Bap_recipe - probably a merge artifact * everything compiles, lot's of warning though( * removed polymorphic compare almost everywhere * fixes few more lost polymorphic compare + warnings * fixed one more deprecated * updates testsuite submodule * revert changes in text-tags * remove new Format functions from bap_ir * updated testsuite/bap-veri/ * silenced a couple of warnings * reworked bap-future applicative interface * updated bap-future, replaced Caml.ignore to ignore * added travis 4.09 to travis * added setup.ml.pre.in to hide warnings of setup.ml File "oasis/common.setup.ml.in", line 1773, characters 22-40: Alert deprecated: module Stdlib.Pervasives Use Stdlib instead. If you need to stay compatible with OCaml < 4.07, you can use the stdlib-shims library: https://github.com/ocaml/stdlib-shims File "setup.ml", line 3467, characters 16-34: 3467 | Pervasives.compare o2 o1) ^^^^^^^^^^^^^^^^^^ Alert deprecated: module Stdlib.Pervasives Use Stdlib instead. If you need to stay compatible with OCaml < 4.07, you can use the stdlib-shims library: https://github.com/ocaml/stdlib-shims Co-authored-by: gitoleg <[email protected]>
1 parent b40689e commit 1181879

File tree

151 files changed

+635
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+635
-451
lines changed

.travis-ocaml.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ install_on_linux () {
7373
4.07,1.2.2)
7474
OCAML_VERSION=4.02; OCAML_FULL_VERSION=4.07.0
7575
ppa=avsm/ocaml42+opam12 ;;
76+
4.08,1.2.2)
77+
OCAML_VERSION=4.02; OCAML_FULL_VERSION=4.08.0
78+
ppa=avsm/ocaml42+opam12 ;;
79+
4.09,1.2.2)
80+
OCAML_VERSION=4.02; OCAML_FULL_VERSION=4.09.0
81+
ppa=avsm/ocaml42+opam12 ;;
7682
*) echo "Unknown OCAML_VERSION=$OCAML_VERSION OPAM_VERSION=$OPAM_VERSION"
7783
echo "(An unset OCAML_VERSION used to default to \"latest\", but you must now specify it."
7884
echo "Try something like \"OCAML_VERSION=3.12\", \"OCAML_VERSION=4.07\", or see README-travis.md at https://github.com/ocaml/ocaml-ci-scripts )"
@@ -150,6 +156,8 @@ install_on_osx () {
150156
4.05,1.2.2) OCAML_FULL_VERSION=4.05.0; brew install opam ;;
151157
4.06,1.2.2) OCAML_FULL_VERSION=4.06.1; brew install opam ;;
152158
4.07,1.2.2) OCAML_FULL_VERSION=4.07.0; OPAM_SWITCH=${OPAM_SWITCH:-system}; brew install ocaml; brew install opam ;;
159+
4.08,1.2.2) OCAML_FULL_VERSION=4.08.0; OPAM_SWITCH=${OPAM_SWITCH:-system}; brew install ocaml; brew install opam ;;
160+
4.09,1.2.2) OCAML_FULL_VERSION=4.09.0; OPAM_SWITCH=${OPAM_SWITCH:-system}; brew install ocaml; brew install opam ;;
153161
*) echo "Unknown OCAML_VERSION=$OCAML_VERSION OPAM_VERSION=$OPAM_VERSION"
154162
exit 1 ;;
155163
esac

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ cache:
3737
- $HOME/save_opam
3838

3939
env:
40-
- OCAML_VERSION=4.04.1
41-
- OCAML_VERSION=4.05
42-
- OCAML_VERSION=4.06
4340
- OCAML_VERSION=4.07 WITH_BUILD_CACHE=true
41+
- OCAML_VERSION=4.08
42+
- OCAML_VERSION=4.09
4443

4544
stage: Compile
4645
script: bash -ex .travis_install.sh
@@ -58,4 +57,4 @@ jobs:
5857
- stage: Unit tests, checks and bil tests
5958
env:
6059
- OCAML_VERSION=4.07 WITH_BUILD_CACHE=true
61-
script: bash -ex .run_travis_tests.sh veri
60+
script: bash -ex .run_travis_tests.sh veri

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fi
5252
ocaml tools/cat.ml '"\n# $name\n"' -- $SECTIONS $AB _oasis
5353
ocaml tools/cat.ml '"\n# $name\n"' -- $TAGS _tags.in _tags
5454
ocaml tools/cat.ml '"\n#1 \"$name\"\n"' -- $PLUGINS myocamlbuild.ml.in myocamlbuild.ml
55-
ocaml tools/cat.ml '"\n#1 \"$name\"\n"' -- $SETUPS setup.ml.in setup.ml
55+
ocaml tools/cat.ml '"\n#1 \"$name\"\n"' -- setup.ml.pre.in $SETUPS setup.ml.in setup.ml
5656
oasis $QUIET setup
5757
ocamlfind ocamlopt unix.cmxa setup.ml -o setup.exe
5858
rm setup.cmx setup.cmi setup.o

lib/arm/arm_branch.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let lift operand ?link ?x:_ ?cond addr =
1818
let width = Word.bitwidth offset in
1919
let _1 = Word.one 32 in
2020
let min_32 = Word.Int_exn.(_1 lsl Word.of_int 31 ~width) in
21-
let offset = if offset = min_32 then Word.zero 32 else offset in
21+
let offset = if Word.equal offset min_32 then Word.zero 32 else offset in
2222
let r = Word.Int_exn.(addr + pc_offset + offset) in
2323
Bil.int r in
2424
(* TODO detect change to thumb in `x` *)

lib/arm/arm_mem.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Env = Arm_env
88

99
(** Memory access operations *)
1010

11+
let is_pc v = Var.equal v Env.pc
12+
1113

1214
(* Doug TODO check for misaligned access *)
1315
(* Single-register memory access *)
@@ -19,27 +21,27 @@ let lift_r ~(dst1 : Var.t) ?(dst2 : Var.t option) ~(base : Var.t)
1921
* Use the originals
2022
**)
2123
let address = match mode, operation, size, dst1 with
22-
| PostIndex, Ld, W, d when d = Env.pc -> Bil.var o_base
23-
| PreIndex, Ld, W, d when d = Env.pc -> Bil.(var o_base + offset)
24+
| PostIndex, Ld, W, d when is_pc d -> Bil.var o_base
25+
| PreIndex, Ld, W, d when is_pc d -> Bil.(var o_base + offset)
2426
| PostIndex, _, _, _ -> Bil.var base
2527
| PreIndex, _, _, _ | Offset, _, _, _ -> Bil.(var base + offset) in
2628

2729
(* Create temps for original if this is a jump *)
2830
let pre_write_back = match mode, operation, size, dst1 with
29-
| PreIndex, Ld, W, d when d = Env.pc -> [
31+
| PreIndex, Ld, W, d when is_pc d -> [
3032
Bil.move o_base Bil.(var base);
3133
Bil.move base Bil.(var base + offset)
3234
]
33-
| PostIndex, Ld, W, d when d = Env.pc -> [
35+
| PostIndex, Ld, W, d when is_pc d -> [
3436
Bil.move o_base Bil.(var base);
3537
Bil.move base Bil.(var base + offset)
3638
]
3739
| Offset, _, _, _ -> []
3840
| _ -> [] in
3941

4042
let write_back = match mode, operation, size, dst1 with
41-
| PreIndex, Ld, W, d when d = Env.pc -> []
42-
| PostIndex, Ld, W, d when d = Env.pc -> []
43+
| PreIndex, Ld, W, d when is_pc d -> []
44+
| PostIndex, Ld, W, d when is_pc d -> []
4345
| Offset, _, _, _ -> []
4446
| _ -> [Bil.move base Bil.(var base + offset)] in
4547

@@ -66,7 +68,7 @@ let lift_r ~(dst1 : Var.t) ?(dst2 : Var.t option) ~(base : Var.t)
6668
| W | D -> [] in
6769
let loads =
6870
let mem = Bil.var (Env.mem) in
69-
if size = D then [
71+
if [%compare.equal: size] size D then [
7072
Bil.move dst1 (load mem address);
7173
Bil.move (uw dst2) (load mem Bil.(address + four));
7274
] else [
@@ -82,7 +84,7 @@ let lift_r ~(dst1 : Var.t) ?(dst2 : Var.t option) ~(base : Var.t)
8284
(* truncate the value if necessary *)
8385
let trunc = match size with
8486
| B | H ->
85-
let n = if size = B then 8 else 16 in
87+
let n = if [%compare.equal: size] size B then 8 else 16 in
8688
[Bil.move temp Bil.(cast low n (var dst1))]
8789
| W | D -> [] in
8890
let stores =

lib/arm/arm_mem_shift.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ let repair_imm (src : word) ~sign_mask ~imm_mask rtype : exp =
2222
let bit_set =
2323
Word.(Z.(word sign_mask land src) = word sign_mask) in
2424
let negate =
25-
(bit_set && rtype = `NEG) ||
26-
(not bit_set && rtype = `POS) in
25+
(bit_set && [%compare.equal: repair] rtype `NEG) ||
26+
(not bit_set && [%compare.equal: repair] rtype `POS) in
2727
let offset = Z.(src land word imm_mask) in
2828
Bil.int (if negate then Z.neg offset else offset)
2929

3030
let repair_reg reg imm ~sign_mask rtype =
3131
let bit_set =
3232
Word.(Z.(word sign_mask land imm) = word sign_mask) in
3333
let negate =
34-
(bit_set && rtype = `NEG) || (not bit_set && rtype = `POS)
34+
(bit_set && [%compare.equal: repair] rtype `NEG) ||
35+
(not bit_set && [%compare.equal: repair] rtype `POS)
3536
in
3637
let m_one = Word.(ones (bitwidth imm)) in
3738
if negate then Bil.(int m_one * reg) else reg

lib/arm/arm_shift.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ let mem_shift ~src shift typ =
9393
let shift_amt w = Word.Int_err.(!$w land wordm 0xFFF) >>| Bil.int in
9494
(* Converts the shift to a negative if the negative bit is set *)
9595
let to_neg w exp =
96-
if Word.Int_err.(wordm 0x1000 land !$w = wordm 0x1000) then
97-
Bil.(int (Word.ones width) * exp)
98-
else
99-
exp in
96+
match Word.Int_err.(wordm 0x1000 land !$w) with
97+
| Ok x when Word.equal x (word 0x1000) ->
98+
Bil.(int (Word.ones width) * exp)
99+
| _ -> exp in
100100
let r = shift_typ shift >>= fun t -> shift_amt shift >>= fun amt ->
101101
return (t,amt) in
102102
match r with

lib/arm/arm_types.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ type mode_r = Offset | PreIndex | PostIndex
304304
type sign = Signed | Unsigned
305305
type operation = Ld | St
306306
type size = B | H | W | D
307+
[@@deriving compare]
307308

308309
(** Types for multiple-register memory access *)
309310
type mode_m = IA | IB | DA | DB
@@ -314,7 +315,7 @@ type arth = [`ADD | `ADC | `SBC | `RSC | `SUB | `RSB ]
314315
type move = [`AND | `BIC | `EOR | `MOV | `MVN | `ORR ]
315316
type data_oper = [ arth | move]
316317

317-
type repair = [`POS | `NEG]
318+
type repair = [`POS | `NEG] [@@deriving compare]
318319

319320
(** shift types *)
320321
type shift = [`ASR | `LSL | `LSR | `ROR | `RRX]

lib/arm/arm_utils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let tmp ?(name="v") typ =
3030

3131

3232
let assn d s =
33-
if d = Env.pc then Bil.jmp s else Bil.move d s
33+
if Var.equal d Env.pc then Bil.jmp s else Bil.move d s
3434

3535
let bitlen = function
3636
| Type.Imm len -> len

lib/bap/bap_project.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ open Format
1313
module Driver = Bap_disasm_driver
1414

1515
module Event = Bap_main_event
16+
module Buffer = Caml.Buffer
1617
include Bap_self.Create()
1718

1819
let find name = FileUtil.which name
@@ -451,7 +452,7 @@ module Pass = struct
451452
[@@deriving variants, sexp_of]
452453

453454
let find name : pass option =
454-
DList.find passes ~f:(fun p -> p.name = name)
455+
DList.find passes ~f:(fun p -> String.equal p.name name)
455456

456457
exception Failed of error [@@deriving sexp]
457458

@@ -462,7 +463,7 @@ module Pass = struct
462463
raise (Failed (Runtime_error (pass, Exn.Reraised (backtrace, exn))))
463464

464465
let is_evaled pass proj =
465-
List.exists proj.passes ~f:(fun name -> name = pass.name)
466+
List.exists proj.passes ~f:(fun name -> String.equal name pass.name)
466467

467468
let eval pass proj = {
468469
(pass.main proj) with

lib/bap/bap_self.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Format
66
open Cmdliner
77

88
module Event = Bap_main_event
9+
module Buffer = Caml.Buffer
910

1011
module Create() = struct
1112
let bundle = main_bundle ()
@@ -39,7 +40,7 @@ module Create() = struct
3940
let is_key = String.is_prefix ~prefix:"-" in
4041
Array.fold (Plugin.argv ()) ~init:([],`drop) ~f:(fun (args,act) arg ->
4142
let take arg = ("--" ^ arg) :: args in
42-
if arg = Sys.argv.(0) then (name::args,`drop)
43+
if String.equal arg Sys.argv.(0) then (name::args,`drop)
4344
else match String.chop_prefix arg ~prefix, act with
4445
| None,`take when is_key arg -> args,`drop
4546
| None,`take -> arg::args,`drop
@@ -49,7 +50,7 @@ module Create() = struct
4950
fst |> List.rev |> Array.of_list
5051

5152
let argv =
52-
if name = main then Sys.argv
53+
if String.equal name main then Sys.argv
5354
else filter_args name
5455

5556
let has_var v = match Sys.getenv ("BAP_" ^ String.uppercase v) with

lib/bap_bml/bap_bml.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module Cmp(T : Comparable) = struct
7171
end
7272

7373
let (-) pref tag = pref ^ "-" ^ Value.Tag.name tag
74-
let (+) pref suf = if suf = "" then pref else pref^"-"^suf
74+
let (+) pref suf = if String.is_empty suf then pref else pref^"-"^suf
7575

7676
let unit suf set is tag =
7777
Mappers.Nullary.register (set-tag+suf) (marker ident tag ());

lib/bap_bundle/bap_bundle.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
open Core_kernel
22

3+
module Filename = Caml.Filename
4+
35
module Std = struct
46
exception Not_a_bundle
57

@@ -165,7 +167,7 @@ module Std = struct
165167
b >>> fun zip ->
166168
Zip.entries zip |> List.filter_map ~f:(fun e ->
167169
let name = Zip.(e.filename) in
168-
Option.some_if (not (name = Nameof.manifest)) name)
170+
Option.some_if (not (String.equal name Nameof.manifest)) name)
169171

170172
let transform files bundle ~f =
171173
let zin = open_in bundle.path in
@@ -223,7 +225,7 @@ module Std = struct
223225

224226
let update_manifest bundle ~f =
225227
update bundle ~f:(fun file ->
226-
if file = Nameof.manifest
228+
if String.equal file Nameof.manifest
227229
then `Map (fun s -> Manifest.(of_string s |> f |> to_string))
228230
else `Copy)
229231

lib/bap_byteweight/bap_byteweight.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ module Make
4545
let rec outer = function
4646
| 0 -> ()
4747
| n -> inner n 0
48-
and inner length m = match Corpus.look set ~length m with
49-
| None -> outer (length - 1)
50-
| Some s when pass = `Pos && test s ->
48+
and inner length m = match Corpus.look set ~length m,pass with
49+
| None,_ -> outer (length - 1)
50+
| Some s, `Pos when test s ->
5151
Trie.change trie s (function
5252
| None -> Some (1,0)
5353
| Some (a,b) -> Some (a+1,b));
5454
inner length (m+1)
55-
| Some s when pass = `Neg ->
55+
| Some s, `Neg ->
5656
Trie.change trie s (function
5757
| Some (m,n) when not(test s) -> Some (m,n+1)
5858
| x -> x);
@@ -69,7 +69,7 @@ module Make
6969
| None -> false
7070
| Some (_,(a,b)) ->
7171
let n = a + b in
72-
Float.(of_int a / of_int n) > threshold
72+
Float.(of_int a / of_int n > threshold)
7373

7474
let next_if (trie : t) ~length ~f set n =
7575
let open Option.Monad_infix in
@@ -87,7 +87,7 @@ module Make
8787
let next trie ~length ~threshold set n =
8888
next_if trie ~length set n ~f:(fun _ _ (a,b) ->
8989
let n = a + b in
90-
Float.(of_int a / of_int n) > threshold)
90+
Float.(of_int a / of_int n > threshold))
9191

9292
let length = Trie.length
9393
end

lib/bap_byteweight/bap_byteweight_signatures.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let save_exn ?comp ~mode ~path arch data =
6464
let dst = entry ?comp ~mode arch in
6565
List.iter old ~f:(fun (entry,data) ->
6666
let file = Zip.(entry.filename) in
67-
if file <> dst then Zip.add_entry data zip file);
67+
if String.(file <> dst) then Zip.add_entry data zip file);
6868
Zip.add_entry data zip dst;
6969
Zip.close_out zip
7070
with Sys_error msg -> fail (`Sys_error msg)

lib/bap_c/bap_c_abi.ml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let create_arg i addr_size intent name t (data,exp) sub =
8686
let typ = match data with
8787
| Bap_c_data.Imm (sz,_) -> Type.Imm (Size.in_bits sz)
8888
| _ -> Type.Imm (Size.in_bits addr_size) in
89-
let name = if name = "" then sprintf "arg%d" (i+1) else name in
89+
let name = if String.is_empty name then sprintf "arg%d" (i+1) else name in
9090
let var = Var.create (Sub.name sub ^ "_" ^ name) typ in
9191
let arg = Arg.create ~intent var exp in
9292
let arg = Term.set_attr arg Attrs.data data in
@@ -96,22 +96,24 @@ let create_arg i addr_size intent name t (data,exp) sub =
9696

9797

9898
let find_by_name prog name =
99-
Term.enum sub_t prog |> Seq.find ~f:(fun sub -> Sub.name sub = name)
99+
Term.enum sub_t prog |> Seq.find ~f:(fun sub -> String.equal (Sub.name sub) name)
100100

101101
let find_first_caller prog tid =
102102
Term.enum sub_t prog |> Seq.find ~f:(fun sub ->
103103
Term.enum blk_t sub |> Seq.exists ~f:(fun blk ->
104104
Term.enum jmp_t blk |> Seq.exists ~f:(fun jmp ->
105105
match Jmp.kind jmp with
106-
| Call c -> Call.target c = Direct tid
106+
| Call c -> Label.equal (Call.target c) (Direct tid)
107107
| _ -> false)))
108108

109109
let proj_int = function Bil.Int x -> Some x | _ -> None
110110

111-
let has_libc_runtime prog =
112-
find_by_name prog "__libc_csu_fini" <> None &&
113-
find_by_name prog "__libc_csu_init" <> None
111+
let is_sub_exists prog name = Option.is_some @@ find_by_name prog name
112+
let is_sub_absent prog name = not (is_sub_exists prog name)
114113

114+
let has_libc_runtime prog =
115+
is_sub_exists prog "__libc_csu_fini" &&
116+
is_sub_exists prog "__libc_csu_init"
115117

116118
let find_entry_point prog =
117119
Term.enum sub_t prog |>
@@ -156,7 +158,7 @@ let rename_main abi prog = match detect_main_address prog with
156158
| _ -> sub)
157159

158160
let rename_libc_start_main abi prog =
159-
if find_by_name prog "__libc_start_main" = None
161+
if is_sub_absent prog "__libc_start_main"
160162
then match find_libc_start_main prog with
161163
| None -> prog
162164
| Some tid ->
@@ -174,8 +176,8 @@ let stage2 stage1 = object
174176
method! run prog =
175177
let prog = stage1#run prog in
176178
if has_libc_runtime prog &&
177-
(find_by_name prog "main" = None ||
178-
(find_by_name prog "__libc_start_main" = None))
179+
(is_sub_absent prog "main" ||
180+
(is_sub_absent prog "__libc_start_main"))
179181
then fix_libc_runtime stage1 prog
180182
else prog
181183
end

lib/bap_c/bap_c_attr.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let apply attr sub =
1919
module Gnu = struct
2020
let register_attr n f =
2121
let pass {Attr.name; args} sub =
22-
if n = name then f args sub else sub in
22+
if String.equal n name then f args sub else sub in
2323
register pass
2424

2525
exception Attr_type of string * string

lib/bap_c/bap_c_size.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class base (m : model) = object(self)
6969
| `Structure {Spec.t={Compound.fields}}
7070
| `Union {Spec.t={Compound.fields}} ->
7171
List.fold fields ~init:byte ~f:(fun align (_,t) ->
72-
max align (self#alignment t))
72+
Size.max align (self#alignment t))
7373
| `Function _ -> (self#pointer :> size)
7474
| #scalar as t -> self#scalar t
7575

0 commit comments

Comments
 (0)