[fix](build) fix duplicate symbol errors when compiling BE UT with Clang#60504
Merged
hello-stephen merged 1 commit intoapache:masterfrom Feb 5, 2026
Merged
Conversation
Problem: When running `./run-be-ut.sh` without the `--coverage` flag using Clang compiler, the build fails with duplicate symbol errors: ld.lld: error: duplicate symbol: __gcov_fork >>> defined in libgcov.a(libgcov-interface.o) >>> defined in libclang_rt.profile-x86_64.a(GCDAProfiling.o) Root cause analysis: PR apache#59543 introduced a condition in be/CMakeLists.txt to guard GCC-style coverage flags (`-fprofile-arcs -ftest-coverage -lgcov`): if (NOT (ENABLE_CLANG_COVERAGE STREQUAL "ON" AND COMPILER_CLANG)) The intent was to skip GCC coverage when Clang coverage is active. However, this condition has a logic flaw. When using Clang without `--coverage`: - ENABLE_CLANG_COVERAGE = OFF (default, set in run-be-ut.sh line 88) - COMPILER_CLANG = true The condition evaluates as: NOT (OFF AND true) = NOT (false) = true So GCC coverage flags are still added even when using Clang. Clang then implicitly links libclang_rt.profile (which provides its own implementation of __gcov_fork, __gcov_reset, etc.), causing duplicate symbol conflicts with the explicitly linked libgcov.a. Before PR apache#59543, coverage flags were unconditionally added for all compilers in MAKE_TEST mode — which also had the same issue with Clang. Fix: Replace the condition with `if (COMPILER_GCC)` so that GCC-style coverage flags are only added when actually using GCC compiler. This cleanly separates the two coverage mechanisms: - GCC compiler → automatic GCC coverage via -fprofile-arcs + libgcov - Clang compiler → no coverage by default; use --coverage flag to enable Clang coverage via -fprofile-instr-generate | Scenario | Before apache#59543 | After apache#59543 (bug) | This fix | |----------------------|---------------|--------------------|-------------| | GCC, no --coverage | GCC coverage | GCC coverage | GCC coverage| | GCC, --coverage | GCC coverage | GCC coverage | GCC coverage| | Clang, no --coverage | GCC cov (bad) | GCC cov (bad) | No coverage | | Clang, --coverage | GCC+Clang(bad)| Clang coverage | Clang cov |
Contributor
Author
|
run buildall |
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
TPC-H: Total hot run time: 31568 ms |
ClickBench: Total hot run time: 28.69 s |
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
gavinchou
approved these changes
Feb 4, 2026
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
zclllyybb
approved these changes
Feb 4, 2026
Contributor
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
Contributor
|
skip buildall |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
When running
./run-be-ut.shwithout the--coverageflag using Clang compiler, the build fails with duplicate symbol errors:ld.lld: error: duplicate symbol: __gcov_fork
Root cause analysis:
PR #59543 introduced a condition in be/CMakeLists.txt to guard GCC-style coverage flags (
-fprofile-arcs -ftest-coverage -lgcov):if (NOT (ENABLE_CLANG_COVERAGE STREQUAL "ON" AND COMPILER_CLANG))
The intent was to skip GCC coverage when Clang coverage is active. However, this condition has a logic flaw. When using Clang without
--coverage:The condition evaluates as:
NOT (OFF AND true) = NOT (false) = true
So GCC coverage flags are still added even when using Clang. Clang then implicitly links libclang_rt.profile (which provides its own implementation of __gcov_fork, __gcov_reset, etc.), causing duplicate symbol conflicts with the explicitly linked libgcov.a.
Before PR #59543, coverage flags were unconditionally added for all compilers in MAKE_TEST mode — which also had the same issue with Clang.
Fix:
Replace the condition with
if (COMPILER_GCC)so that GCC-style coverage flags are only added when actually using GCC compiler. This cleanly separates the two coverage mechanisms:What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)