Skip to content

Commit

Permalink
configuration: added option to disable linking against libunwind
Browse files Browse the repository at this point in the history
Added a `bool_flag` that allows the user to disable linking against the
`libunwind` binary.

To disable linking against libunwind use the following command line
parameter:

```
--@toolchains_llvm//toolchain/config:libunwind=False

```

Signed-off-by: Michał Maślanka <[email protected]>
  • Loading branch information
mmaslankaprv authored and fmeum committed Aug 23, 2024
1 parent 192cf04 commit a3b0dbb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
13 changes: 9 additions & 4 deletions toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def cc_toolchain_config(
# Similar to link_flags, but placed later in the command line such that
# unused symbols are not stripped.
link_libs = []
libunwind_link_flags = []

# Flags for ar.
archive_flags = []
Expand Down Expand Up @@ -205,13 +206,15 @@ def cc_toolchain_config(
link_flags.extend([
"-l:libc++.a",
"-l:libc++abi.a",
])
libunwind_link_flags = [
"-l:libunwind.a",
# Compiler runtime features.
"-rtlib=compiler-rt",
# To support libunwind.
"-lpthread",
"-ldl",
])
]
else:
# Several system libraries on macOS dynamically link libc++ and
# libc++abi, so static linking them becomes a problem. We need to
Expand All @@ -223,11 +226,13 @@ def cc_toolchain_config(
"-L{}/usr/lib".format(sysroot_path),
"-lc++",
"-lc++abi",
"-Bstatic",
"-lunwind",
"-Bdynamic",
"-L{}lib".format(toolchain_path_prefix),
])
libunwind_link_flags = [
"-Bstatic",
"-lunwind",
]

elif stdlib == "libc++":
cxx_flags = [
Expand Down Expand Up @@ -340,7 +345,7 @@ def cc_toolchain_config(
dbg_compile_flags = dbg_compile_flags,
opt_compile_flags = opt_compile_flags,
cxx_flags = cxx_flags,
link_flags = link_flags,
link_flags = link_flags + select({"//conditions:default": [], str(Label("@toolchains_llvm//toolchain/config:use_libunwind")): libunwind_link_flags}),
archive_flags = archive_flags,
link_libs = link_libs,
opt_link_flags = opt_link_flags,
Expand Down
27 changes: 27 additions & 0 deletions toolchain/config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2021 The Bazel Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

bool_flag(
name = "libunwind",
build_setting_default = True,
visibility = ["//visibility:public"],
)

config_setting(
name = "use_libunwind",
flag_values = {":libunwind": "True"},
visibility = ["//visibility:public"],
)

0 comments on commit a3b0dbb

Please sign in to comment.