Skip to contentSkip to conversation

RPi app built with SDK won't load

DISCUSSION Paul D. DeRocco 3 participants 5 messages Jun 29, 2017 – Jul 6, 2017 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

I posted about this a week or so ago, but have narrowed things down further.

I built a 32-bit non-GUI RPi image which works, built the corresponding SDK, and used the SDK's toolchain to build an empty C program (just "return 0;" inside main). When I run it on the target, the shell complains:

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

If I run "ldd test", it dies with the same error, without even getting far enough to trace the search for libc, the only referenced library. (Yes, the x attribute is set.)

On my host system, I ran arm-poky-linux-objdump -x on the test program, and then ran it on the version of chmod.coreutils from the rootfs of the build (because it was the smallest executable in /bin). The only differences were that chmod referenced a couple more libraries, the section addresses and sizes were of course different, test had a small .comment section listing the compiler used, and chmod had a .gnu_debuglink section. All attributes were the same, even the contents of the .ARM.attributes section.

Yet despite this, chmod runs fine, but test doesn't.

What else could possibly return an ENOENT error code to the shell so early in the load process?

Signature · 2 lines
Ciao,               Paul D. DeRocco
Paul                mailto:[email protected]

A message that is not in the archive (sent off-list or not yet received): CAC+thW12U7RCZsSS7tuSVWis+bycbDo6t-oFiOpePoQ9nJ3qSA@mail.gmail.com

#2 lore raw
Quoted 7 lines

From: Andrea Galbusera [mailto:[email protected]]

Could you please post the exact source code of your test program and the steps you take to (a) build the SDK and (b) build your test executable? Is your running image a pretty standard one (core-image-minimal, rpi-test-image or so) or do your own with custom features?

It did have some custom features, so I did a plain build of core-image-minimal using raspberrypi3 as the MACHINE. I also did a populate_sdk for it, and installed the SDK in /opt/poky/2.2.1-a32 by running the install script.

The test program test.c is just "int main(void) { return 0; }". I normally use Eclipse CDT to compile native programs, so I set up a cross project using the SDK, which involves a few manual settings, including telling it the tools are in /opt/poky/2.2.1-a32/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux, and adding a --sysroot to the command lines. The compiler command line came out as:

arm-poky-linux-gcc --sysroot=/opt/poky/2.2.1-a32/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi -O3 -Wall -c -mfloat-abi=hard -MMD -MP -MF"test.d" -MT"test.o" -o "test.o" "../test.c"

(without the line breaks). I had to add "-mfloat-abi-hard" to get it to link. The link command line was:

arm-poky-linux-gcc --sysroot=/opt/poky/2.2.1-a32/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi -s -o "test" ./test.o

(again, without the line breaks). After dd-ing the image to my SD card, I mounted it and manually copied the "test" program into its rootfs. When I stuck it in the RPi3 and ran it, I got

-sh: ./test: not found

The shell in this case is busybox, so the error message is slightly different from bash.

I rechecked everything I had described before, analyzing the executable and comparing it to some working executable from the rootfs. There must be SOMETHING in my executable that the loader is barfing on, after it's successfully opened the file but before it starts looking for libraries. But it's an awfully small executable, so it's hard to imaging where that something is hiding.

Signature · 2 lines
Ciao,               Paul D. DeRocco
Paul                mailto:[email protected]
#3 lore raw

Did you try compiling in text mode?

$  $CC -o test test.c
Signature · 6 lines
Pierre FICHEUX -/- CTO Smile-ECS, France -\- [email protected]
                                    http://www.smile.fr
                                    http://ingenierie.openwide.fr
I would love to change the world, but they won't give me the source code

Le 2017-07-02 03:07, Paul D. DeRocco a écrit :
Quoted 53 lines
Quoted 7 lines

From: Andrea Galbusera [mailto:[email protected]]

Could you please post the exact source code of your test program and the steps you take to (a) build the SDK and (b) build your test executable? Is your running image a pretty standard one (core-image-minimal, rpi-test-image or so) or do your own with custom features?

It did have some custom features, so I did a plain build of core-image-minimal using raspberrypi3 as the MACHINE. I also did a populate_sdk for it, and installed the SDK in /opt/poky/2.2.1-a32 by running the install script.

The test program test.c is just "int main(void) { return 0; }". I normally use Eclipse CDT to compile native programs, so I set up a cross project using the SDK, which involves a few manual settings, including telling it the tools are in /opt/poky/2.2.1-a32/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux, and adding a --sysroot to the command lines. The compiler command line came out as:

arm-poky-linux-gcc --sysroot=/opt/poky/2.2.1-a32/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi -O3 -Wall -c -mfloat-abi=hard -MMD -MP -MF"test.d" -MT"test.o" -o "test.o" "../test.c"

(without the line breaks). I had to add "-mfloat-abi-hard" to get it to link. The link command line was:

