From 291b40ee9a6a032b04ec0ee58f45b04a0e674ce7 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 30 Jun 2025 15:54:14 +0800 Subject: [PATCH] cmake: remove osdc/error_code.cc from osdc to fix ODR violation Fix AddressSanitizer ODR (One Definition Rule) violation caused by osdc/error_code.cc being compiled into both the osdc library and ceph-common library. The violation occurred because osdc_error_category was defined in both the rbd binary (via osdc) and libceph-common.so, creating duplicate symbols at runtime. Since all targets that link against osdc also link against ceph-common, removing osdc/error_code.cc from osdc doesn't break the build while eliminating the duplicate definition. ASan error sample: ``` ==857433==ERROR: AddressSanitizer: odr-violation (0x5612ad665760): [1] size=22 'typeinfo name for osdc_error_category' /home/jenkins-build/build/workspace/ceph-pull-requests/src/osdc/error_code.cc in /home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/rbd [2] size=22 'typeinfo name for osdc_error_category' /home/jenkins-build/build/workspace/ceph-pull-requests/src/osdc/error_code.cc in /home/jenkins-build/build/workspace/ceph-pull-requests/build/lib/libceph-common.so.2 These globals were registered at these points: [1]: #0 0x5612acd62c88 in __asan_register_globals (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/rbd+0x815c88) (BuildId: 62a02cbbf3426e5470e16372e3b53a18cb18ce0f) #1 0x5612acd63d59 in __asan_register_elf_globals (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/rbd+0x816d59) (BuildId: 62a02cbbf3426e5470e16372e3b53a18cb18ce0f) #2 0x7f28d3b02eba in call_init csu/../csu/libc-start.c:145:3 #3 0x7f28d3b02eba in __libc_start_main csu/../csu/libc-start.c:379:5 ``` Signed-off-by: Kefu Chai --- src/osdc/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/osdc/CMakeLists.txt b/src/osdc/CMakeLists.txt index 637ce32755583..38d4dfd35652e 100644 --- a/src/osdc/CMakeLists.txt +++ b/src/osdc/CMakeLists.txt @@ -1,8 +1,7 @@ set(osdc_files Filer.cc - ObjectCacher.cc - error_code.cc) -# Objecter.cc and Striper.cc are part of libcommon + ObjectCacher.cc) +# error_code.cc, Objecter.cc and Striper.cc are part of libcommon add_library(osdc STATIC ${osdc_files}) target_link_libraries(osdc ceph-common) if(WITH_EVENTTRACE) -- 2.39.5