[llvm] [bazel] Rework liblldb (PR #91549)
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 18:29:07 PDT 2024
https://github.com/keith created https://github.com/llvm/llvm-project/pull/91549
Previously we were linking liblldb as a shared library, but also linking the contents into the lldb binary. This is invalid and results in subtle runtime issues because of duplicate constants, like the global plugin registry. This now links the dylib to lldb directly. This requires we switch to cc_binary instead because cc_shared_library expects your library to export all symbols in your transitive dependency tree, where we only want to export lldb symbols.
>From ba5d58318d2fbeb903358bac93c9f972831db430 Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Wed, 8 May 2024 18:28:06 -0700
Subject: [PATCH] [bazel] Rework liblldb
Previously we were linking liblldb as a shared library, but also linking
the contents into the lldb binary. This is invalid and results in subtle
runtime issues because of duplicate constants, like the global plugin
registry. This now links the dylib to lldb directly. This requires we
switch to cc_binary instead because cc_shared_library expects your
library to export all symbols in your transitive dependency tree,
where we only want to export lldb symbols.
---
.../llvm-project-overlay/lldb/BUILD.bazel | 62 ++++++++++++-------
1 file changed, 41 insertions(+), 21 deletions(-)
diff --git a/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel b/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
index 8fb90e850f000..3f3e49950e35d 100644
--- a/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
@@ -728,37 +728,57 @@ cc_library(
],
)
-cc_library(
- name = "liblldb.static",
- deps = [
- ":API",
- ":Interpreter",
- ],
+genrule(
+ name = "gen_exports_file_linux",
+ srcs = ["//lldb:source/API/liblldb-private.exports"],
+ outs = ["exports_linux.txt"],
+ cmd = """
+cat > $(OUTS) <<EOF
+{
+ global:
+ $$(sed 's/$$/;/g' $(SRCS))
+};
+EOF
+""",
)
-cc_shared_library(
- name = "liblldb",
- # TODO: Remove once fixed https://github.com/bazelbuild/bazel/issues/21893
+genrule(
+ name = "gen_exports_file_macos",
+ srcs = ["//lldb:source/API/liblldb-private.exports"],
+ outs = ["exports_macos.txt"],
+ cmd = "sed 's/^/_/g' $(SRCS) > $(OUTS)",
+)
+
+cc_binary(
+ name = "lldb{}".format(PACKAGE_VERSION),
additional_linker_inputs = select({
+ "@platforms//os:linux": [
+ ":gen_exports_file_linux",
+ ],
"@platforms//os:macos": [
- ":HostMacOSXObjCXX",
- "//lldb/source/Plugins:PluginPlatformMacOSXObjCXX",
+ ":gen_exports_file_macos",
],
"//conditions:default": [],
}),
- shared_lib_name = select({
- "@platforms//os:macos": "liblldb{}.dylib".format(PACKAGE_VERSION),
- "@platforms//os:linux": "liblldb{}.so".format(PACKAGE_VERSION),
- }),
- # TODO: Remove once fixed https://github.com/bazelbuild/bazel/issues/21893
- user_link_flags = select({
+ linkopts = select({
+ "@platforms//os:linux": [
+ "-Wl,--export-dynamic-symbol-list=$(location :gen_exports_file_linux)",
+ ],
"@platforms//os:macos": [
- "$(location :HostMacOSXObjCXX)",
- "$(location //lldb/source/Plugins:PluginPlatformMacOSXObjCXX)",
+ "-Wl,-exported_symbols_list,$(location :gen_exports_file_macos)",
],
"//conditions:default": [],
}),
- deps = [":liblldb.static"],
+ linkshared = True,
+ deps = [
+ ":API",
+ ":Interpreter",
+ ],
+)
+
+cc_import(
+ name = "liblldb_wrapper",
+ shared_library = "lldb{}".format(PACKAGE_VERSION),
)
gentbl_cc_library(
@@ -794,7 +814,7 @@ cc_binary(
deps = [
":APIHeaders",
":Host",
- ":liblldb.static",
+ ":liblldb_wrapper",
":lldb_options_inc_gen",
"//llvm:Option",
"//llvm:Support",
More information about the llvm-commits
mailing list