Search code examples
gcclinux-kernelclangclang++llvm-clang

Clang error: Cannot compile builtin function yet


I am compiling the linux kernel code which also contains the gcc libraries (separately added) with clang. I am stuck at the following error:

gcc/unwind-dw2.c:1336:3: error: cannot compile this __builtin_init_dwarf_reg_size_table yet 

'__builtin_init_dwarf_reg_size_table' is a builtin function in gcc. I could not find enough material on the net to solve this error. However I have found the reference to this function in clang as:

BUILTIN(__builtin_init_dwarf_reg_size_table, "vv*", "n")

at location prebuilt_include/clang/include/clang/Basic/Builtins.def. But I don't understand what is its purpose.

Any heads-up regarding the error would be really helpful.

Edit: While looking around to understand how clang works, I found another reference to this builtin function in CGBuiltin.cpp file in function 'EmitBuiltinExpr'. But could not understand how can I use it to solve my problem. Is there any good source to understand all this?


Solution

  • Clang code suggests that, the error cannot compile this <something> yet means that <something> is a construct that is not supported by Clang on the target architecture.

    In this case,init_dwarf_reg_size_table is a GCC builtin, which isn't fully supported on all Clang targets. Inspecting GCC's builtins.def can confirm that init_dwarf_reg_size_table is a GCC extension.

    As a workaround, you may have to compile with GCC instead, or with a more recent clang version which supports this builtin, if any.


    Following clang code, the cannot compile this <something> yet message is printed by the ErrorUnsupported function in CodeGenModule.cpp:

    /// ErrorUnsupported - Print out an error that codegen doesn't support the
    /// specified stmt yet.
    void CodeGenModule::ErrorUnsupported(const Stmt *S, const char *Type) {
      unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error,
                                                   "cannot compile this %0 yet");
      std::string Msg = Type;
      getDiags().Report(Context.getFullLoc(S->getLocStart()), DiagID)
        << Msg << S->getSourceRange();
    }
    

    In CGBuiltin.cpp, the builtin is expanded and ErrorUnsupported is called if the the initDwarfEHRegSizeTable target hook failed:

      case Builtin::BI__builtin_init_dwarf_reg_size_table: {
        Value *Address = EmitScalarExpr(E->getArg(0));
        if (getTargetHooks().initDwarfEHRegSizeTable(*this, Address))
          CGM.ErrorUnsupported(E, "__builtin_init_dwarf_reg_size_table");
        return RValue::get(llvm::UndefValue::get(ConvertType(E->getType())));
      }
    

    initDwarfEHRegSizeTable is defined in TargetInfo.cpp. To be honest, I don't fully understand yet under what conditions it fails (which also depends on the target architecture).