This is an automated email from the ASF dual-hosted git repository.

hellostephen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new f39bb99174e [fix](build) fix duplicate symbol errors when compiling BE 
UT with Clang (#60504)
f39bb99174e is described below

commit f39bb99174e772973344c808721a17919245b566
Author: deardeng <[email protected]>
AuthorDate: Thu Feb 5 11:44:45 2026 +0800

    [fix](build) fix duplicate symbol errors when compiling BE UT with Clang 
(#60504)
    
    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 #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 #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 #59543 | After #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 |
---
 be/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt
index ab7c5dfa6b2..16f3737d494 100644
--- a/be/CMakeLists.txt
+++ b/be/CMakeLists.txt
@@ -715,10 +715,10 @@ endif ()
 
 if (MAKE_TEST)
     add_compile_options(-DGTEST_USE_OWN_TR1_TUPLE=0)
-    # Only add GCC-style coverage when NOT using Clang coverage
+    # Only add GCC-style coverage when using GCC compiler
     # to avoid duplicate symbol errors (e.g., __gcov_fork, __gcov_reset)
     # between libgcov.a and libclang_rt.profile-x86_64.a
-    if (NOT (ENABLE_CLANG_COVERAGE STREQUAL "ON" AND COMPILER_CLANG))
+    if (COMPILER_GCC)
         add_compile_options(-fprofile-arcs -ftest-coverage)
         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs 
-ftest-coverage")
         if (NOT OS_MACOSX)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to