OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Jul 26, 2017 7:02 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: ELF file .text section file offset
PostPosted: Sun Mar 19, 2017 2:00 am 
Offline

Joined: Sun Mar 19, 2017 1:26 am
Posts: 1
Hey.
I use this https://github.com/alexhoppus/rpios/blob/master/user/Makefile Makefile to build this https://github.com/alexhoppus/rpios/blob/master/user/app1.c application with the use of this https://github.com/alexhoppus/rpios/blob/master/user/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:
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:
user (master) $ hexdump -C ./app1 | less

Code:
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  |.@...0... ......|
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  |.@-..@...0... ..|


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/26834470/controlling-file-offset-in-linking


Top
 Profile  
 
 Post subject: Re: ELF file .text section file offset
PostPosted: Sun Mar 19, 2017 2:53 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 787
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.


Top
 Profile  
 
 Post subject: Re: ELF file .text section file offset
PostPosted: Sun Mar 19, 2017 12:35 pm 
Offline

Joined: Sun Jan 15, 2017 5:10 pm
Posts: 7
Location: San Francisco, CA
What is in your ".text.boot" section?

_________________
Levente Kurusa


Top
 Profile  
 
 Post subject: Re: ELF file .text section file offset
PostPosted: Sun Mar 19, 2017 3:40 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 133
Location: Ukraine, Bachmut
show your readelf -l output

_________________
Trying to write an NT-like OS (ANT). First target architecture is mips32r2.
Hopefully this is not only not NSFW, but rather opposite. and feasible as well.


Top
 Profile  
 
 Post subject: Re: ELF file .text section file offset
PostPosted: Tue Mar 21, 2017 1:36 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 124
I had the same issue. It's --nmagic you need. The GNU linker documentation does not mention it, but it also sets alignment.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group