Skip to content

Commit 1484777

Browse files
bmourad01bmourad01
andauthored
Adds the libraries parameter to the disassemble command (#1547)
* First draft of the BIR linker * Try running autorun passes on the project * Fix typo * Remove newline * Just give the name up front * Allow user to specify which units to link with * Update manpage * Convert the `Bap_sema` passes to KB-friendly versions * Multiple changes - Reject ARM `__svc` stubs - Don't link to stubs in the target unit - Use the KB-friendly `Program.lift` * Avoid extra seq allocation * Adds SSA to KB, as well as `Term.KB.{map,filter,filter_map}` * Remove link * Link plugin * Small cleanup * Provide aliases when we have ambiguous names/addresses * Multiple improvements - Use aliases if there is no matching subroutine - Link in the minimal slice of the callgraph by default - Remove the stub subroutines after linking * Link with graphlib and regular * Fixes style * Resolve stubs in all units as well If we have more than one unit to link with, then one unit may have stubs that can be resolved to the implementation in another * Undo local change * Tidy up the subroutine collection * Reworks the linking to `Bap_project` * Revert breaking the interface to `Project.Input.file` * Revert change * Adds the `library` type + prevents duplicate libraries * Update docs * Use stable dedup * Refine glibc internal aliases * Rename parameter to `--libraries` * Fix formatting + KB rule for aliases * Fix stub detection + allow many to one mapping for stubs * More efficient dedup * Neaten * Fix the actual pass that updates the jumps * Fill in the missing requirements for `glibc-internal-aliases` * Collect the set of linked tids before running the linker * Mangle the subroutines that implement the resolved stubs * Adds the `--link-only` parameter to `stub-resolver` In some instances we may be interested in linking only a subset of the stubs to their implementations. This is mainly motivated by the fact that, when the stub resolver does link the implementations, and we later want to run the program with Primus, then the Primus Lisp stubs will no longer be called for these stubs that were resolved, even though we may still want to use them. * Extends aliases rule to include possible names * Promise to compute aliases in objdump plugin * Add `no-link` parameter to the stub resolver We can explicitly ask it to not link certain stubs to implementations * Fix `should_link` Co-authored-by: bmourad01 <[email protected]>
1 parent 3db2748 commit 1484777

File tree

13 files changed

+599
-251
lines changed

13 files changed

+599
-251
lines changed

lib/bap/bap.mli

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5890,7 +5890,7 @@ module Std : sig
58905890
val require : (string, (string -> 'a) -> 'a) Ogre.attribute
58915891

58925892

5893-
(** (is-little-endian FLAG)] is set for files with words encoded in the
5893+
(** [(is-little-endian FLAG)] is set for files with words encoded in the
58945894
little-endian order.
58955895
58965896
@since 2.2.0 *)
@@ -10341,12 +10341,12 @@ module Std : sig
1034110341
type t = project
1034210342
type state [@@deriving bin_io]
1034310343
type input
10344+
type library
1034410345

1034510346
(** IO interface to a project data structure. *)
1034610347
include Data.S with type t := t
1034710348

10348-
(** [from_file filename] creates a project from the provided input
10349-
source.
10349+
(** [create input] creates a project from the provided input source.
1035010350
1035110351
The input code regions are speculatively disassembled and the
1035210352
set of basic blocks is determined, using the algorithm
@@ -10444,8 +10444,13 @@ module Std : sig
1044410444
@since 2.0.0 the parameter [symbolizer] is unused
1044510445
@since 2.0.0 the parameter [rooter] is unused
1044610446
@since 2.0.0 the parameter [reconstructor] is unused
10447-
@since 2.2.0 the package parameter is added
10447+
@since 2.2.0 the parameter [package] is added
1044810448
10449+
@since 2.6.0 if [input] consists of library files in addition
10450+
to the main binary, then the accessors to the state of the
10451+
project reflect that of the main binary, except for [program],
10452+
which contains the code of both the main program and the library
10453+
programs linked together.
1044910454
*)
1045010455
val create :
1045110456
?package:string ->
@@ -10467,14 +10472,12 @@ module Std : sig
1046710472
*)
1046810473
val arch : t -> arch
1046910474

10470-
1047110475
(** [target project] returns the target system of the project.
1047210476
1047310477
@since 2.2.0
1047410478
*)
1047510479
val target : t -> Theory.Target.t
1047610480

10477-
1047810481
(** [specification p] returns the specification of the binary.
1047910482
1048010483
@since 2.2.0 *)
@@ -10484,7 +10487,6 @@ module Std : sig
1048410487
1048510488
@since 2.0.0 *)
1048610489
val state : t -> state
10487-
1048810490
(** [disasm project] returns results of disassembling *)
1048910491
val disasm : t -> disasm
1049010492

@@ -10498,10 +10500,7 @@ module Std : sig
1049810500
(** [map_program t ~f] maps the IR representation of the program
1049910501
with function [f].
1050010502
10501-
Note: since the program is computed lazily this function
10502-
should be preferred to [program] composed [with_program] for
10503-
passes that transform the program representation so that they
10504-
are not run if the program is never ever used.
10503+
@since 2.6.0 the program is no longer lazily computed.
1050510504
*)
1050610505
val map_program : t -> f:(program term -> program term) -> t
1050710506

@@ -10593,6 +10592,58 @@ module Std : sig
1059310592
(** [del project attr] removes an attribute from a project *)
1059410593
val del : t -> 'a tag -> t
1059510594

10595+
(** [libraries project] returns the shared libraries that were loaded
10596+
with [project]. *)
10597+
val libraries : t -> library list
10598+
10599+
(** A library that was loaded alongside the main program.
10600+
10601+
@since 2.6.0
10602+
*)
10603+
module Library : sig
10604+
type t = library
10605+
10606+
(** [unit library] returns the unit associated with the library. *)
10607+
val unit : library -> Theory.Unit.t
10608+
10609+
(** [arch library] reveals the architecture of the library.
10610+
10611+
@since 2.6.0
10612+
@deprecated use [target library] instead.
10613+
*)
10614+
val arch : library -> arch
10615+
10616+
(** [target library] returns the target system of the library.
10617+
10618+
@since 2.6.0
10619+
*)
10620+
val target : library -> Theory.Target.t
10621+
10622+
(** [specification library] returns the specification of the library.
10623+
10624+
@since 2.6.0
10625+
*)
10626+
val specification : library -> Ogre.doc
10627+
10628+
(** [state library] returns the core state of the library.
10629+
10630+
@since 2.6.0
10631+
*)
10632+
val state : library -> state
10633+
10634+
(** [disasm library] returns the results of disassembling the library.
10635+
10636+
@since 2.6.0
10637+
*)
10638+
val disasm : library -> disasm
10639+
10640+
(** [memory library] returns the memory of the library.
10641+
10642+
@since 2.6.0
10643+
*)
10644+
val memory : library -> value memmap
10645+
end
10646+
1059610647
(** Information obtained during project reconstruction.
1059710648
1059810649
These pieces of information are guaranteed to be discovered
@@ -10685,8 +10736,16 @@ module Std : sig
1068510736
contradicts the information in the file then the project
1068610737
creation will fail.
1068710738
10739+
@since 2.6.0 a list of files [libraries] can be provided,
10740+
which are libraries that will be linked with the main program.
10741+
It is presumed that they are specified in topological order.
10742+
1068810743
@since 2.2.0 *)
10689-
val load : ?target:Theory.Target.t -> ?loader:string -> string -> t
10744+
val load :
10745+
?target:Theory.Target.t ->
10746+
?loader:string ->
10747+
?libraries:string list ->
10748+
string -> t
1069010749

1069110750
(** [raw_file ?base target ~filename] creates an input from a binary
1069210751
file that is raw code for the given [target], i.e.,
@@ -10769,7 +10828,6 @@ module Std : sig
1076910828
be looked up in the {!Image.available_backends}.
1077010829
1077110830
@deprecated use [Input.load filename]
10772-
1077310831
*)
1077410832
val file : ?loader:string -> filename:string -> t
1077510833

@@ -10784,7 +10842,7 @@ module Std : sig
1078410842
*)
1078510843
val create :
1078610844
?finish:(project -> project) ->
10787-
arch -> string -> code:value memmap -> data: value memmap -> t
10845+
arch -> string -> code:value memmap -> data:value memmap -> t
1078810846
end
1078910847

1079010848
(** {3 Registering passes}

0 commit comments

Comments
 (0)