Discussion:
ELF file OS ABI invalid
chzong
2014-09-29 09:00:37 UTC
Permalink
Hi,
I met a problem when I used luajit make a lua file to a object file.
I use the command "luajit -b -a arm scimark.lua scimark.o" make an object file for an arm target board.
And this object file will be linked with other object file compiled by arm gnu tool chain form c source file.
In the C file ,it can not requre " scimark" for can not find the file "scimark.lua" or "scimark.so"
Then I compile the scimark.o to a scimark.so file .
When execute a binary file compiled from C source file and it require "scimark" on the target board, I met the error
"ELF file OS ABI invalid"
Our target board ,there is a cortex-a9 dual core arm cpu. Is this problem due to our cpu architecture ?


Best Regards
Cheng
Mike Pall
2014-09-29 09:36:01 UTC
Permalink
Post by chzong
Then I compile the scimark.o to a scimark.so file .
When execute a binary file compiled from C source file and it require "scimark" on the target board, I met the error
"ELF file OS ABI invalid"
To translate from .o to .so you need to use the exact same
toolchain and linker options used to build your target
environment binaries.

I suggest you inspect a working binary for the target (executable
or shared library) and compare with the .so that doesn't work. The
best tool for that is readelf -hA.

Compare the output, looking at the flags, versions and attributes.
If there's a difference in the aeabi attribute section, then it's
very likely due to the options used to create the .so from the .o.

--Mike
chzong
2014-09-30 01:45:20 UTC
Permalink
Hi, Mike
I used the readelf -hA tool to check the working binary ,.so and .o
The .o and .so looks the same but the binary not.
This is the information of the .o file:

ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 52 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 6
Section header string table index: 2


This is the .so elf information.


ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x1f8
Start of program headers: 52 (bytes into file)
Start of section headers: 6056 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 4
Size of section headers: 40 (bytes)
Number of section headers: 10
Section header string table index: 7


The binary has more information ,it has more flags and attributes.
I think the .o compiled by command "luajit -b -a arm" without the flags and attributes will not work on my target board.
How can I make the .o with the flags and attributes ?

ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x8a51
Start of program headers: 52 (bytes into file)
Start of section headers: 10000 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 38
Section header string table index: 35
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7
Tag_CPU_arch_profile: Application
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-2
Tag_VFP_arch: VFPv3
Tag_Advanced_SIMD_arch: NEONv1
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_rounding: Needed
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align8_needed: Yes
Tag_ABI_align8_preserved: Yes, except leaf SP
Tag_ABI_enum_size: int
Tag_ABI_HardFP_use: SP and DP
Tag_CPU_unaligned_access: v6
Post by Mike Pall
Post by chzong
Then I compile the scimark.o to a scimark.so file .
When execute a binary file compiled from C source file and it require "scimark" on the target board, I met the error
"ELF file OS ABI invalid"
To translate from .o to .so you need to use the exact same
toolchain and linker options used to build your target
environment binaries.
I suggest you inspect a working binary for the target (executable
or shared library) and compare with the .so that doesn't work. The
best tool for that is readelf -hA.
Compare the output, looking at the flags, versions and attributes.
If there's a difference in the aeabi attribute section, then it's
very likely due to the options used to create the .so from the .o.
--Mike
Mike Pall
2014-09-30 12:18:21 UTC
Permalink
Post by chzong
The binary has more information ,it has more flags and attributes.
I think the .o compiled by command "luajit -b -a arm" without the flags and attributes will not work on my target board.
How can I make the .o with the flags and attributes ?
No, the .o is fine. You need to fix how you translate from the .o
to the .so.

--Mike
chzong
2014-10-10 08:45:03 UTC
Permalink
Hi Mike,


Thanks for your help.
I have solved the problem.
Just as you said , the .so file was bad .
It is very strange When I using ld to translate the .o to the .so, I should never place the .o compile by luajit in the front of other .o . Otherwise the "OS/ABI" field of ELF header
will be changed to "ARM". The correct value is "UNIX - System V".
This is my link command below: the scimarklib.o is compile by luajit.


/proj/toolchain/armv7a-vfp-neon-wrs-linux/host-cross/usr/toolchain/bin/arm-wrs-linux-gnueabi-ld --sysroot=/proj/toolchain/armv7a-vfp-neon-wrs-linux/sysroots/cortexa9-vfp-neon-wrs-linux-gnueabi -share -fPIC scimarklib.o -L./ -lluajit-5.1 -o scimarklibarm.so




By the way , We plan to use Cortex A57 arm cpu on our board . Will luajit support ARM64 architecture in the next two years?


Thanks again.


Regards


Cheng
Post by Mike Pall
Post by chzong
The binary has more information ,it has more flags and attributes.
I think the .o compiled by command "luajit -b -a arm" without the flags and attributes will not work on my target board.
How can I make the .o with the flags and attributes ?
No, the .o is fine. You need to fix how you translate from the .o
to the .so.
--Mike
Mike Pall
2014-10-10 12:00:10 UTC
Permalink
Post by chzong
Just as you said , the .so file was bad .
It is very strange When I using ld to translate the .o to the .so, I should never place the .o compile by luajit in the front of other .o . Otherwise the "OS/ABI" field of ELF header
will be changed to "ARM". The correct value is "UNIX - System V".
This is my link command below: the scimarklib.o is compile by luajit.
/proj/toolchain/armv7a-vfp-neon-wrs-linux/host-cross/usr/toolchain/bin/arm-wrs-linux-gnueabi-ld --sysroot=/proj/toolchain/armv7a-vfp-neon-wrs-linux/sysroots/cortexa9-vfp-neon-wrs-linux-gnueabi -share -fPIC scimarklib.o -L./ -lluajit-5.1 -o scimarklibarm.so
Nowadaye, one should never use ld directly. Always use the
compiler frontend, i.e. the cross-gcc in your case. This usually
ensures that this doesn't happen (by adding a preamble .o).
Post by chzong
By the way , We plan to use Cortex A57 arm cpu on our board .
Will luajit support ARM64 architecture in the next two years?
Anybody is welcome to contribute an ARM64 port.

--Mike

Loading...