Skip to content

Commit

Permalink
Merge pull request #3 from fdopen/datasymbols
Browse files Browse the repository at this point in the history
recognize data symbols inside import libraries
  • Loading branch information
dra27 committed Apr 21, 2020
2 parents f083066 + 2ed47c2 commit 742a6eb
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions reloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,16 @@ let build_dll link_exe output_file files exts extra_args =
let objs = collect (function (f, `Obj x) -> Some (f,x) | _ -> None) files in
let libs = collect (function (f, `Lib (x,_)) -> Some (f,x) | _ -> None) files in

let with_data_symbol symbols sym_name f =
if !toolchain <> `MSVC && !toolchain <> `MSVC64 then
match check_prefix "__nm_" sym_name with
| None -> ()
| Some s ->
let imp_name = "__imp_" ^ s in
if List.exists ( fun p -> Symbol.is_defin p &&
p.sym_name = imp_name) symbols then
f s;
in
(* Collect all the available symbols, including those defined
in default libraries *)
let defined, from_imports, unalias =
Expand Down Expand Up @@ -717,7 +727,11 @@ let build_dll link_exe output_file files exts extra_args =

(* Collect defined symbols *)
List.iter
(fun sym -> if Symbol.is_defin sym then add_def sym.sym_name)
(fun sym ->
if Symbol.is_defin sym then (
add_def sym.sym_name;
with_data_symbol obj.symbols sym.sym_name add_def)
)
obj.symbols

and collect_file fn =
Expand Down Expand Up @@ -769,10 +783,13 @@ let build_dll link_exe output_file files exts extra_args =
(fun sym ->
if Symbol.is_defin sym
then begin
if !explain then
Printf.printf "Symbol %s found in %s(%s)\n%!" sym.sym_name fn
objname;
Hashtbl.replace defined_in sym.sym_name (fn, objname, obj);
let f s =
if !explain then
Printf.printf "Symbol %s found in %s(%s)\n%!" s fn objname;
Hashtbl.replace defined_in s (fn,objname,obj);
in
f sym.sym_name;
with_data_symbol obj.symbols sym.sym_name f
end
)
obj.symbols
Expand Down

0 comments on commit 742a6eb

Please sign in to comment.