Skip to content

Commit

Permalink
ELF: do not return imported symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
nojb committed May 26, 2020
1 parent f7b64c9 commit 84bd38d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions utils/binutils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,15 @@ module ELF = struct
Array.init (dynsym.sh_size / dynsym.sh_entsize) mk
end

let find_symbol symbols symname =
let f = function
| {st_shndx = 0; _} -> false
| {st_name; _} -> st_name = symname
in
array_find f symbols

let symbol_offset sections symbols symname =
match array_find (fun {st_name; _} -> st_name = symname) symbols with
match find_symbol symbols symname with
| None ->
None
| Some {st_shndx; st_value; _} ->
Expand All @@ -294,7 +301,7 @@ module ELF = struct
(sub st_value sections.(st_shndx).sh_addr))

let defines_symbol symbols symname =
Array.exists (fun {st_name; _} -> st_name = symname) symbols
Option.is_some (find_symbol symbols symname)

let read ic =
seek_in ic 0;
Expand Down Expand Up @@ -677,3 +684,10 @@ let defines_symbol {defines_symbol; _} symname =

let symbol_offset {symbol_offset; _} symname =
symbol_offset symname

let () =
match Sys.argv with
| [|_; filename; symbol|] ->
Printf.printf "%B\n%!" (defines_symbol (Result.get_ok (read filename)) symbol)
| _ ->
()

0 comments on commit 84bd38d

Please sign in to comment.