ELF file .text section file offset

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
alexhoppus
Posts: 1
Joined: Sun Mar 19, 2017 1:26 am

ELF file .text section file offset

Post by alexhoppus »

Hey.
I use this https://github.com/alexhoppus/rpios/blo ... r/Makefile Makefile to build this https://github.com/alexhoppus/rpios/blo ... ser/app1.c application with the use of this https://github.com/alexhoppus/rpios/blo ... /linker.ld linker script. After building it turned out that the size of this app is abnormally huge, currently I tested it on Ubuntu 16.04/14.04 and for different versions of arm-none-eabi-* toolchain it gives 70K/35K appropriately. The reason of such a big size of ELF file is that .text section is placed inside ELF file with a big offset:

Code: Select all

user (master) $ arm-linux-gnueabi-readelf --sections app1 | grep .text
  [ 1] .text             PROGBITS        00800000 008000 000078 00  AX  0   0  4
As you can see in this case .text section is located at offset 0x8000 inside ELF file. The space between ELF header and text section is filled with zeros.

Code: Select all

user (master) $ hexdump -C ./app1 | less

Code: Select all

00000000  7f 45 4c 46 01 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 28 00 01 00 00 00  00 00 80 00 34 00 00 00  |..(.........4...|
00000020  5c 81 00 00 02 02 00 05  34 00 20 00 01 00 28 00  |\.......4. ...(.|
00000030  09 00 06 00 01 00 00 00  00 80 00 00 00 00 80 00  |................|
00000040  00 00 80 00 b8 00 00 00  b8 00 00 00 05 00 00 00  |................|
00000050  00 80 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00008000  00 00 a0 e3 00 10 a0 e3  1a 00 00 ea 04 40 2d e5  |.............@-.|
00008010  03 40 a0 e1 02 30 a0 e1  01 20 a0 e1 00 10 a0 e1  |[email protected]... ......|
00008020  01 00 a0 e3 00 00 00 ef  04 40 9d e4 1e ff 2f e1  |.........@..../.|
00008030  04 40 2d e5 03 40 a0 e1  02 30 a0 e1 01 20 a0 e1  |.@[email protected]... ..|
I use this application from inside of my self-written OS and this app is linked as a data blob with the kernel image. The kernel is loaded using UART bootloader that's why the final image size is critical. Also as you have guessed i use ELF loader for apps so preserving ELF format is important for me. The question is - why this text section offset is so huge, what is the reason for this? And how can i control it?
Actually, i have found the similar question on SO, but it is unanswered http://stackoverflow.com/questions/2683 ... in-linking
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: ELF file .text section file offset

Post by alexfru »

I have not tried these, but there seem to be a few clues: If you're really concerned about the size, then either you should use a different format or simply compress the file.
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Re: ELF file .text section file offset

Post by lkurusa »

What is in your ".text.boot" section?
Cheers,

Lev
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: ELF file .text section file offset

Post by zaval »

show your readelf -l output
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: ELF file .text section file offset

Post by bzt »

I had the same issue. It's --nmagic you need. The GNU linker documentation does not mention it, but it also sets alignment.
Post Reply