From afb6a4fd1183fbcc087c154acb22b7b2ce875827 Mon Sep 17 00:00:00 2001 From: Timotej Kapus Date: Thu, 25 Jul 2019 07:34:50 -0700 Subject: [PATCH] [sledge] Fix internalization Summary: Currently bitcode produced with `sledge buck link` can have missing symbols that are clearly defined in the source. For example consider a symbol `awesome_function` that is defined in the libraries linked in but not in the produced binary (despite being reachable from main). `llvm-nm` of the bitcode produced by `llvm-link` might look like: ``` U awesome_function t awesome_function.1892 ``` Some our `awesome_function` is undefined and its definition is called `awsome_function.1892` for some reason and is local. I think this is because symbol get internalized too early and then they get renamed and somehow lost. Not sure why `llvm-link` behaves this way sometimes. This patch removes internalization from `llvm-link` and puts it into `opt`, where it doesn't cause problems. Reviewed By: jvillard Differential Revision: D16494153 fbshipit-source-id: aad9053a4 --- sledge/src/sledge_buck.ml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/sledge/src/sledge_buck.ml b/sledge/src/sledge_buck.ml index f7780ec58..e1bcdb0b8 100644 --- a/sledge/src/sledge_buck.ml +++ b/sledge/src/sledge_buck.ml @@ -149,17 +149,15 @@ let llvm_link_opt ~fuzzer ~bitcode_output modules = ( ( if fuzzer then echo ~n:() (Option.value_exn (Model.read "/lib_fuzzer_main.bc")) else return () ) - |- run - (Lazy.force llvm_bin ^ "llvm-link") - ( "-internalize" - :: ( "-internalize-public-api-list=" - ^ String.concat ~sep:"," (Config.find_list "entry-points") ) - :: "-o=-" :: modules ) + |- run (Lazy.force llvm_bin ^ "llvm-link") ("-o=-" :: modules) |- run (Lazy.force llvm_bin ^ "opt") - [ "-o=" ^ bitcode_output; "-globaldce"; "-globalopt"; "-mergefunc" - ; "-constmerge"; "-argpromotion"; "-ipsccp"; "-mem2reg"; "-dce" - ; "-globaldce"; "-deadargelim"; "-global-merge-on-const" + [ "-o=" ^ bitcode_output; "-internalize" + ; "-internalize-public-api-list=" + ^ String.concat ~sep:"," (Config.find_list "entry-points") + ; "-globaldce"; "-globalopt"; "-mergefunc"; "-constmerge" + ; "-argpromotion"; "-ipsccp"; "-mem2reg"; "-dce"; "-globaldce" + ; "-deadargelim"; "-global-merge-on-const" ; "-global-merge-ignore-single-use=false" ; "-global-merge-group-by-use=false" (* global-merge-max-offset is set to 0 by default. If a global