This is an archive of the discontinued LLVM Phabricator instance.

[Compiler-rt] Emit error if builtins library cannot be found
ClosedPublic

Authored by kongyi on May 5 2020, 11:11 PM.

Details

Summary

Since setting COMPILER_RT_USE_BUILTINS_LIBRARY would remove -z,defs flag, missing builtins library would continue to build unnoticed. Explicitly emit an error in such case.

Diff Detail

Event Timeline

kongyi created this revision.May 5 2020, 11:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2020, 11:11 PM
Herald added subscribers: Restricted Project, mgorny, dberris. · View Herald Transcript
hhb accepted this revision.May 8 2020, 10:15 PM
This revision is now accepted and ready to land.May 8 2020, 10:15 PM
hhb requested changes to this revision.May 8 2020, 10:19 PM
hhb added inline comments.
compiler-rt/cmake/Modules/AddCompilerRT.cmake
240

Should be "NOTFOUND"?

This revision now requires changes to proceed.May 8 2020, 10:19 PM
kongyi updated this revision to Diff 264411.May 15 2020, 9:01 PM
kongyi marked an inline comment as done.
hhb accepted this revision.May 15 2020, 11:42 PM
This revision is now accepted and ready to land.May 15 2020, 11:42 PM
This revision was automatically updated to reflect the committed changes.

This broke bootstrapping compiler-rt builtins for me.

When bootstrapping a new toolchain from scratch, we don't have any compiler-rt builtins, so this test will necessarily fail - until the builtins have been compiled and installed.

I can work around it temporarily by not setting COMPILER_RT_USE_BUILTINS_LIBRARY while building the builtins, but if that flag isnt' set, it literally means "we should use libgcc instead of compiler-rt builtins".

I think this kind of fix would make sense:

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index 1dde396b1f6..55fd125bac2 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -231,13 +231,14 @@ function(add_compiler_rt_runtime name type)
         if(WIN32)
           set_output_name(output_name_${libname} ${name}_dynamic ${arch})
         else()
           set_output_name(output_name_${libname} ${name} ${arch})
         endif()
       endif()
-      if(COMPILER_RT_USE_BUILTINS_LIBRARY AND NOT type STREQUAL "OBJECT")
+      if(COMPILER_RT_USE_BUILTINS_LIBRARY AND NOT type STREQUAL "OBJECT" AND 
+         NOT name STREQUAL "clang_rt.builtins")
         get_compiler_rt_target(${arch} target)
         find_compiler_rt_library(builtins ${target} builtins_${libname})
          if(builtins_${libname} STREQUAL "NOTFOUND")
           message(FATAL_ERROR "Cannot find builtins library for the target architecture")
         endif()
       endif()

Because when building the builtins themselves, we can't expect to find builtins, right? (Alternatively the check against clang_rt.builtins could be moved down to the NOTFOUND case.)

Because when building the builtins themselves, we can't expect to find builtins, right? (Alternatively the check against clang_rt.builtins could be moved down to the NOTFOUND case.)

You're right, we shouldn't fail the build for standalone clang_rt.builtins target. Please submit your change.

Because when building the builtins themselves, we can't expect to find builtins, right? (Alternatively the check against clang_rt.builtins could be moved down to the NOTFOUND case.)

You're right, we shouldn't fail the build for standalone clang_rt.builtins target. Please submit your change.

Thanks, pushed in 54a85240709ecbcab329fb39af8ba5d6cd565305.