Page 1 of 1

ELF:Linking and zero-filled space that's not a .data section

Posted: Wed May 18, 2011 11:03 pm
by KarimAllah
test.S

Code: Select all

.globl start_code
start_code:
        b .
ldscript

Code: Select all

ENTRY(start_code)

SECTIONS
{
  .text :
  {
   *(.text)
  }
}
and I create the final elf using :

Code: Select all

arm-none-linux-gnueabi-gcc -c test.S
arm-none-linux-gnueabi-ld -T ldscript test.o -o test
My problem now is that the '.text' section starts at offset 0x8000 and there's this huge unused space between the '.text' and the headers.

Code: Select all

arm-none-linux-gnueabi-readelf -a test
Output:

Code: Select all

....

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 008000 000004 00  AX  0   0  1
  [ 2] .ARM.attributes   ARM_ATTRIBUTES  00000000 008004 000014 00      0   0  1
  [ 3] .shstrtab         STRTAB          00000000 008018 000031 00      0   0  1
  [ 4] .symtab           SYMTAB          00000000 00813c 000050 10      5   4  4
  [ 5] .strtab           STRTAB          00000000 00818c 00000f 00      0   0  1

.....

Code: Select all

hexdump -C test
Output:

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 00 00 34 00 00 00  |..(.........4...|
00000020  4c 80 00 00 00 00 00 05  34 00 20 00 01 00 28 00  |L.......4. ...(.|
00000030  06 00 03 00 01 00 00 00  00 80 00 00 00 00 00 00  |................|
00000040  00 00 00 00 04 00 00 00  04 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  fe ff ff ea 41 13 00 00  00 61 65 61 62 69 00 01  |....A....aeabi..|
00008010  09 00 00 00 06 01 08 01  00 2e 73 79 6d 74 61 62  |..........symtab|
00008020  00 2e 73 74 72 74 61 62  00 2e 73 68 73 74 72 74  |..strtab..shstrt|
00008030  61 62 00 2e 74 65 78 74  00 2e 41 52 4d 2e 61 74  |ab..text..ARM.at|
00008040  74 72 69 62 75 74 65 73  00 00 00 00 00 00 00 00  |tributes........|
00008050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

......
Is there a way to move the '.text' to an earlier position in the image file ? and why is this huge zero-filled space ? Is it an alignment requirement or what ?

NOTE:
Using ALIGN(x) and SUBALIGN(y) in the '.text' section didn't change it at all.


Thanks in advance.

Re: ELF:Linking and zero-filled space that's not a .data sec

Posted: Thu May 19, 2011 12:29 am
by xenos
I'm not quite sure whether this applies to ARM as well, but I had a similar problem on x86_64. There was a huge (1 MB) empty space in my kernel ELF file. I fixed it using the ld option -z max-page-size=0x1000, so the start of my kernel code is aligned on a 4k boundary instead of a 1M boundary.

Re: ELF:Linking and zero-filled space that's not a .data sec

Posted: Thu May 19, 2011 12:59 am
by KarimAllah
Thanks alot 'XenOS', it worked. :)


I took a look at the man page and it says :

Code: Select all

"max-page-size=value
               Set the emulation maximum page size to value.."
What is the 'emulation maximum page size' ?