Arm Community
Arm Community
  • Site
  • User
  • Site
  • Search
  • User
  • Groups
    • Arm Research
    • DesignStart
    • Education Hub
    • Graphics and Gaming
    • High Performance Computing
    • Innovation
    • Multimedia
    • Open Source Software and Platforms
    • Physical
    • Processors
    • Security
    • System
    • Software Tools
    • TrustZone for Armv8-M
    • 中文社区
  • Blog
    • Artificial Intelligence
    • Automotive
    • Healthcare
    • HPC
    • Infrastructure
    • Innovation
    • Internet of Things
    • Machine Learning
    • Mobile
    • Smart Homes
    • Wearables
  • Forums
    • All developer forums
    • IP Product forums
    • Tool & Software forums
    • Pelion IoT Platform
  • Activity
  • Support
    • Open a support case
    • Documentation
    • Downloads
    • Training
    • Arm Approved program
    • Arm Design Reviews
  • More
  • Cancel
Processors
  • Developer Community
  • IP Products
  • Processors
  • Jump...
  • Cancel
Processors
Processors blog File not found when executing assembled program
  • Blogs
  • Leaderboard
  • Forums
  • Videos & Files
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
  • New
More blogs in Processors
  • DesignStart blog

  • Machine Learning IP blog

  • Processors blog

  • TrustZone for Armv8-M blog

Tell us what you think
Tags
  • not_found
  • Assembly
  • Android
  • linker
  • elf
  • execve
  • problem
  • linking
  • Linux
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

File not found when executing assembled program

Myy
Myy
November 29, 2016

The main problem

When assembling your first programs with AS, and linking it to external libraries like this :

armv7a-hardfloat-linux-gnueabi-as -o test.o test.S

armv7a-hardfloat-linux-gnueabi-ld.gold --hash-style=sysv -o test test.o -lc

You might be confronted to this error when executing your program :

$ ./test

-bash: ./test: No such file or directory

Using strace to pinpoint the problem will result to something like this :

execve("./test", ["./test"], [/* 28 vars */]) = -1 ENOENT (No such file or directory)

write(2, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory

) = 40

exit_group(1)                           = ?

+++ exited with 1 +++

Looking at execve manual page, ENOENT is described like this :

ENOENT The file filename or a script or ELF interpreter does not exist, or a shared library needed for the file or interpreter cannot be found.

The executable is not a script. The file clearly exists. However, the ELF interpreter ?

When running readelf -l elf_executable you can see which interpreter the executable tries to use. In this case, the output is :

Elf file type is EXEC (Executable file)

Entry point 0x81b8

There are 5 program headers, starting at offset 52

Program Headers:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align

  PHDR           0x000034 0x00008034 0x00008034 0x000a0 0x000a0 R   0x4

  INTERP         0x0000d4 0x000080d4 0x000080d4 0x00013 0x00013 R   0x1

      [Requesting program interpreter: /usr/lib/libc.so.1]

  LOAD           0x000000 0x00008000 0x00008000 0x00208 0x00208 R E 0x1000

  LOAD           0x000208 0x00009208 0x00009208 0x000cc 0x000cc RW  0x1000

  DYNAMIC        0x000208 0x00009208 0x00009208 0x000a0 0x000a0 RW  0x4

Section to Segment mapping:

  Segment Sections...

   00    

   01     .interp

   02     .interp .dynsym .dynstr .hash .gnu.version .gnu.version_r .rel.plt .plt .text

   03     .dynamic .data .got

   04     .dynamic

The line Requesting program interpreter shows which ELF interpreter the system tries to use. On this system /usr/lib/libc.so.1 does not exist, which is why executing the program returns "File not found".

However, on a Linux system for example, the standard ELF interpreter is not libc but ld.

The solution

Define the system dynamic linker as the ELF interpreter using the --dynamic-linker directive when linking the program.

When linking programs for Linux ARM systems :

armv7a-hardfloat-linux-gnueabi-ld.gold --hash-style=sysv --dynamic-linker=/lib/ld-linux-armhf.so.3 -o test test.o -lc

When linking programs for Android ARM systems :

armv7a-hardfloat-linux-gnueabi-ld.gold --hash-style=sysv --dynamic-linker=/system/bin/linker -o test test.o -lc

Anonymous
Parents
  • Myy
    Offline Myy over 2 years ago

    I just encountered the same issue while trying to cross-compile a C program from a system using GlibC and execute it on a system using Musl.

    Musl dynamic  linker is located at : /lib/ld-musl-armhf.so.1 on ARMv7 with Hardware FPU.

    So you'll have to pass -Wl,--dynamic-linker=/lib/ld-musl-armhf.so.1 to GCC, when linking an executable, to be able to execute the program correctly on the Musl system.

    Example :

    arm-linux-gnueabihf-gcc -o test test.c -Wl,--dynamic-linker=/lib/ld-musl-armhf.so.1

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Comment
  • Myy
    Offline Myy over 2 years ago

    I just encountered the same issue while trying to cross-compile a C program from a system using GlibC and execute it on a system using Musl.

    Musl dynamic  linker is located at : /lib/ld-musl-armhf.so.1 on ARMv7 with Hardware FPU.

    So you'll have to pass -Wl,--dynamic-linker=/lib/ld-musl-armhf.so.1 to GCC, when linking an executable, to be able to execute the program correctly on the Musl system.

    Example :

    arm-linux-gnueabihf-gcc -o test test.c -Wl,--dynamic-linker=/lib/ld-musl-armhf.so.1

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Children
No Data
Processors blog
  • Processors blog: How to generate litmus tests automatically with the diy7 tool

    Jade Alglave
    Jade Alglave
    The second tutorial on using the Memory Model Tool, this blog offers a working example of how to generate litmus tests automatically with the diy7 tool.
    • June 11, 2020
  • Processors blog: Introducing the Arm Cortex-X Custom Program

    Stefan Rosinger
    Stefan Rosinger
    Read this introduction to the Arm Cortex-X Custom Program, outlining what the new program entails and providing details about the new Arm Cortex-X1 CPU which is part of the program.
    • May 26, 2020
  • Processors blog: Arm Cortex-A78 CPU: Sustained Performance for Greater Digital Immersion

    Vincent Risson
    Vincent Risson
    This blog explores the key features and benefits of the Arm Cortex-A78 CPU.
    • May 26, 2020