Skip to content

Commit ccdf4f4

Browse files
authored
selects specific llvm components for linking (#1435)
Up until now, we were linking all available LLVM components that resulted in the bloated binary image and linking errors due to improperly packaged libraries on various distributions, e.g., missing Polly library, various problems with libterm, and so on, all these problems arose from components that we do not actually use. Moreover, the problem were never solved and issues remain open for decades. The new approach is to link only the selected components. Since the list of available components is quite extensive (around 200) and there is no documentation available about their dependencies and intention, it is quite hard to identify the subset that we really need. The current default set works fine on llvm-14 but we can refine it later, once we will discover any problems. The components could be manually selected via the `./configure` script with the `--with-llvm-components` option. For example `--with-llvm-components=all` will enable the old behavior.
1 parent a49b97c commit ccdf4f4

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

oasis/llvm.setup.ml.in

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
let default_llvm_components = [
2+
"all-targets";
3+
"binaryformat";
4+
"core";
5+
"mc";
6+
"debuginfodwarf";
7+
"debuginfomsf";
8+
"debuginfopdb";
9+
]
10+
11+
12+
let llvm_components () : unit =
13+
BaseEnv.var_define
14+
~hide:false
15+
~dump:true
16+
~cli:BaseEnv.CLIWith
17+
~short_desc:(fun () ->
18+
"the comma-separated list of required LLVM components")
19+
("llvm_components")
20+
(fun () -> String.concat "," default_llvm_components) |>
21+
definition_end
122

223
let strip_patch ver =
324
match String.index_opt ver '.' with
@@ -6,13 +27,15 @@ let strip_patch ver =
627

728
let extract config link_static v =
829
let link_mode = if link_static then "--link-static" else "" in
9-
OASISExec.run_read_one_line ~ctxt config [link_mode; "--"^v]
30+
let components = if v = "libs"
31+
then String.split_on_char ',' @@ BaseEnv.var_get "llvm_components"
32+
else [] in
33+
OASISExec.run_read_one_line ~ctxt config @@
34+
link_mode :: ("--"^v) :: components
1035

11-
let extract_ldflags config link_static = function
12-
| "3.4" -> extract config link_static "ldflags"
13-
| _ ->
14-
extract config link_static "ldflags" ^
15-
" " ^ extract config link_static "system-libs"
36+
let extract_ldflags config link_static =
37+
extract config link_static "ldflags" ^ " " ^
38+
extract config link_static "system-libs"
1639

1740
let llvm var () : unit =
1841
BaseEnv.var_define
@@ -22,12 +45,9 @@ let llvm var () : unit =
2245
("llvm_"^var)
2346
(fun () ->
2447
let config = BaseEnv.var_get "llvm_config" in
25-
let version = strip_patch @@ BaseEnv.var_get "llvm_version" in
26-
let link_static = match version with
27-
| "3.4" | "3.8" -> false
28-
| _ -> BaseEnv.var_get "llvm_static" = "true" in
48+
let link_static = BaseEnv.var_get "llvm_static" = "true" in
2949
if var = "ldflags"
30-
then extract_ldflags config link_static version
50+
then extract_ldflags config link_static
3151
else extract config link_static var) |>
3252
definition_end
3353

@@ -36,13 +56,13 @@ let llvm_version () : unit =
3656
~hide:false
3757
~dump:true
3858
~cli:BaseEnv.CLIWith
39-
~short_desc:(fun () -> "llvm version (e.g., 3.4)")
59+
~short_desc:(fun () -> "llvm version (e.g., 10)")
4060
"llvm_version"
4161
(fun () ->
4262
try
4363
ignore @@ OASISFileUtil.which ~ctxt "llvm-config";
4464
OASISExec.run_read_one_line ~ctxt "llvm-config" ["--version"]
45-
with Not_found -> "3.4") |>
65+
with Not_found -> "10") |>
4666
definition_end
4767

4868
let llvm_config () : unit =
@@ -92,6 +112,7 @@ let llvm_lib () : unit =
92112

93113
let () =
94114
define [
115+
llvm_components;
95116
llvm_version;
96117
llvm_config;
97118
llvm_mainlib;

0 commit comments

Comments
 (0)