This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Loading an elf file


Tristan Gingold wrote:
> On Apr 9, 2010, at 11:50 AM, Bahadir Balban wrote:
>> I am trying to load an elf file. Often read-only, writeable and exec
>> sections are packed into one loadable segment as below:
>>
>>> Program Headers:
>>>  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
>>>  LOAD           0x008000 0xf0008000 0x00008000 0x29000 0x2f21c RWE 0x8000
>>>  LOAD           0x038000 0xf0038000 0x00038000 0x044e8 0x044e8 RW  0x8000
>>>
>>> Section to Segment mapping:
>>>  Segment Sections...
>>>   00     .text .rodata .data .bss 
>>>   01     .init 
> No, you don't need to inspect sections.  Looks like the executable was not generated as you expected it.
> 
> The way sections are packed into segments is controlled by the linker script.  You need to check it.
> You'd also be better to check the attributes of the sections.
> 
> Tristan.
> 

Here's an excerpt from the linker script we use, could you please
comment on what's missing?

> ENTRY(kernel_physical)
> 
> SECTIONS
> {
> 	. = kernel_virtual;
> 	_start_kernel = .;
> 	.text : AT (ADDR(.text) - kernel_offset)
> 	{
> 		_start_text = .;
> 		/* Make sure head.S comes first */
> 		/* *head.o(.text) This only works when given its full path. Bad limitation. */
> 		*(.text.head)
> 		*(.text)
> 		_end_text = .;
> 	}
> 	. = ALIGN(4);
> 	/* rodata is needed else your strings will link at physical! */
> 	.rodata : AT (ADDR(.rodata) - kernel_offset) { *(.rodata) }
> 	.rodata1 : AT (ADDR(.rodata1) - kernel_offset) { *(.rodata1) }
> 	.data : AT (ADDR(.data) - kernel_offset)
> 	{
> 		_start_data = .;
> 		*(.data)
> 		/* Best alignment because we need 4 x (4K) and 1 x 16K block */
> 		. = ALIGN(16K);
> 		_start_vectors = .;
> 		*(.data.vectors)
> 		. = ALIGN(4K);
> 		_end_vectors = .;
> 		_start_kip = .;
> 		*(.data.kip)
> 		. = ALIGN(4K);
> 		_end_kip = .;
> 		_start_syscalls = .;
> 		*(.data.syscalls)
> 		. = ALIGN(4K);
> 		_end_syscalls = .;
> 		_start_init_pgd = .;
> 		*(.data.pgd);
> 		_end_init_pgd = .;
> 		_start_bootstack = .;
> 		. = ALIGN(4K);
> 		. += PAGE_SIZE * CONFIG_NCPU;
> 		_end_bootstack = .;
> 		_end_data = .;
> 	}
> 	.bss : AT (ADDR(.bss) - kernel_offset)
> 	{
> 		*(.bss)
> 	}
> 	. = ALIGN(4K);
> 
> 	/* Below part is to be discarded after boot */
> 	_start_init = .;
> 	.init : AT (ADDR(.init) - kernel_offset)
> 	{
> 		*(.init.task.pgd) 	/* Non-global task table on split tables, otherwise nil */
> 		*(.init.bootmem)
> 		*(.init.data)
> 	}
> 	_end_init = .;
> 	_end_kernel = .;
> 	_end = .;
> }


Thank you,

-- 
Bahadir


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]