[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: BUG: Not enough room for program headers, try linking with -N
From: |
Nick Clifton |
Subject: |
Re: BUG: Not enough room for program headers, try linking with -N |
Date: |
09 Aug 2002 18:29:44 +0100 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/21.1 |
Hi Tobias,
> arm-elf-ld: a.out: Not enough room for program headers, try linking
> with -N
> arm-elf-ld: final link failed: Bad value
>
> Why does it tell me to use -N? Wouldn't -n be a better choice (now that
> it works)?
Hmm, yes it would.
> If I change the vaddr of the .text section from 0 to say 0x1000, it
> works,
Right. This is because, without -n or -N the linker will try to
arrange for the sections in the output file to be on page boundaries
so that they can be directly mmap'ed into memory. Since you have
specified that the .text section should start at address 0x0 the
linker tries to place it at offset 0x0 into the file (ie right at the
start of the file). But the ELF spec says that the ELF header has to
be the first thing in the file, hence there is a conflict.
> but then the program headers look strange (the first one is
> completely strange, and the alignment is weird):
>
> Program Header:
> LOAD off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**15
> filesz 0x00001020 memsz 0x00001020 flags rwx
> LOAD off 0x00009000 vaddr 0x00001000 paddr 0x00002000 align 2**15
> filesz 0x00000020 memsz 0x00000020 flags r-x
Right, so you would be better off declaring your own program headers
rather than having the linker try to guess them for you.
> Do you agree that I should not need --nmagic in this case, or is
> there something wrong with my link script?
There is something wrong - you need to tell the linker how to create
the program headers. For example this script:
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(__reset)
PHDRS
{
headers PT_PHDR FILEHDR PHDRS ;
text PT_LOAD ;
data PT_LOAD ;
}
SECTIONS
{
.text 0x0 : AT ( 0x2000 )
{
*(.text)
*(.glue_7t)
*(.glue_7)
} : text
.data :
{
*(.data)
*(.bss)
} : data
}
Works and produces the following layout:
a.out: file format elf32-littlearm
Program Header:
PHDR off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
filesz 0x00000094 memsz 0x00000094 flags r--
LOAD off 0x00008000 vaddr 0x00000000 paddr 0x00002000 align 2**15
filesz 0x00000020 memsz 0x00000020 flags r-x
LOAD off 0x00008020 vaddr 0x00000020 paddr 0x00000020 align 2**15
filesz 0x00000000 memsz 0x00000000 flags rw-
private flags = 0: [APCS-32] [FPA float format]
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000020 00000000 00002000 00008000 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000000 00000020 00002020 00008020 2**0
CONTENTS, ALLOC, LOAD, DATA
So now you have a explicit segment to hold the file header and program
headers, an explicit segment for the text section, which is held at an
offset of 0x8000 into the file, but which will be loaded at address
0x2000 and which will be expected to run at address 0x0000. Plus you
have a further segment for the .data section, which follows
immediately after the segment for the .text section, but which has
different attributes.
Cheers
Nick