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

arm: Using =const syntax crashes llvm #51

Open
stuxnot opened this issue May 6, 2024 · 1 comment
Open

arm: Using =const syntax crashes llvm #51

stuxnot opened this issue May 6, 2024 · 1 comment
Assignees

Comments

@stuxnot
Copy link
Collaborator

stuxnot commented May 6, 2024

Trying to assemble ldr r0, =0xfefaff leads to a SEGFAULT in LLVM.
Reproduce with ./nyxstone --arch armv8m -A ldr r0, =0xfefaff. Stack trace:

==48173==The signal is caused by a READ memory access.
==48173==Hint: address points to the zero page.
    #0 0x64b7826a51f6 in llvm::ARMTargetStreamer::addConstantPoolEntry(llvm::MCExpr const*, llvm::SMLoc) (/home/stuxnot/nyxstone/build/nyxstone+0xc5a1f6) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #1 0x64b78261d009 in (anonymous namespace)::ARMAsmParser::processInstruction(llvm::MCInst&, llvm::SmallVectorImpl<std::unique_ptr<llvm::MCParsedAsmOperand, std::default_delete<llvm::MCParsedAsmOperand> > > const&, llvm::MCStreamer&) (/home/stuxnot/nyxstone/build/nyxstone+0xbd2009) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #2 0x64b782601203 in (anonymous namespace)::ARMAsmParser::MatchAndEmitInstruction(llvm::SMLoc, unsigned int&, llvm::SmallVectorImpl<std::unique_ptr<llvm::MCParsedAsmOperand, std::default_delete<llvm::MCParsedAsmOperand> > >&, llvm::MCStreamer&, unsigned long&, bool) (/home/stuxnot/nyxstone/build/nyxstone+0xbb6203) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #3 0x64b78367abda in (anonymous namespace)::AsmParser::parseAndMatchAndEmitTargetInstruction((anonymous namespace)::ParseStatementInfo&, llvm::StringRef, llvm::AsmToken, llvm::SMLoc) (/home/stuxnot/nyxstone/build/nyxstone+0x1c2fbda) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #4 0x64b78366dd7f in (anonymous namespace)::AsmParser::parseStatement((anonymous namespace)::ParseStatementInfo&, llvm::MCAsmParserSemaCallback*) (/home/stuxnot/nyxstone/build/nyxstone+0x1c22d7f) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #5 0x64b78366723c in (anonymous namespace)::AsmParser::Run(bool, bool) (/home/stuxnot/nyxstone/build/nyxstone+0x1c1c23c) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #6 0x64b781fb5f8a in nyxstone::Nyxstone::assemble_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, std::vector<nyxstone::Nyxstone::LabelDefinition, std::allocator<nyxstone::Nyxstone::LabelDefinition> > const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<nyxstone::Nyxstone::Instruction, std::allocator<nyxstone::Nyxstone::Instruction> >*) const (/home/stuxnot/nyxstone/build/nyxstone+0x56af8a) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #7 0x64b781faf112 in nyxstone::Nyxstone::assemble_to_instructions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, std::vector<nyxstone::Nyxstone::LabelDefinition, std::allocator<nyxstone::Nyxstone::LabelDefinition> > const&) const (/home/stuxnot/nyxstone/build/nyxstone+0x564112) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #8 0x64b781f3f85d in main (/home/stuxnot/nyxstone/build/nyxstone+0x4f485d) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)
    #9 0x759926c41d49  (/usr/lib/libc.so.6+0x25d49) (BuildId: 915eeec6439cfded1125deefc44a8d73e57873d9)
    #10 0x759926c41e0b in __libc_start_main (/usr/lib/libc.so.6+0x25e0b) (BuildId: 915eeec6439cfded1125deefc44a8d73e57873d9)
    #11 0x64b781f3c614 in _start (/home/stuxnot/nyxstone/build/nyxstone+0x4f1614) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/stuxnot/nyxstone/build/nyxstone+0xc5a1f6) (BuildId: 95b68f8e1575f8feb3ea63dd5c274ff0124ca25b) in llvm::ARMTargetStreamer::addConstantPoolEntry(llvm::MCExpr const*, llvm::SMLoc)
@stuxnot stuxnot self-assigned this May 10, 2024
@stuxnot
Copy link
Collaborator Author

stuxnot commented May 10, 2024

A simple first fix should be to filter for =const in arm assembly and return a custom error. Trying to emit constants like ldrb r0, .label; .label: .byte 0xff is currently not supported by nyxstone anyway.

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

1 participant