arm-poky-linux-gcc --sysroot=/opt/poky/2.2.1-a32/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi -s -o "test" ./test.o

(again, without the line breaks). After dd-ing the image to my SD card, I mounted it and manually copied the "test" program into its rootfs. When I stuck it in the RPi3 and ran it, I got

-sh: ./test: not found

The shell in this case is busybox, so the error message is slightly different from bash.

I rechecked everything I had described before, analyzing the executable and comparing it to some working executable from the rootfs. There must be SOMETHING in my executable that the loader is barfing on, after it's successfully opened the file but before it starts looking for libraries. But it's an awfully small executable, so it's hard to imaging where that something is hiding.

--

Ciao, Paul D. DeRocco
Paul mailto:[email protected]

#4 lore raw
In reply to Paul D. DeRocco
Quoted 14 lines · Paul D. DeRocco
Quoted 7 lines

From: Andrea Galbusera [mailto:[email protected]]

Could you please post the exact source code of your test program and the steps you take to (a) build the SDK and (b) build your test executable? Is your running image a pretty standard one (core-image-minimal, rpi-test-image or so) or do your own with custom features?

It did have some custom features, so I did a plain build of core-image-minimal using raspberrypi3 as the MACHINE. I also did a populate_sdk for it, and installed the SDK in /opt/poky/2.2.1-a32 by running the install script.

The test program test.c is just "int main(void) { return 0; }". I normally use Eclipse CDT to compile native programs, so I set up a cross project using the SDK, which involves a few manual settings, including telling it the tools are in /opt/poky/2.2.1-a32/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux, and adding a --sysroot to the command lines. The compiler command line came out as:

arm-poky-linux-gcc --sysroot=/opt/poky/2.2.1-a32/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi -O3 -Wall -c -mfloat-abi=hard -MMD -MP -MF"test.d" -MT"test.o" -o "test.o" "../test.c"

Quoted 8 lines

(without the line breaks). I had to add "-mfloat-abi-hard" to get it to link. The link command line was:

arm-poky-linux-gcc --sysroot=/opt/poky/2.2.1-a32/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi -s -o "test" ./test.o

(again, without the line breaks). After dd-ing the image to my SD card, I mounted it and manually copied the "test" program into its rootfs. When I stuck it in the RPi3 and ran it, I got

-sh: ./test: not found

pick a program that runs fine on target say /sbin/init and your test program then find the unstripped binaries of both on your build system. run

arm-poky-linux-gcc -A init and
arm-poky-linux-gcc -A test

send the output of both cmds.

Quoted 14 lines

The shell in this case is busybox, so the error message is slightly different from bash.

I rechecked everything I had described before, analyzing the executable and comparing it to some working executable from the rootfs. There must be SOMETHING in my executable that the loader is barfing on, after it's successfully opened the file but before it starts looking for libraries. But it's an awfully small executable, so it's hard to imaging where that something is hiding.

--

Ciao, Paul D. DeRocco
Paul mailto:[email protected]

--
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto

A message that is not in the archive (sent off-list or not yet received): CAFfxioxyEy1iWzktbKT6hBnq+AA6kS=g8srE-fLyWEJq1c=V0Q@mail.gmail.com

#6 lore raw

I incorporated all the relevant symbols from environment-setup-cortexa7hf-neon-vfpv4-poky-linux-gnueabi. I defined the compilation command as ${CC} ${CFLAGS} and the linker command as ${LD} ${LDFLAGS}. Other Eclipse settings added -O3 -Wall -c to the compile, and -s to the link.

When I did the build, the compile succeeded, but the link complained about "-Wl,-O1" as an unrecognized option. I first tried eliminating the "-Wl," prefixes, but that gave me a "cannot find entry symbol _start" error. I put the "-Wl," prefixes back, but changed the link command from arm-poky-linux-gnueabi-ld to arm-poky-linux-gnueabi-gcc, and it linked okay, but gave me the same runtime error I've been struggling with.

However, Lukasz put his finger on the problem when he wrote

Quoted 5 lines

From: Lukasz Tekieli [mailto:[email protected]]

it seems that if linker is called without -mfloat-abi=hard then the ld is set to /lib/ld-linux.so.3 instead of /lib/ld-linux-armhf.so.3 which is the correct one.

It turns out the correct way to run the linker is $CC $CFLAGS $LDFLAGS, not $LD $LDFLAGS.

The reason this escaped me for all this time is that I was using arm-poky-linux-gnueabi-objdump -x on the executable, and grepping for NEEDED to find out what shared libraries were needed. The actual loader isn't listed in this way. Using the -s option showed that the .interp section contained the string /lib/ld-linux.so.3. Now it correctly shows /lib/ld-linux-armhf.so.3.

Thanks to all who looked into this for me.

Signature · 2 lines
Ciao,               Paul D. DeRocco
Paul                mailto:[email protected]