Skip to content

Commit

Permalink
renovates the LLVM backend
Browse files Browse the repository at this point in the history
Droping support of old LLVM and legacy backends
-----------------------------------------------

We drop a lot of old code (minus 3k lines of code) thus removing the support
burden and making it easier to maintain, fix, and upgrade the code.

Fixes #1166

Simplifies the implementation
-----------------------------

The remaining code base is significanly simplified. We dropped the
separation between relocatable and non-relocatable files, removed any
transformations of addresses from the LLVM backend (we now emit
absolute virtual addresses). The whole logic of transforming from the
llvm view to the bap image view now fits into a hundred lines of
code (instead of hundreds lines spread across 16 files as it was
before).

Fixes #1183
Fixes #1189

Produces more information
-------------------------------

The relocation information is now emitted for all files (not only for
relocatable). Also, removes tons of checks that were preventing our
backends from emitting valuable symbolic information.

Paves the road to #1135 and #1161
  • Loading branch information
ivg committed Aug 5, 2020
1 parent 853a392 commit 7110388
Show file tree
Hide file tree
Showing 47 changed files with 719 additions and 3,051 deletions.
33 changes: 29 additions & 4 deletions lib/bap/bap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5538,6 +5538,7 @@ module Std : sig
type addr = int64
type size = int64
type off = int64
type value = int64

(** a contiguous piece of memory. *)
type 'a region = {
Expand Down Expand Up @@ -5566,41 +5567,56 @@ module Std : sig
(** [subarch name] the subarchitecture, when applicable,
e.g., v7, v8, r2, etc. Should be appended to the arch
name to get the full description, e.g., armv7.
@since 2.2.0
*)
val subarch : (string, (string -> 'a) -> 'a) Ogre.attribute


(** [vendor name] the second part of the build triplet,
e.g., apple, pc, ibm, unknown. Could be just an empty string.
e.g., apple, pc, ibm, unknown. Could be just an empty
string.
@since 2.2.0
*)
val vendor : (string, (string -> 'a) -> 'a) Ogre.attribute


(** [system name] the operating system name, for which the
binary is specifically built, e.g., ananas, ios, linux.
@since 2.2.0
*)
val system : (string, (string -> 'a) -> 'a) Ogre.attribute


(** [abi name] the environment/toolchain/abi under which the
binary is expected to be run, e.g., gnu, android, msvc
@since 2.2.0
*)
val abi : (string, (string -> 'a) -> 'a) Ogre.attribute


(** [bits m] is the bitness of the target architecture, e.g.,
16, 32, 64.
@since 2.2.0
*)
val bits : (size, (size -> 'a) -> 'a) Ogre.attribute


(** [is_little_endian yes-or-no] is [true] if the target is
little endian. *)
little endian.
@since 2.2.0 *)
val is_little_endian : (bool, (bool -> 'a) -> 'a) Ogre.attribute


(** [bias offset] the value by which all addresses are biased
wrt to the real addresses in the binary. *)
wrt to the real addresses in the binary.
@since 2.2.0 *)
val bias : (off, (off -> 'a) -> 'a) Ogre.attribute

(** [segment addr size readable writable executable] a memory
Expand All @@ -5614,7 +5630,7 @@ module Std : sig
(** [code_start addr] an address starts a code sequence *)
val code_start : (addr, (addr -> 'a) -> 'a) Ogre.attribute

(** [entry_point addr] an address is a program entry point *)
(** [entry_point addr] an address is the program entry point *)
val entry_point : (addr, (addr -> 'a) -> 'a) Ogre.attribute

(** [symbol_chunk addr size root] a contiguous piece of a program
Expand Down Expand Up @@ -5652,8 +5668,17 @@ module Std : sig
i.e., an address of a first byte of the image. *)
val base_address : (addr, (addr -> 'a) -> 'a) Ogre.attribute


(** [code_region addr size off] the memory region in the file
with the given offset [off] and [size] is code that should be loaded
at the specified virtual address [addr]. *)
val code_region :
(addr * size * off, (addr -> size -> off -> 'a) -> 'a) Ogre.attribute

(** [symbol_value addr value] the symbol at address the
specified [value]. *)
val symbol_value :
(addr * value, (addr -> value -> 'a) -> 'a) Ogre.attribute
end
end

Expand Down
5 changes: 5 additions & 0 deletions lib/bap_image/bap_image.ml
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,15 @@ module Scheme = struct
type addr = int64
type size = int64
type off = int64
type value = int64
type 'a region = {addr : int64; size: int64; info : 'a}
let region addr size info = {addr; size; info}
let void_region addr size = {addr; size; info = ()}

let off = "off" %: int
let size = "size" %: int
let addr = "addr" %: int
let value = "value" %: int
let name = "name" %: str
let root = "root" %: int
let readable = "r" %: bool
Expand Down Expand Up @@ -378,6 +380,9 @@ module Scheme = struct
let external_reference () =
declare "external-reference" (scheme addr $ name) Tuple.T2.create
let base_address () = declare "base-address" (scheme addr) ident

let symbol_value () =
declare "symbol-value" (scheme addr $ value) Tuple.T2.create
end


Expand Down
3 changes: 3 additions & 0 deletions lib/bap_image/bap_image.mli
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module Scheme : sig
type addr = int64
type size = int64
type off = int64
type value = int64

type 'a region = {addr : addr; size : int64; info : 'a}

Expand Down Expand Up @@ -130,4 +131,6 @@ module Scheme : sig
val code_region :
(addr * size * off, (addr -> size -> off -> 'a) -> 'a) Ogre.attribute

val symbol_value :
(addr * value, (addr -> value -> 'a) -> 'a) Ogre.attribute
end
3 changes: 2 additions & 1 deletion lib/bap_llvm/bap_llvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module Std = struct

let llvm_version = strip_version Bap_llvm_config.version
let init_disassembler = Bap_llvm_disasm.init
let init_loader = Bap_llvm_ogre_loader.init
let init_loader ?base ?pdb_path () =
ok_exn @@ Bap_llvm_loader.init ?base ?pdb_path ()
end
68 changes: 0 additions & 68 deletions lib/bap_llvm/bap_llvm_binary.ml

This file was deleted.

14 changes: 0 additions & 14 deletions lib/bap_llvm/bap_llvm_coff_scheme.ml

This file was deleted.

27 changes: 0 additions & 27 deletions lib/bap_llvm/bap_llvm_elf_scheme.ml

This file was deleted.

Loading

0 comments on commit 7110388

Please sign in to comment.