* Loading an elf file
@ 2010-04-09 9:50 Bahadir Balban
2010-04-09 10:35 ` Tristan Gingold
0 siblings, 1 reply; 5+ messages in thread
From: Bahadir Balban @ 2010-04-09 9:50 UTC (permalink / raw)
To: binutils
Hi,
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
This forces me to inspect sections rather than program segments to
distinguish RX, RO, RW parts of the executable.
Firstly is the above elf file correctly assembled? Secondly I thought
the standard practice to load an elf file is to use program headers
only, but I am obliged to inspect sections. Can you comment?
Thanks,
--
Bahadir
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Loading an elf file
2010-04-09 9:50 Loading an elf file Bahadir Balban
@ 2010-04-09 10:35 ` Tristan Gingold
2010-04-09 14:48 ` Bahadir Balban
0 siblings, 1 reply; 5+ messages in thread
From: Tristan Gingold @ 2010-04-09 10:35 UTC (permalink / raw)
To: Bahadir Balban; +Cc: binutils
On Apr 9, 2010, at 11:50 AM, Bahadir Balban wrote:
> Hi,
>
> 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
>
> This forces me to inspect sections rather than program segments to
> distinguish RX, RO, RW parts of the executable.
>
> Firstly is the above elf file correctly assembled? Secondly I thought
> the standard practice to load an elf file is to use program headers
> only, but I am obliged to inspect sections. Can you comment?
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Loading an elf file
2010-04-09 10:35 ` Tristan Gingold
@ 2010-04-09 14:48 ` Bahadir Balban
2010-04-09 15:17 ` Alan Modra
2010-04-09 15:54 ` John Reiser
0 siblings, 2 replies; 5+ messages in thread
From: Bahadir Balban @ 2010-04-09 14:48 UTC (permalink / raw)
To: Tristan Gingold; +Cc: binutils
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Loading an elf file
2010-04-09 14:48 ` Bahadir Balban
@ 2010-04-09 15:17 ` Alan Modra
2010-04-09 15:54 ` John Reiser
1 sibling, 0 replies; 5+ messages in thread
From: Alan Modra @ 2010-04-09 15:17 UTC (permalink / raw)
To: Bahadir Balban; +Cc: Tristan Gingold, binutils
On Fri, Apr 09, 2010 at 05:48:04PM +0300, Bahadir Balban wrote:
> Here's an excerpt from the linker script we use, could you please
> comment on what's missing?
Lacks page alignment gaps. Your hardware can't change memory
protection on byte boundaries. The linker knows this, so if you mash
RW sections up against RE sections you'll get a RWE segment.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Loading an elf file
2010-04-09 14:48 ` Bahadir Balban
2010-04-09 15:17 ` Alan Modra
@ 2010-04-09 15:54 ` John Reiser
1 sibling, 0 replies; 5+ messages in thread
From: John Reiser @ 2010-04-09 15:54 UTC (permalink / raw)
To: binutils
> Here's an excerpt from the linker script we use, could you please
> comment on what's missing?
On a machine such as i686 or x86_64, run "ld -verbose" to see a default
linker script. Pay attention to ALIGN commands and other expressions
involving ". &", such as these and others:
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1));
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
.sharable_data : ALIGN(CONSTANT (MAXPAGESIZE))
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
--
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-04-09 15:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-09 9:50 Loading an elf file Bahadir Balban
2010-04-09 10:35 ` Tristan Gingold
2010-04-09 14:48 ` Bahadir Balban
2010-04-09 15:17 ` Alan Modra
2010-04-09 15:54 ` John Reiser
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).