Skip to content

Commit b2e77cd

Browse files
committed
gn build: Build libclang.so and libLTO.so on ELF platforms.
This requires changing the ELF build to enable -fPIC, consistent with other platforms. Differential Revision: https://reviews.llvm.org/D108223
1 parent 3d91d5b commit b2e77cd

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

llvm/utils/gn/build/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ config("llvm_code") {
377377
"//llvm/include",
378378
"$root_gen_dir/llvm/include",
379379
]
380+
if (current_os != "win") {
381+
cflags = [ "-fPIC" ]
382+
}
380383
}
381384

382385
config("lld_code") {

llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,24 @@ import("//llvm/version.gni")
55
# This build file is just enough to get check-clang to pass, it's missing
66
# several things from the CMake build:
77
# - a build target copying the Python bindings
8-
# - the GN linux build always builds without -fPIC (as if LLVM_ENABLE_PIC=OFF
9-
# in the CMake build), so libclang is always a static library on linux
108
# - the GN build doesn't have LIBCLANG_BUILD_STATIC
119

12-
libclang_target_type = "shared_library"
13-
if (host_os != "win" && host_os != "mac") {
14-
# ELF targets need -fPIC to build shared libs but they aren't on by default.
15-
# For now, make libclang a static lib there.
16-
libclang_target_type = "static_library"
17-
} else {
18-
action("linker_script_to_exports") {
19-
script = "linker-script-to-export-list.py"
20-
inputs = [ "libclang.map" ]
21-
outputs = [ "$target_gen_dir/libclang.exports" ]
22-
args = [
23-
rebase_path(inputs[0], root_build_dir),
24-
rebase_path(outputs[0], root_build_dir),
25-
]
26-
}
10+
action("linker_script_to_exports") {
11+
script = "linker-script-to-export-list.py"
12+
inputs = [ "libclang.map" ]
13+
outputs = [ "$target_gen_dir/libclang.exports" ]
14+
args = [
15+
rebase_path(inputs[0], root_build_dir),
16+
rebase_path(outputs[0], root_build_dir),
17+
]
18+
}
2719

28-
symbol_exports("exports") {
29-
deps = [ ":linker_script_to_exports" ]
30-
exports_file = "$target_gen_dir/libclang.exports"
31-
}
20+
symbol_exports("exports") {
21+
deps = [ ":linker_script_to_exports" ]
22+
exports_file = "$target_gen_dir/libclang.exports"
3223
}
3324

34-
target(libclang_target_type, "libclang") {
25+
shared_library("libclang") {
3526
configs += [ "//llvm/utils/gn/build:clang_code" ]
3627
deps = [
3728
"//clang/include/clang/Config",
@@ -48,14 +39,17 @@ target(libclang_target_type, "libclang") {
4839
"//llvm/lib/Support",
4940
"//llvm/lib/Target:TargetsToBuild",
5041
]
42+
if (current_os == "win" || current_os == "mac") {
43+
deps += [ ":exports" ]
44+
} else {
45+
inputs = [ "libclang.map" ]
46+
ldflags =
47+
[ "-Wl,--version-script," + rebase_path(inputs[0], root_build_dir) ]
48+
}
5149
if (clang_enable_arcmt) {
5250
deps += [ "//clang/lib/ARCMigrate" ]
5351
}
5452

55-
if (libclang_target_type == "shared_library") {
56-
deps += [ ":exports" ]
57-
}
58-
5953
defines = []
6054

6155
if (host_os == "win") {

llvm/utils/gn/secondary/llvm/tools/lto/BUILD.gn

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import("//llvm/utils/gn/build/symbol_exports.gni")
22
import("//llvm/version.gni")
33

4-
lto_target_type = "shared_library"
5-
if (host_os != "mac" && host_os != "win") {
6-
# ELF targets need -fPIC to build shared libs but they aren't on by default.
7-
# For now, make libclang a static lib there.
8-
lto_target_type = "static_library"
9-
}
10-
114
symbol_exports("exports") {
125
exports_file = "lto.exports"
136
}
147

15-
target(lto_target_type, "lto") {
8+
shared_library("lto") {
169
output_name = "LTO"
1710
deps = [
11+
":exports",
1812
"//llvm/lib/Bitcode/Reader",
1913
"//llvm/lib/IR",
2014
"//llvm/lib/LTO",
@@ -29,10 +23,6 @@ target(lto_target_type, "lto") {
2923
"lto.cpp",
3024
]
3125

32-
if (lto_target_type == "shared_library") {
33-
deps += [ ":exports" ]
34-
}
35-
3626
if (host_os == "mac") {
3727
ldflags = [
3828
"-Wl,-compatibility_version,1",

0 commit comments

Comments
 (0)