[llvm] r223372 - Detect if the linker is gold and if so always use --gc-sections.

David Blaikie dblaikie at gmail.com
Thu Apr 2 15:31:31 PDT 2015


On Thu, Dec 4, 2014 at 9:54 AM, Rafael Espindola <rafael.espindola at gmail.com
> wrote:

> Author: rafael
> Date: Thu Dec  4 11:54:35 2014
> New Revision: 223372
>
> URL: http://llvm.org/viewvc/llvm-project?rev=223372&view=rev
> Log:
> Detect if the linker is gold and if so always use --gc-sections.
>

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.

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)

& 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?


>
> Modified:
>     llvm/trunk/cmake/modules/AddLLVM.cmake
>
> Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=223372&r1=223371&r2=223372&view=diff
>
> ==============================================================================
> --- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
> +++ llvm/trunk/cmake/modules/AddLLVM.cmake Thu Dec  4 11:54:35 2014
> @@ -142,6 +142,14 @@ function(add_llvm_symbol_exports target_
>    set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
>  endfunction(add_llvm_symbol_exports)
>
> +if(NOT WIN32 AND NOT APPLE)
> +  execute_process(COMMAND ${CMAKE_C_COMPILER} -Wl,--version
> +                  OUTPUT_VARIABLE stdout)
> +  if("${stdout}" MATCHES "GNU gold")
> +    set(LLVM_LINKER_IS_GOLD ON)
> +  endif()
> +endif()
> +
>  function(add_link_opts target_name)
>    # Pass -O3 to the linker. This enabled different optimizations on
> different
>    # linkers.
> @@ -150,12 +158,18 @@ function(add_link_opts target_name)
>                   LINK_FLAGS " -Wl,-O3")
>    endif()
>
> +  if(LLVM_LINKER_IS_GOLD)
> +    # With gold gc-sections is always safe.
> +    set_property(TARGET ${target_name} APPEND_STRING PROPERTY
> +                 LINK_FLAGS " -Wl,--gc-sections")
> +  endif()
> +
>    if(NOT LLVM_NO_DEAD_STRIP)
>      if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
>        # ld64's implementation of -dead_strip breaks tools that use
> plugins.
>        set_property(TARGET ${target_name} APPEND_STRING PROPERTY
>                     LINK_FLAGS " -Wl,-dead_strip")
> -    elseif(NOT WIN32)
> +    elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD)
>        # Object files are compiled with -ffunction-data-sections.
>        # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that
> breaks
>        # tools that use plugins. Always pass --gc-sections once we require
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150402/386d59a9/attachment.html>


More information about the llvm-commits mailing list