[compiler-rt] r214040 - builtins: avoid multiple definitions of symbols

Saleem Abdulrasool compnerd at compnerd.org
Sat Jul 26 16:44:22 PDT 2014

Author: compnerd
Date: Sat Jul 26 18:44:22 2014
New Revision: 214040

URL: http://llvm.org/viewvc/llvm-project?rev=214040&view=rev
builtins: avoid multiple definitions of symbols

The architecture specific implementation of routines would be built and included
along with the generic implementation.  This would result in multiple
definitions of those symbols.

The linker is free to select either of the two.  Most of the time, this
shouldn't be too terrible as the forward iteration should catch the architecture
version due to the ordering.  Rather than relying on the linker and build
infrastructure ordering things in a specific manner, only provide the
architecture version when available.

This reduces the size of compiler-rt, simplifies inspection of the library
implementations, and guarantees that the desired version is selected at a
slightly complex build system.


Modified: compiler-rt/trunk/lib/builtins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/CMakeLists.txt?rev=214040&r1=214039&r2=214040&view=diff
--- compiler-rt/trunk/lib/builtins/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/builtins/CMakeLists.txt Sat Jul 26 18:44:22 2014
@@ -249,15 +249,26 @@ set(arm_SOURCES
 if (NOT WIN32)
-  foreach(arch x86_64 i386 arm)
-    if(CAN_TARGET_${arch})
+  foreach (arch x86_64 i386 arm)
+    if (CAN_TARGET_${arch})
+      # Filter out generic versions of routines that are re-implemented in
+      # architecture specific manner.  This prevents multiple definitions of the
+      # same symbols, making the symbol selection non-deterministic.
+      foreach (_file ${${arch}_SOURCES})
+        if (${_file} MATCHES ${arch}/*)
+          get_filename_component(_name ${_file} NAME)
+          string(REPLACE ".S" ".c" _cname "${_name}")
+          list(REMOVE_ITEM ${arch}_SOURCES ${_cname})
+        endif ()
+      endforeach ()
       set_source_files_properties(${${arch}_SOURCES} PROPERTIES LANGUAGE C)
       add_compiler_rt_runtime(clang_rt.builtins-${arch} ${arch} STATIC
-        SOURCES ${${arch}_SOURCES}
-        CFLAGS "-std=c99")
+                              SOURCES ${${arch}_SOURCES}
+                              CFLAGS "-std=c99")
       add_dependencies(builtins clang_rt.builtins-${arch})
-    endif()
-  endforeach()
+    endif ()
+  endforeach ()
+endif ()
 add_dependencies(compiler-rt builtins)

More information about the llvm-commits mailing list