https://llvm.org/bugs/show_bug.cgi?id=28220
Bug ID: 28220 Summary: COFF writer crash with -O2 but not -O1: missing associated COMDAT section for section .CRT$XCU Product: new-bugs Version: trunk Hardware: PC OS: Windows NT Status: NEW Severity: normal Priority: P Component: new bugs Assignee: unassignedb...@nondot.org Reporter: mattiwa...@gmail.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified Created attachment 16602 --> https://llvm.org/bugs/attachment.cgi?id=16602&action=edit IR of foo.cpp with -O1 I don't actually know if this is a codegen or optimizer bug, but it only manifests at -O2 so the optimizer at least influences it. Anyway, here's the code: template<typename T> struct DumbPointer { DumbPointer() : ItsNull(nullptr) {} T* ItsNull; }; template<typename T> struct __declspec(dllimport) GetMyT // Note: dllimport needed to reproduce { static DumbPointer<T> Instance; }; template<typename T> DumbPointer<T> GetMyT<T>::Instance; // Will cause a warning with -Wglobal-constructors static void* P = GetMyT<void>::Instance.ItsNull; This compiles with clang -O1, but crashes with -O2, using: clang -cc1 -triple x86_64-pc-windows-msvc19 -fms-compatibility -std=c++14 -emit-obj -O<1|2> foo.cpp -o foo.obj. LLVM/Clang used is 3.9 273191 from trunk and 3.8 stable. The error is: fatal error: error in backend: Missing associated COMDAT section for section .CRT$XCU. This comes from WinCOFFObjectWriter. I will attach the LLVM IR files (which I'm not very good at reading), but the relevant difference in the generated x86 assembly seems to be that the -O2 version has an associative .CRT$XCU (global ctor) section and the -O1 version does not. However, the full 25 MB preprocessed .cpp file I reduced this from actually has two *added* .CRT$XCU sections when compiled with -O2 (4 with -O2 of which 3 associative, compared to 2 with -O1 of which 1 associative). Regardless this leads to the same crash in the COFF writer. Using opt+llc I was able to pinpoint the source of the change to the -elim-avail-extern pass, and indeed after compiling LLVM with the first half of the pass commented out I was able to run the entire .cpp -> .obj compilation on both the sample and the 25 MB file using -O2 with no crash. (By the way, why is there no way to disable a specific optimizer pass? I found OptBisect, but that seems rather useless to me if you want to single out one pass, since it skips every pass after the given threshold. I know you can specify the whole pass list manually, but it would be much simpler to do -O2 -skip-pass=elim-avail-extern.) So my question is: is the optimizer pass wrong in eliminating initializers of globals that are dllimport, or is the COFF writer choking on something it should be able to patch up? If it's the former, shouldn't the bitcode verifier have been able to catch it? -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs