llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

llc assertion failure with COFF target

Open david-xl opened this issue 10 years ago • 15 comments

Bugzilla Link 25912
Resolution FIXED
Resolved on Dec 21, 2015 19:39
Version trunk
OS Linux
CC @majnemer,@vns-mn,@kcc,@rnk

Extended Description

pass the following simple ll file to llc, llc will assert. I have not looked at in in details.

; ModuleID = '' target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-pc-win64-coff"

@​llvm.global_ctors = appending global [1 x { i32, void (), i8 }] [{ i32, void (), i8 } { i32 0, void ()* @​__llvm_profile_init, i8* null }]

; Function Attrs: noinline define internal void @​__llvm_profile_init() unnamed_addr #​1 { ret void }

attributes #​0 = { nounwind }

The assertion failure is:

llc: /usr/local/google/davidxl/dev/llvm/include/llvm/Support/Casting.h:237: typename cast_retty<X, Y >::ret_type llvm::cast(Y ) [X = llvm::MCSectionCOFF, Y = llvm::MCSection]: Assertion `isa(Val) && "cast() argument of incompatible type!"' failed. 0 llc 0x0000000000670b41 backtrace + 65 1 llc 0x0000000003ccd4c1 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 241 2 llc 0x0000000003cce9f4 3 libpthread.so.0 0x00007f379b9e3330 4 libc.so.6 0x00007f379ac0bcb7 gsignal + 55 5 libc.so.6 0x00007f379ac0f0a8 abort + 328 6 libc.so.6 0x00007f379ac04b76 7 libc.so.6 0x00007f379ac04c22 8 llc 0x0000000002cc7eb4 9 llc 0x0000000002634513 llvm::AsmPrinter::EmitXXStructorList(llvm::DataLayout const&, llvm::Constant const, bool) + 3523 10 llc 0x000000000261d26e llvm::AsmPrinter::EmitSpecialLLVMGlobal(llvm::GlobalVariable const) + 766

david-xl avatar Dec 21 '15 23:12 david-xl

Fixed in r256226.

majnemer avatar Dec 22 '15 03:12 majnemer

feel free to commit it to bring your bot back: r256225.

kcc avatar Dec 22 '15 03:12 kcc

FTR, this also seems to crash the sanitizer bootstrap bot: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/ 10417/steps/check-llvm%20msan/logs/stdio

The following patch seems to fix that test, feel free to commit it to bring your bot back:

diff --git a/test/Instrumentation/InstrProfiling/#23499 .ll b/test/Instrumentation/InstrProfiling/#23499 .ll index d63c01a..d92adf3 100644 --- a/test/Instrumentation/InstrProfiling/#23499 .ll +++ b/test/Instrumentation/InstrProfiling/#23499 .ll @@ -4,7 +4,7 @@

; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s ; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s -; RUN: opt < %s -mtriple=x86_64-pc-win64-coff -instrprof -S | FileCheck %s --check-prefix=COFF +; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -instrprof -S | FileCheck %s --check-prefix=COFF

majnemer avatar Dec 22 '15 03:12 majnemer

FTR, this also seems to crash the sanitizer bootstrap bot: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/10417/steps/check-llvm%20msan/logs/stdio

kcc avatar Dec 22 '15 02:12 kcc

Great. Thanks for fixing the issue (set aside the win32 vs win64 issue, I think the bug itself is still valid -- as elf section should not be created when the specified format is coff).

david-xl avatar Dec 22 '15 02:12 david-xl

Because win64 isn't the name of the MSVC environment.

Sorry I am still confused. Is x86_64-pc-win64-coff a valid triple to use?

"x86_64-pc-win64-coff" is a valid triple in the sense that LLVM should be able to successfully parse it into something but the result will not make sense to LLVM. The "win64" component that you are specifying has no meaning to LLVM.

x86_64-pc-win64-coff: valid. we know what CPU and object file is targeted, we don't know what OS environment "win64" means. x86_64-pc-win32-coff: valid. we know what CPU and object file is targeted and we know we are targeting Windows.

Ok -- is there any documentation on that? Should LLVM recognize win64 as windows or there is a reason LLVM can not do that?

We could teach LLVM to recognize win64 but I think it would be a superfluous change, there would be no real benefit that I can see.

I saw one other test case uses this triple: test/CodeGen/X86/statepoint-stackmap-format.ll

Should it be fixed?

Yes, I am working on a patch to fix this crash. The patch will also fix that test case.

I also did not seem to find any test case with xxx-win32-coff combination.

That is because we infer the 'coff' object file format from the rest of the triple, 'win32' cannot natively load anything other than 'coff'.

majnemer avatar Dec 22 '15 02:12 majnemer

Because win64 isn't the name of the MSVC environment.

Sorry I am still confused. Is x86_64-pc-win64-coff a valid triple to use?

"x86_64-pc-win64-coff" is a valid triple in the sense that LLVM should be able to successfully parse it into something but the result will not make sense to LLVM. The "win64" component that you are specifying has no meaning to LLVM.

x86_64-pc-win64-coff: valid. we know what CPU and object file is targeted, we don't know what OS environment "win64" means. x86_64-pc-win32-coff: valid. we know what CPU and object file is targeted and we know we are targeting Windows.

Ok -- is there any documentation on that? Should LLVM recognize win64 as windows or there is a reason LLVM can not do that?

I saw one other test case uses this triple: test/CodeGen/X86/statepoint-stackmap-format.ll

Should it be fixed?

I also did not seem to find any test case with xxx-win32-coff combination.

david-xl avatar Dec 22 '15 01:12 david-xl

Because win64 isn't the name of the MSVC environment.

Sorry I am still confused. Is x86_64-pc-win64-coff a valid triple to use?

"x86_64-pc-win64-coff" is a valid triple in the sense that LLVM should be able to successfully parse it into something but the result will not make sense to LLVM. The "win64" component that you are specifying has no meaning to LLVM.

x86_64-pc-win64-coff: valid. we know what CPU and object file is targeted, we don't know what OS environment "win64" means. x86_64-pc-win32-coff: valid. we know what CPU and object file is targeted and we know we are targeting Windows.

majnemer avatar Dec 22 '15 01:12 majnemer

Because win64 isn't the name of the MSVC environment.

Sorry I am still confused. Is x86_64-pc-win64-coff a valid triple to use?

david-xl avatar Dec 22 '15 01:12 david-xl

Because win64 isn't the name of the MSVC environment.

majnemer avatar Dec 22 '15 01:12 majnemer

Why can't win64 be used?

david-xl avatar Dec 22 '15 01:12 david-xl

StaticCtorSection is created as ELF in

MCObjectFileInfo::InitMCObjectFileInfo because TT.isOSWindows() returns false.

The IL is still legal here, right?

The IR is fine but your triple is wrong. I believe you want x86_64-pc-win32-coff.

majnemer avatar Dec 22 '15 00:12 majnemer

StaticCtorSection is created as ELF in

MCObjectFileInfo::InitMCObjectFileInfo because TT.isOSWindows() returns false.

The IL is still legal here, right?

I think so. The logic in MCObjectFileInfo::InitMCObjectFileInfo to find the object format ta use is really suspicious.

llvmbot avatar Dec 22 '15 00:12 llvmbot

StaticCtorSection is created as ELF in

MCObjectFileInfo::InitMCObjectFileInfo because TT.isOSWindows() returns false.

The IL is still legal here, right?

david-xl avatar Dec 22 '15 00:12 david-xl

StaticCtorSection is created as ELF in

MCObjectFileInfo::InitMCObjectFileInfo because TT.isOSWindows() returns false.

llvmbot avatar Dec 22 '15 00:12 llvmbot