Add missing bsd link libraries (#859) This mirrors this behavior from the clang driver: https://github.com/llvm/llvm-project/blob/3e892fad65730692057da27bebb2e34d3ad7bde7/clang/lib/Driver/ToolChains/OpenBSD.cpp#L365-L366 The same does not apply for freebsd (I didn't check netbsd which isn't supported here right now). Alternatively we could use clang++ for linking directly instead of clang, which would add these automatically, but that would make it harder to disable these in the case you are linking pure C Fixes https://github.com/bazelbuild/rules_cc/issues/857 Closes #859 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_cc/pull/859 from keith:ks/add-missing-openbsd-link-flags 70575fbff89f98fb4eb76db417e035133e8d767f PiperOrigin-RevId: 977503273 Change-Id: Ifcb127ace43f5bad5f075de8dc7ae21d3182858d
diff --git a/cc/private/toolchain/bsd_cc_toolchain_config.bzl b/cc/private/toolchain/bsd_cc_toolchain_config.bzl index d10557a..74891d6 100644 --- a/cc/private/toolchain/bsd_cc_toolchain_config.bzl +++ b/cc/private/toolchain/bsd_cc_toolchain_config.bzl
@@ -60,6 +60,10 @@ if cpu not in ("freebsd", "openbsd"): fail("unsupported BSD CPU: %s" % cpu) + extra_default_link_flags = [] + if cpu == "openbsd": + extra_default_link_flags = ["-lc++abi", "-lpthread"] + default_link_flags_feature = feature( name = "default_link_flags", enabled = True, @@ -70,9 +74,10 @@ flag_group( flags = [ "-lc++", + "-lm", "-Wl,-z,relro,-z,now,-z,origin", "-no-canonical-prefixes", - ], + ] + extra_default_link_flags, ), ], ),