Skip to content

Commit

Permalink
Drop coverage linker flags from stdlib build
Browse files Browse the repository at this point in the history
We never compile CGo with coverage instrumentation and the stdlib
contains no user-provided C/C++ code, so linking coverage runtimes is
never needed.
  • Loading branch information
fmeum committed Apr 6, 2023
1 parent 5d87e18 commit 1651196
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion go/private/actions/stdlib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load(
"//go/private:common.bzl",
"COVERAGE_OPTIONS_DENYLIST",
)
load(
"//go/private:providers.bzl",
"GoStdLib",
Expand Down Expand Up @@ -96,10 +100,12 @@ def _build_stdlib(go):
else:
# NOTE(#2545): avoid unnecessary dynamic link
# go std library doesn't use C++, so should not have -lstdc++
# Also drop coverage flags as nothing in the stdlib is compiled with
# coverage - we disable it for all CGo code anyway.
ldflags = [
option
for option in extldflags_from_cc_toolchain(go)
if option not in ("-lstdc++", "-lc++")
if option not in ("-lstdc++", "-lc++") and option not in COVERAGE_OPTIONS_DENYLIST
]
env.update({
"CGO_ENABLED": "1",
Expand Down
9 changes: 9 additions & 0 deletions go/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,12 @@ def count_group_matches(v, prefix, suffix):
count = count + 1

return count

# C/C++ compiler and linker options related to coverage instrumentation.
COVERAGE_OPTIONS_DENYLIST = {
"--coverage": None,
"-ftest-coverage": None,
"-fprofile-arcs": None,
"-fprofile-instr-generate": None,
"-fcoverage-mapping": None,
}
5 changes: 3 additions & 2 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ load(
"goos_to_extension",
"goos_to_shared_extension",
"is_struct",
"COVERAGE_OPTIONS_DENYLIST",
)
load(
"//go/platform:apple.bzl",
Expand Down Expand Up @@ -86,7 +87,7 @@ _UNSUPPORTED_C_COMPILERS = {
"clang-cl": None,
}

_COMPILER_OPTIONS_DENYLIST = {
_COMPILER_OPTIONS_DENYLIST = dict({
# cgo parses the error messages from the compiler. It can't handle colors.
# Ignore both variants of the diagnostics color flag.
"-fcolor-diagnostics": None,
Expand All @@ -107,7 +108,7 @@ _COMPILER_OPTIONS_DENYLIST = {
"-fprofile-arcs": None,
"-fprofile-instr-generate": None,
"-fcoverage-mapping": None,
}
}, **COVERAGE_OPTIONS_DENYLIST)

_LINKER_OPTIONS_DENYLIST = {
"-Wl,--gc-sections": None,
Expand Down

0 comments on commit 1651196

Please sign in to comment.