[LLVMdev] TableGen crash

LRN lrn1986 at gmail.com
Thu Jan 1 21:19:50 PST 2009


TableGen crashes while building llvm when it tries to generate
/llvm/tools/llvmc/plugins/Base/AutoGenerated.inc from
/llvm/tools/llvmc/plugins/Base/Base.td
As a result AutoGenerated.inc is full of garbage and it's not possible
to proceed any further.

I've debugged TableGen and found out that it dies somewhere in
EmitForwardOptionPropertyHandlingCode().

I've modified LLVMCConfigurationEmitter.cpp to be like this:

/// EmitForwardOptionPropertyHandlingCode - Helper function used to
/// implement EmitActionHandler. Emits code for
/// handling the (forward) and (forward_as) option properties.
void EmitForwardOptionPropertyHandlingCode (const OptionDescription& D,
                                            const char* Indent,
                                            const std::string& NewName,
                                            std::ostream& O) {
  const std::string& Name = NewName.empty()
    ? ("-" + D.Name)
    : NewName;

  switch (D.Type) {
  case OptionType::Switch:
    O << Indent << "vec.push_back(\"" << Name << "\");\n";
    break;
  case OptionType::Parameter:
    O << Indent << "vec.push_back(\"" << Name << "\");\n";
    O << Indent << "vec.push_back(" << D.GenVariableName() << ");\n";
    break;
  case OptionType::Prefix:
    O << Indent << "vec.push_back(\"" << Name << "\" + "
      << D.GenVariableName() << ");\n";
    break;
  case OptionType::PrefixList:
    O << Indent << "for (" << D.GenTypeDeclaration()
      << "::iterator B = " << D.GenVariableName() << ".begin(),\n"
      << Indent << "E = " << D.GenVariableName() << ".end(); B != E; ++B)\n"
      << Indent << Indent1 << "vec.push_back(\"" << Name << "\" + "
      << "*B);\n";
    break;
  case OptionType::ParameterList:
    O << Indent;
    O << "for (";
    O << D.GenTypeDeclaration();
    O << "::iterator B = ";
    O << D.GenVariableName();
    O << ".begin(),\n";
    O << Indent;
    O << "E = ";
    O << D.GenVariableName();
    O << ".end() ; B != E; ++B) {\n";
    O << Indent;
    O << Indent1;
    O << "vec.push_back(\"";
    O << Name;
    O << "\");\n";
    O << Indent;
    O << Indent1;
    O << "vec.push_back(*B);\n";
    O << Indent;
    O << "}\n";
    break;
  case OptionType::Alias:
  default:
    throw std::string("Aliases are not allowed in tool option
descriptions!");
  }
}

and re-built TableGen.

then from /d/projects/llvm/utils/TableGen i did:

$ gdb
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
(gdb) file d:\\projects\\llvm\\Debug\\bin\\tblgen.exe
Reading symbols from d:\projects\llvm\Debug\bin\tblgen.exe...done.
(gdb) set args -I d:/projects/llvm/tools/llvmc/plugins/Base -I
d:/projects/llvm/include -I d:/projects/llvm/lib/Target -gen-llvmc -o
d:/projects/llvm/tools/llvmc/plugins/Base/Debug/AutoGenerated.inc.tmp
d:/projects/llvm/tools/llvmc/plugins/Base/Base.td
(gdb) start
Breakpoint 1 at 0x481330: file TableGen.cpp, line 129.
Starting program: d:\projects\llvm\Debug\bin\tblgen.exe -I
d:/projects/llvm/tools/llvmc/plugins/Base -I d:/projects/llvm/include -I
d:/projects/llvm/lib/Target -gen-llvmc -o
d:/projects/llvm/tools/llvmc/plugins/Base/Debug/Aut
oGenerated.inc.tmp d:/projects/llvm/tools/llvmc/plugins/Base/Base.td
[New thread 3744.0x1a10]
Error: dll starting at 0x77d40000 not found.
Error while mapping shared library sections:
NOT_AN_IMAGE: No such file or directory.
Error while mapping shared library sections:
C:\WINXP64\SysWOW64\ntdll32.dll: No such file or directory.
Error: dll starting at 0x77d40000 not found.
Error: dll starting at 0x77c20000 not found.
main (argc=2293680, argv=0x4010b6) at TableGen.cpp:129
129     int main(int argc, char **argv) {
(gdb) break 196
Breakpoint 2 at 0x481b7c: file TableGen.cpp, line 196.
(gdb) c
Continuing.

Breakpoint 2, main (argc=2293680, argv=0x4010b6) at TableGen.cpp:196
196           LLVMCConfigurationEmitter(Records).run(*Out);
(gdb) s
llvm::LLVMCConfigurationEmitter::run (this=0x22ff40, O=0xd0d190) at
LLVMCConfigurationEmitter.cpp:1882
1882      PluginData Data;
(gdb) break 1147
Breakpoint 3 at 0x45a651: file LLVMCConfigurationEmitter.cpp, line 1147.
(gdb) c
Continuing.

Breakpoint 3, (anonymous
namespace)::EmitForwardOptionPropertyHandlingCode (D=0xd0d81c,
Indent=0xd0de4c ' ' <repeats 12 times>, NewName=0x22f860, O=0xd0d190) at
LLVMCConfigurationEmitter.cpp:1149
1149        : NewName;
(gdb) n
1151      switch (D.Type) {
(gdb) n
1171        O << Indent;
(gdb) n
1172        O << "for (";
(gdb) n
1173        O << D.GenTypeDeclaration();
(gdb) n
1174        O << "::iterator B = ";
(gdb) n
1175        O << D.GenVariableName();
(gdb) n
1176        O << ".begin(),\n";
(gdb) n
1177        O << Indent;
(gdb) n
1178        O << "E = ";
(gdb) n
1179        O << D.GenVariableName();
(gdb) n
1180        O << ".end() ; B != E; ++B) {\n";
(gdb) n
1181        O << Indent;
(gdb) n
1182        O << Indent1;
(gdb) n
1183        O << "vec.push_back(\"";
(gdb) n
1184        O << Name;
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x77bc10f5 in wsopen () from C:\WINXP64\syswow64\msvcrt.dll
(gdb) bt
#0  0x77bc10f5 in wsopen () from C:\WINXP64\syswow64\msvcrt.dll
#1  0x0000006c in ?? ()
#2  0x00000003 in ?? ()
#3  0x77bf4a00 in ?? ()
#4  0x00000400 in ?? ()
#5  0x00d0da7c in ?? ()
#6  0x00000000 in ?? ()

I think there's something wrong with NewName. I don't know how to debug
std::string's in gdb, so i can't check what's happening with it, but an
attempt to step into "const std::string& Name = NewName.empty() ? ("-" +
D.Name) : NewName;" results in a segfault.
"(gdb) print NewName.c_str()" causes a segfault too.

This is reproduceable for both SVN and 2.4, but not in 2.3 (2.3 builds
without errors).

P.S. /llvm/utils/unittest/googletest/include/gtest/gtest-port.h:175 is
VERY true. Tell kenton that gtest-filepath.cc:267 should be updated
accordingly.



More information about the llvm-dev mailing list