llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.25k stars 12.08k forks source link

ThinLTO doesn't know to use AT&T syntax inline asm #34830

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 35482
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor

Extended Description

clang version 6.0.0 (trunk 318877) Target: i686-pc-windows-msvc

Reduced from xptcstubs.cpp in the Mozilla tree:

$ cat x.cpp
asm(".text\n\t"
    ".align     4\n\t"
    ".globl     \"?Stub0@nsXPTCStubBase@@UAG?AW4nsresult@@XZ\"\n\t"
    ".def       \"?Stub0@nsXPTCStubBase@@UAG?AW4nsresult@@XZ\"; \n\t"
    ".scl       2\n\t"
    ".type      46\n\t"
    ".endef\n\t"
    "\"?Stub0@nsXPTCStubBase@@UAG?AW4nsresult@@XZ\":\n\t"
    "mov $0, %ecx\n\t");

$ clang-cl -c x.cpp && echo works fine
works fine

$ clang-cl -flto=thin -c x.cpp

It hits: void MCStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) { llvm_unreachable("this directive only supported on COFF targets"); }

Presumably because it's an MCStreamer and not a MCWinCOFFStreamer?

#​0 0x016210f0 llvm::MCStreamer::BeginCOFFSymbolDef(class llvm::MCSymbol const *) e:\source\llvm\lib\mc\mcstreamer.cpp:893:0
#​1 0x01679e35 `anonymous namespace'::COFFAsmParser::ParseDirectiveDef e:\source\llvm\lib\mc\mcparser\coffasmparser.cpp:428:0
#&#8203;2 0x01679525 llvm::MCAsmParserExtension::HandleDirective<class `anonymous namespace'::COFFAsmParser,&A0x156022ba::COFFAsmParser::ParseDirectiveDef(class llvm::StringRef,class llvm::SMLoc)>(class llvm::MCAsmParserExtension *,class llvm::StringRef,class llvm::SMLoc) e:\source\llvm\include\llvm\mc\mcparser\mcasmparserextension.h:39:0
#&#8203;3 0x0166af4c `anonymous namespace'::AsmParser::parseStatement e:\source\llvm\lib\mc\mcparser\asmparser.cpp:1886:0
#&#8203;4 0x016575f6 `anonymous namespace'::AsmParser::Run e:\source\llvm\lib\mc\mcparser\asmparser.cpp:892:0
#&#8203;5 0x020a4839 llvm::ModuleSymbolTable::CollectAsmSymbols(class llvm::Module const &,class llvm::function_ref<void (class llvm::StringRef,enum llvm::object::BasicSymbolRef::Flags)>) e:\source\llvm\lib\object\modulesymboltable.cpp:195:0
#&#8203;6 0x030aa6d1 llvm::buildModuleSummaryIndex(class llvm::Module const &,class std::function<class llvm::BlockFrequencyInfo * (class llvm::Function const &)>,class llvm::ProfileSummaryInfo *) e:\source\llvm\lib\analysis\modulesummaryanalysis.cpp:405:0
#&#8203;7 0x030adc3d llvm::ModuleSummaryIndexWrapperPass::runOnModule(class llvm::Module &) e:\source\llvm\lib\analysis\modulesummaryanalysis.cpp:572:0
#&#8203;8 0x0141b38f `anonymous namespace'::MPPassManager::runOnModule e:\source\llvm\lib\ir\legacypassmanager.cpp:1591:0
#&#8203;9 0x0141ac98 llvm::legacy::PassManagerImpl::run(class llvm::Module &) e:\source\llvm\lib\ir\legacypassmanager.cpp:1695:0
#&#8203;10 0x019e3ee7 `anonymous namespace'::EmitAssemblyHelper::EmitAssembly e:\source\llvm\tools\clang\lib\codegen\backendutil.cpp:790:0
#&#8203;11 0x019e510f clang::EmitBackendOutput(class clang::DiagnosticsEngine &,class clang::HeaderSearchOptions const &,class clang::CodeGenOptions const &,class clang::TargetOptions const &,class clang::LangOptions const &,class llvm::DataLayout const &,class llvm::Module *,enum clang::BackendAction,class std::unique_ptr<class llvm::raw_pwrite_stream,struct std::default_delete<class llvm::raw_pwrite_stream> >) e:\source\llvm\tools\clang\lib\codegen\backendutil.cpp:1165:0
#&#8203;12 0x031e62b9 clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &) e:\source\llvm\tools\clang\lib\codegen\codegenaction.cpp:292:0
#&#8203;13 0x0241fefb clang::ParseAST(class clang::Sema &,bool,bool) e:\source\llvm\tools\clang\lib\parse\parseast.cpp:162:0
#&#8203;14 0x01d1367f clang::ASTFrontendAction::ExecuteAction(void) e:\source\llvm\tools\clang\lib\frontend\frontendaction.cpp:998:0
#&#8203;15 0x01d1356f clang::FrontendAction::Execute(void) e:\source\llvm\tools\clang\lib\frontend\frontendaction.cpp:901:0
#&#8203;16 0x01ce4e9c clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) e:\source\llvm\tools\clang\lib\frontend\compilerinstance.cpp:992:0
#&#8203;17 0x01d856b1 clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) e:\source\llvm\tools\clang\lib\frontendtool\executecompilerinvocation.cpp:252:0
#&#8203;18 0x00ead6c2 cc1_main(class llvm::ArrayRef<char const *>,char const *,void *) e:\source\llvm\tools\clang\tools\driver\cc1_main.cpp:221:0
#&#8203;19 0x00ea84d7 ExecuteCC1Tool e:\source\llvm\tools\clang\tools\driver\driver.cpp:309:0
#&#8203;20 0x00eaac0e main e:\source\llvm\tools\clang\tools\driver\driver.cpp:388:0
#&#8203;21 0x030590a3 _scrt_common_main_seh f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253:0
#&#8203;22 0x74e68654 BaseThreadInitThunk (C:\WINDOWS\System32\KERNEL32.DLL+0x18654)
#&#8203;23 0x77d14a47 __RtlUserThreadStart (C:\WINDOWS\SYSTEM32\ntdll.dll+0x64a47)
#&#8203;24 0x77d14a17 _RtlUserThreadStart (C:\WINDOWS\SYSTEM32\ntdll.dll+0x64a17)
clang-cl.exe: error: clang frontend command failed due to signal (use -v to see invocation)
llvmbot commented 5 years ago

FWIW, in clang 9.0.0, this no longer hits an unreachable. Now we have:

$ clang-cl -c x.cpp && echo works fine works fine

$ clang-cl -flto=thin -c x.cpp error: unknown token in expression mov $0, %ecx

presumably due to a misunderstanding about Intel versus AT&T syntax.

If I add an explicit ".att_syntax\n\t" to the repro, then it works.

MaskRay commented 8 months ago

https://reviews.llvm.org/D82862 made AT&T syntax in module-level inline asm work, at the cost of non-working Intel syntax in module-level inline asm (clang -c -flto -masm=intel a.c). The priority is probably low, as most people use AT&T syntax and Intel syntax support has been weak in LLVM.

Furthermore, module-level inline asm statements are concatenated. Using one global setting likely doesn't work with mixed Intel and AT&T syntax. I think fixing this property, which likely requires inteldialect in module asm, has even lower priority.

@zmodem @uweigand @nico