[PATCH] D31063: LTO: Fix a potential race condition in the caching API.

Ulrich Weigand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 14:16:10 PDT 2017


uweigand added a comment.

In https://reviews.llvm.org/D31063#704025, @pcc wrote:

> The only explanation I can think of is that there is some sort of bug in your stdlib that causes the if condition to succeed.


Indeed, this does appear to be the case.   I can reproduce the problem with this simple program:

  #include <iostream>
  #include <system_error>
  
  int main() {
      std::error_code code = std::error_code(ENOENT, std::generic_category());
      if (code != std::errc::no_such_file_or_directory)
        std::cout << "comparison failed" << std::endl;
  }

This fails on the build bot machine, but succeeds on my other development machines.  It appears the problem is related to the fact on this machine (running SLES12), the system compiler is a gcc 4.8, but the system libstdc++ library is one from gcc 6.  This of course is supposed to be a compatible combination, but apparently there is a problem when comparing error codes.  The value is the same, but the category class pointer doesn't match, apparently because in the gcc 6 libstdc++ there are two flavours of those classes, and when mixing gcc 4.8 and gcc 6 code, sometimes wrong versions get compared ...

> What happens if you apply this patch?
> 
>   diff --git a/llvm/lib/LTO/Caching.cpp b/llvm/lib/LTO/Caching.cpp
>   index d8b91c48ee3..c24540e1860 100644
>   --- a/llvm/lib/LTO/Caching.cpp
>   +++ b/llvm/lib/LTO/Caching.cpp
>   @@ -37,7 +37,8 @@ Expected<NativeObjectCache> lto::localCache(StringRef CacheDirectoryPath,
>          return AddStreamFn();
>        }
>    
>   -    if (MBOrErr.getError() != std::errc::no_such_file_or_directory)
>   +    if (MBOrErr.getError() != std::errc::no_such_file_or_directory &&
>   +        MBOrErr.getError().message() != "No such file or directory")
>          report_fatal_error(Twine("Failed to open cache file ") + EntryPath +
>                             ": " + MBOrErr.getError().message() + "\n");
>    

This does fix the problem for me.  Likewise the (maybe more straightforward) fix

  if ((std::errc)MBOrErr.getError().value() != std::errc::no_such_file_or_directory)
    ...

I'll work with the distro to hopefully get this fixed, but maybe we can get a workaround along those  lines installed so the build bot can continue to run in the meantime?


Repository:
  rL LLVM

https://reviews.llvm.org/D31063





More information about the llvm-commits mailing list