Skip to content

Commit

Permalink
Bugfix for LTO. (#266)
Browse files Browse the repository at this point in the history
These `-fno-lto` can leak out to downstream builds.
- When using clang, `-flto=thin` will be append to command by bazel,
reverting the `-fno-lto`.
- But when using gcc with `-flto=auto`, they do not cancel out, causing
undefined references when linker searches for bin code in non-fat obj.
    - Not sure if this is intentional or a compiler bug.

Add toolchain-aware routing.
  • Loading branch information
xkszltl authored Jun 3, 2024
1 parent 0f9f677 commit 550c89e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,24 @@ def cris_deps_libbacktrace(prefix = "."):
name = "libbacktrace",
path = prefix + "/external/libbacktrace",
build_file_content = """
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")
config_setting(
name = "use_clang",
values = {
"compiler": "clang",
},
)
selects.config_setting_group(
name = "linux_use_clang",
match_all = [
"@platforms//os:linux",
"use_clang",
]
)
filegroup(
name = "all_content",
srcs = glob(["**"]),
Expand All @@ -218,8 +234,16 @@ filegroup(
configure_make(
name = "libbacktrace",
lib_source = ":all_content",
copts = ["-fno-lto"],
linkopts = ["-fno-lto"],
# Missing stack trace when using clang LTO.
# - https://github.com/cyfitech/cris-core/issues/95#issuecomment-1441056572
copts = select({
"linux_use_clang": ["-fno-lto"],
"//conditions:default": [],
}),
linkopts = select({
"linux_use_clang": ["-fno-lto"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
)
""",
Expand Down

0 comments on commit 550c89e

Please sign in to comment.