Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR35482
Status NEW
Importance P enhancement
Reported by dmajor (dmajor@bugmail.cc)
Reported on 2017-11-30 11:27:03 -0800
Last modified on 2019-09-09 08:10:21 -0700
Version unspecified
Hardware PC Windows NT
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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
#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
#3 0x0166af4c `anonymous namespace'::AsmParser::parseStatement
e:\source\llvm\lib\mc\mcparser\asmparser.cpp:1886:0
#4 0x016575f6 `anonymous namespace'::AsmParser::Run
e:\source\llvm\lib\mc\mcparser\asmparser.cpp:892:0
#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
#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
#7 0x030adc3d llvm::ModuleSummaryIndexWrapperPass::runOnModule(class
llvm::Module &) e:\source\llvm\lib\analysis\modulesummaryanalysis.cpp:572:0
#8 0x0141b38f `anonymous namespace'::MPPassManager::runOnModule
e:\source\llvm\lib\ir\legacypassmanager.cpp:1591:0
#9 0x0141ac98 llvm::legacy::PassManagerImpl::run(class llvm::Module &)
e:\source\llvm\lib\ir\legacypassmanager.cpp:1695:0
#10 0x019e3ee7 `anonymous namespace'::EmitAssemblyHelper::EmitAssembly
e:\source\llvm\tools\clang\lib\codegen\backendutil.cpp:790:0
#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
#12 0x031e62b9 clang::BackendConsumer::HandleTranslationUnit(class
clang::ASTContext &)
e:\source\llvm\tools\clang\lib\codegen\codegenaction.cpp:292:0
#13 0x0241fefb clang::ParseAST(class clang::Sema &,bool,bool)
e:\source\llvm\tools\clang\lib\parse\parseast.cpp:162:0
#14 0x01d1367f clang::ASTFrontendAction::ExecuteAction(void)
e:\source\llvm\tools\clang\lib\frontend\frontendaction.cpp:998:0
#15 0x01d1356f clang::FrontendAction::Execute(void)
e:\source\llvm\tools\clang\lib\frontend\frontendaction.cpp:901:0
#16 0x01ce4e9c clang::CompilerInstance::ExecuteAction(class
clang::FrontendAction &)
e:\source\llvm\tools\clang\lib\frontend\compilerinstance.cpp:992:0
#17 0x01d856b1 clang::ExecuteCompilerInvocation(class clang::CompilerInstance
*)
e:\source\llvm\tools\clang\lib\frontendtool\executecompilerinvocation.cpp:252:0
#18 0x00ead6c2 cc1_main(class llvm::ArrayRef<char const *>,char const *,void *)
e:\source\llvm\tools\clang\tools\driver\cc1_main.cpp:221:0
#19 0x00ea84d7 ExecuteCC1Tool
e:\source\llvm\tools\clang\tools\driver\driver.cpp:309:0
#20 0x00eaac0e main e:\source\llvm\tools\clang\tools\driver\driver.cpp:388:0
#21 0x030590a3 _scrt_common_main_seh
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253:0
#22 0x74e68654 BaseThreadInitThunk (C:\WINDOWS\System32\KERNEL32.DLL+0x18654)
#23 0x77d14a47 __RtlUserThreadStart (C:\WINDOWS\SYSTEM32\ntdll.dll+0x64a47)
#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)
Quuxplusone 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.