<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 4, 2014 at 9:54 AM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Thu Dec  4 11:54:35 2014<br>
New Revision: 223372<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=223372&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=223372&view=rev</a><br>
Log:<br>
Detect if the linker is gold and if so always use --gc-sections.<br></blockquote><div><br></div><div>so... this makes Debug+Asserts builds vaguely frustrating. 'dump()' functions are going missing left, right, and center if you're debugging a program that has no existing calls to these functions.<br><br>Perhaps we should turn this off for Debug builds? (Doug Evans on GDB tells me there's no particular mechanism for __attribute__((used)) or anything that would force certain uncalled functions to make it through -ffunction-sections + --gc-sections unscathed, otherwise that /might/ be a reasonable workaround)<br><br>& if we aren't using --gc-sections, should we turn off -ffunction-sections too, to save us some space/time/hassle/etc? or does it have other uses?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    llvm/trunk/cmake/modules/AddLLVM.cmake<br>
<br>
Modified: llvm/trunk/cmake/modules/AddLLVM.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=223372&r1=223371&r2=223372&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=223372&r1=223371&r2=223372&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)<br>
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Thu Dec  4 11:54:35 2014<br>
@@ -142,6 +142,14 @@ function(add_llvm_symbol_exports target_<br>
   set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)<br>
 endfunction(add_llvm_symbol_exports)<br>
<br>
+if(NOT WIN32 AND NOT APPLE)<br>
+  execute_process(COMMAND ${CMAKE_C_COMPILER} -Wl,--version<br>
+                  OUTPUT_VARIABLE stdout)<br>
+  if("${stdout}" MATCHES "GNU gold")<br>
+    set(LLVM_LINKER_IS_GOLD ON)<br>
+  endif()<br>
+endif()<br>
+<br>
 function(add_link_opts target_name)<br>
   # Pass -O3 to the linker. This enabled different optimizations on different<br>
   # linkers.<br>
@@ -150,12 +158,18 @@ function(add_link_opts target_name)<br>
                  LINK_FLAGS " -Wl,-O3")<br>
   endif()<br>
<br>
+  if(LLVM_LINKER_IS_GOLD)<br>
+    # With gold gc-sections is always safe.<br>
+    set_property(TARGET ${target_name} APPEND_STRING PROPERTY<br>
+                 LINK_FLAGS " -Wl,--gc-sections")<br>
+  endif()<br>
+<br>
   if(NOT LLVM_NO_DEAD_STRIP)<br>
     if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")<br>
       # ld64's implementation of -dead_strip breaks tools that use plugins.<br>
       set_property(TARGET ${target_name} APPEND_STRING PROPERTY<br>
                    LINK_FLAGS " -Wl,-dead_strip")<br>
-    elseif(NOT WIN32)<br>
+    elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD)<br>
       # Object files are compiled with -ffunction-data-sections.<br>
       # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks<br>
       # tools that use plugins. Always pass --gc-sections once we require<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>