builtins: avoid multiple definitions of symbols
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 26 Jul 2014 23:44:22 +0000 (23:44 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 26 Jul 2014 23:44:22 +0000 (23:44 +0000)
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.

llvm-svn: 214040

compiler-rt/lib/builtins/CMakeLists.txt

index 6289cdd..309ef4f 100644 (file)
@@ -249,15 +249,26 @@ set(arm_SOURCES
 add_custom_target(builtins)
 
 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()
+    endif ()
+  endforeach ()
+endif ()
 
 add_dependencies(compiler-rt builtins)