[llvm-bugs] [Bug 51504] New: Inline asm causes lld to crash

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 17 05:04:25 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51504

            Bug ID: 51504
           Summary: Inline asm causes lld to crash
           Product: lld
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: arslankhan52 at gmail.com
                CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com

Hi,
While compiling a program with inline asm i encountered a missing symbol error.
Here is the code that triggered it: 
    __asm volatile ("ldr r0, =_estack");
    __asm volatile ("mov sp, r0");
    __asm volatile ("bl _reset");
    __asm volatile ("b _start");

Here both _start and _reset were defined in the same file. However, ldd still
complains them as missing symbols. Since, I was using flto, I tried to make it
work by branching to llvm IR name instead changing it to:
    __asm volatile ("ldr r0, =_estack");
    __asm volatile ("mov sp, r0");
    __asm volatile ("bl @_reset");
    __asm volatile ("b @_start");

which led to:

LLVM ERROR: Error parsing inline asm

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace.
Stack dump:

0.      Program arguments: /home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld
-lc -lrdimon -Map=build/output.map build/init/startup.o build/syscall.o
build/main.o
build//home/arslan/projects/LBC/FreeRTOS/FreeRTOS/Source/portable/GCC/ARM_CM3/port.o
build//home/arslan/projects/LBC/FreeRTOS/FreeRTOS/Source/tasks.o
build//home/arslan/projects/LBC/FreeRTOS/FreeRTOS/Source/list.o
build//home/arslan/projects/LBC/FreeRTOS/FreeRTOS/Source/queue.o
build//home/arslan/projects/LBC/FreeRTOS/FreeRTOS/Source/timers.o
build//home/arslan/projects/LBC/FreeRTOS/FreeRTOS/Source/event_groups.o
build//home/arslan/projects/LBC/FreeRTOS/FreeRTOS/Source/portable/MemMang/heap_1.o
build/main_blinky.o -Bstatic
-L/home/arslan/node_modules/llvm-12.0.0.obj/lib/clang/12.0.0/lib/baremetal
-L/home/arslan/node_modules/llvm-12.0.0.obj/bin/../lib/clang-runtimes/arm-none-eabi/lib
-T ./scripts/mps2_m3.ld
-L/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/thumb/v7-m/nofp
-L/usr/lib/gcc/arm-none-eabi/9.2.1
-L/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib -L./ -lc -lm
-lclang_rt.builtins-arm -o build/RTOSDemo.axf
1.      Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2.      Running pass 'ARM Assembly Printer' on function '@Reset_Handler'
 #0 0x000000000087e993 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x87e993)
 #1 0x000000000087c8de llvm::sys::RunSignalHandlers()
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x87c8de)
 #2 0x000000000087f13f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f3367b7e3c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f336742218b raise
/build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f3367401859 abort /build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
 #6 0x000000000083eb89
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x83eb89)
 #7 0x000000000083e9a6
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x83e9a6)
 #8 0x0000000001b53521
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1b53521)
 #9 0x0000000001b54b1e llvm::AsmPrinter::emitInlineAsm(llvm::MachineInstr
const*) const (/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1b54b1e)
#10 0x0000000001b437c2 llvm::AsmPrinter::emitFunctionBody()
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1b437c2)
#11 0x0000000001103bb9
llvm::ARMAsmPrinter::runOnMachineFunction(llvm::MachineFunction&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1103bb9)
#12 0x0000000001f2befe
llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1f2befe)
#13 0x00000000030dfe9d llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x30dfe9d)
#14 0x00000000030e5b73 llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x30e5b73)
#15 0x00000000030e050f llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x30e050f)
#16 0x0000000001e68d3e codegen(llvm::lto::Config const&, llvm::TargetMachine*,
std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>, unsigned
int, llvm::Module&, llvm::ModuleSummaryIndex const&) LTOBackend.cpp:0:0
#17 0x0000000001e6815d llvm::lto::backend(llvm::lto::Config const&,
std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>, unsigned
int, std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >,
llvm::ModuleSummaryIndex&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1e6815d)
#18 0x0000000001e5cd00
llvm::lto::LTO::runRegularLTO(std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1e5cd00)
#19 0x0000000001e5c50f
llvm::lto::LTO::run(std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>,
std::function<std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)> (unsigned
int, llvm::StringRef)>)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x1e5c50f)
#20 0x0000000000a02210 lld::elf::BitcodeCompiler::compile()
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0xa02210)
#21 0x00000000009943d6 void
lld::elf::LinkerDriver::compileBitcodeFiles<llvm::object::ELFType<(llvm::support::endianness)1,
false> >() (/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x9943d6)
#22 0x00000000009880ef void
lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::support::endianness)1,
false> >(llvm::opt::InputArgList&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x9880ef)
#23 0x000000000097d4dd lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char
const*>) (/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x97d4dd)
#24 0x000000000097ae1f lld::elf::link(llvm::ArrayRef<char const*>, bool,
llvm::raw_ostream&, llvm::raw_ostream&)
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x97ae1f)
#25 0x000000000082a9bd lldMain(int, char const**, llvm::raw_ostream&,
llvm::raw_ostream&, bool) lld.cpp:0:0
#26 0x000000000082a260 main
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x82a260)
#27 0x00007f33674030b3 __libc_start_main
/build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:342:3
#28 0x0000000000829f49 _start
(/home/arslan/node_modules/llvm-12.0.0.obj/bin/ld.lld+0x829f49)


I think there are 2 bugs, first the missing symbol issue and secondly this
crash! Please let me know if i can add anything else from my side.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210817/504f8ab8/attachment-0001.html>


More information about the llvm-bugs mailing list