[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
master
Timotej Kapus 5 years ago committed by Facebook Github Bot
parent 1415be9153
commit afb6a4fd11

@ -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

Loading…
Cancel
Save