[llvm] r200695 - Don't use -ffunction-sections if -fno-function-sections is not supported in the compiler.

Justin Bogner mail at justinbogner.com
Mon Feb 3 13:49:26 PST 2014


Evgeniy Stepanov <eugeni.stepanov at gmail.com> writes:
> Don't use -ffunction-sections if -fno-function-sections is not
> supported in the compiler.
>
> This will disable -ffunction-sections in older versions of Clang where it
> breaks build of sanitizer runtime library.
>
> Modified:
>     llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
>
> Modified: llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/HandleLLVMOptions.cmake?rev=200695&r1=200694&r2=200695&view=diff==============================================================================
> --- llvm/trunk/cmake/modules/HandleLLVMOptions.cmake (original)
> +++ llvm/trunk/cmake/modules/HandleLLVMOptions.cmake Mon Feb  3 07:57:09 2014
> @@ -350,13 +350,23 @@ if (UNIX AND
>    append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
>  endif()
>  
> +# Clang prior to 3.5 ignored -fno-function-sections.
> +# It's pretty hard to test directly, so we rely on the version number.
> +if( ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) )
> +  set(LLVM_COMPILER_HAS_BROKEN_FNO_FUNCTION_SECTIONS ON)
> +endif()
> +

Please don't do it this way. Relying on version numbers to check for a
feature is the wrong thing to do. It doesn't account for the 5000
revisions that are called 3.5 and don't support this flag and just
generally isn't nice to packagers.

It also wouldn't be very scalable if other compilers needed to be
handled as well, though that doesn't seem to be the case in this
particular example.

Can't we check if the compiler supports the flag directly?

>  # Add flags for add_dead_strip().
>  # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF?
>  # But MinSizeRel seems to add that automatically, so maybe disable these
>  # flags instead if LLVM_NO_DEAD_STRIP is set.
>  if(NOT CYGWIN AND NOT WIN32)
>    if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
> -    append("-ffunction-sections -fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
> +    # Don't add -ffunction-section if it can be disabled with -fno-function-sections.
> +    # Doing so will break sanitizers.
> +    if (NOT LLVM_COMPILER_HAS_BROKEN_FNO_FUNCTION_SECTIONS)
> +      append("-ffunction-sections -fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
> +    endif()
>    endif()
>  endif()
>  
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list