Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in MSP430 DAG->DAG Should only be an extending load, not truncating! #86

Open
dmikushin opened this issue Jan 24, 2019 · 4 comments

Comments

@dmikushin
Copy link
Contributor

dmikushin commented Jan 24, 2019

void *alloca(unsigned int size);

short foo(char** data, char encoding)
{
	char* encoding_addr = alloca(sizeof(char));
	*encoding_addr = encoding;

	char tmp3 = *encoding_addr;
	short conv2 = tmp3;
	short and = conv2 & 0xf;

	switch (and)
	{
	case 0 :
	case 4 :
	case 10 :
		return 1;
	case 11 :
		return 2;
	}
}

$ clang -cc1 msp430-reloc.c -S -o -
msp430-reloc.c:25:1: warning: control may reach end of non-void function
}
^
.text
.file "msp430-reloc.c"
clang: /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6425: llvm::SDValue llvm::SelectionDAG::getLoad(llvm::ISD::MemIndexedMode, llvm::ISD::LoadExtType, llvm::EVT, const llvm::SDLoc&, llvm::SDValue, llvm::SDValue, llvm::SDValue, llvm::EVT, llvm::MachineMemOperand*): Assertion `MemVT.getScalarType().bitsLT(VT.getScalarType()) && "Should only be an extending load, not truncating!"' failed.
Stack dump:
0. Program arguments: clang -cc1 -emit-llvm msp430-reloc.c -S -o -

  1. parser at end of file
  2. Code generation
  3. Running pass 'Function Pass Manager' on module 'msp430-reloc.c'.
  4. Running pass 'MSP430 DAG->DAG Pattern Instruction Selection' on function '@foo'
    LLVMSymbolizer: error reading file: No such file or directory
    #0 0x00007fb9e8f5a2d3 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/Support/Unix/Signals.inc:495:0
    Add MC layer #1 0x00007fb9e8f5a366 PrintStackTraceSignalHandler(void*) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/Support/Unix/Signals.inc:559:0
    [MSP430] Improve support for 'interrupt' attribute #2 0x00007fb9e8f5808c llvm::sys::RunSignalHandlers() /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/Support/Signals.cpp:67:0
    SelectionDAG fails on assertion #3 0x00007fb9e8f59cf5 SignalHandler(int) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/Support/Unix/Signals.inc:358:0
    Use rrcl node instead of clrc+rrc #4 0x00007fb9e50d5f20 (/lib/x86_64-linux-gnu/libc.so.6+0x3ef20)
    Add MSP430 toolchain #5 0x00007fb9e50d5e97 gsignal /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
    LLD fails on TI provided ld scripts #6 0x00007fb9e50d7801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
    [MCLayer] Add remaining instruction forms #7 0x00007fb9e50c739a __assert_fail_base /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
    [WIP] Fixes for LLD #8 0x00007fb9e50c7412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
    Impossible reg-to-reg copy #9 0x00007fb9e44c39d5 llvm::SelectionDAG::getLoad(llvm::ISD::MemIndexedMode, llvm::ISD::LoadExtType, llvm::EVT, llvm::SDLoc const&, llvm::SDValue, llvm::SDValue, llvm::SDValue, llvm::EVT, llvm::MachineMemOperand*) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6424:0
    Error in backend: Cannot select RRCL #10 0x00007fb9e44c387f llvm::SelectionDAG::getLoad(llvm::ISD::MemIndexedMode, llvm::ISD::LoadExtType, llvm::EVT, llvm::SDLoc const&, llvm::SDValue, llvm::SDValue, llvm::SDValue, llvm::MachinePointerInfo, llvm::EVT, unsigned int, llvm::MachineMemOperand::Flags, llvm::AAMDNodes const&, llvm::MDNode const*) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6411:0
    Enable newlib building #11 0x00007fb9e44c41ea llvm::SelectionDAG::getExtLoad(llvm::ISD::LoadExtType, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::MachinePointerInfo, llvm::EVT, unsigned int, llvm::MachineMemOperand::Flags, llvm::AAMDNodes const&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6488:0
    Enable RIOT building #12 0x00007fb9e43655fb (anonymous namespace)::SelectionDAGLegalize::ExpandNode(llvm::SDNode*) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:3496:0
    Fix writeback register size for 8rp i-forms #13 0x00007fb9e4351717 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1226:0
    Add rrcl8 pseudo #14 0x00007fb9e436d9d0 llvm::SelectionDAG::Legalize() /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:4599:0
    Add __builtin_flt_rounds #15 0x00007fb9e44fe0c0 llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:863:0
    Prologue/epilogue optimization #16 0x00007fb9e4504667 llvm::SelectionDAGISel::FinishBasicBlock() /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:2082:0
    Disassembler failure #17 0x00007fb9e4503048 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1796:0
    EABI requires to pass structurs larger than 32 bits by reference #18 0x00007fb9e44fb738 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:472:0
    Fix disassembler; add bit[rm]c instructions #19 0x00007fb9ecf49715 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/CodeGen/MachineFunctionPass.cpp:74:0
    Omit frame pointer by default #20 0x00007fb9ec20feb4 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/IR/LegacyPassManager.cpp:1644:0
    Inline asm register names #21 0x00007fb9ec21012b llvm::FPPassManager::runOnModule(llvm::Module&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/IR/LegacyPassManager.cpp:1679:0
    [RIOT] Non-asm stmt in naked function #22 0x00007fb9ec21052c (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/IR/LegacyPassManager.cpp:1744:0
    Relocation Types defined by EABI are different from clang supported #23 0x00007fb9ec210d4f llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/IR/LegacyPassManager.cpp:1857:0
    Aligment for i32, i64, f32, f64 is more than EABI states #24 0x00007fb9ec210f7f llvm::legacy::PassManager::run(llvm::Module&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/lib/IR/LegacyPassManager.cpp:1889:0
    [MSP430] Add more tests for calling convention and ABI #25 0x00007fb9e69b6774 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream >) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:871:0
    [MSP430] Fix i64, f32 and f64 alignment #26 0x00007fb9e69b9af8 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream >) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:1300:0
    Possible optimization for unaligned load/store #27 0x00007fb9e6df3b01 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:293:0
    [#18] Align byval lowering with MSP430 EABI #28 0x00007fb9ded801e6 clang::ParseAST(clang::Sema&, bool, bool) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/Parse/ParseAST.cpp:177:0
    .refsym directive is not supported #29 0x00007fb9e5e03fc7 clang::ASTFrontendAction::ExecuteAction() /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:1018:0
    @Rn is not supported as destination #30 0x00007fb9e6df04b8 clang::CodeGenAction::ExecuteAction() /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1045:0
    .weak directive is ignored #31 0x00007fb9e5e039b8 clang::FrontendAction::Execute() /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:921:0
    lld produces broken elf #32 0x00007fb9e5d79600 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:969:0
    [MSP430] Emulate [at]rd in destination position as 0(rd) #33 0x00007fb9e586080e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/marcusmae/acctek/msp430-clang-newlib/msp430-clang/src/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:267:0
    [MSP430] Add support for .refsym directive #34 0x0000562603396d60 (clang+0x4ad60)
    undefined symbol: __lshrsi3 #35 0x000056260338bf93 (clang+0x3ff93)
    Wrong relocation type #36 0x000056260338cc75 (clang+0x40c75)
    lld is not able to link with libgcc (relaxation is not supported) #37 0x00007fb9e50b8b97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
    [MSP430] Add RTLIB::[SRL/SRA/SHL]_I32 lowering to EABI lib calls #38 0x000056260338997a (clang+0x3d97a)
    Aborted (core dumped)
@chbessonova
Copy link
Contributor

It has the same root cause as #72.
Without driver (in the case when cc1 running) frontend assumes RelocationModel = PIC by default.

@dmikushin
Copy link
Contributor Author

dmikushin commented Jan 26, 2019 via email

@chbessonova
Copy link
Contributor

@dmikushin The patch disables PIC/PIE in the driver. The driver doesn't start when cc1 is calling, so, driver configuration has no effect.
clang msp430-reloc.c -S -o - (cc1 is removed from command line) should finish successfully.
I didn't find how to force RelocationModel = Static in the frontend, so it seems we should manually specify -mrelocation-model=static calling cc1, but may be @asl can suggest some better solution.

@dmikushin
Copy link
Contributor Author

dmikushin commented Jan 26, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants