This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
-Ttext and phdr_in_segment
- From: Senthil Kumar Selvaraj <senthil_kumar dot selvaraj at atmel dot com>
- To: <binutils at sourceware dot org>
- Date: Mon, 21 Jan 2013 19:23:04 +0530
- Subject: -Ttext and phdr_in_segment
Hi,
_bfd_elf_map_sections_to_segments sets phdr_in_segment to
TRUE and sets it to false only if the LMA of the first section is less
than the elf header size + program headers size.
bfd_size_type phdr_size = elf_tdata (abfd)->program_header_size;
if (phdr_size == (bfd_size_type) -1)
phdr_size = get_program_header_size (abfd, info);
phdr_size += bed->s->sizeof_ehdr;
if ((abfd->flags & D_PAGED) == 0
|| (sections[0]->lma & addr_mask) < phdr_size
<snip>)
phdr_in_segment = FALSE;
}
Is the comparison with LMA right for embedded targets like AVR, where
the LMA refers to a FLASH address, and the header is not written
to FLASH? What is the intention behind the check?
For the AVR target, specifying -Ttext=<val>, with <val> bigger than
the size of the headers results in phdr_in_segment being set to true,
and this causes the headers to be placed in the text segment.
For <val> less than sizeof(headers), say 0x40, this is what objdump prints
Program Header:
LOAD off 0x00000074 vaddr 0x00000040 paddr 0x00000040 align 2**0
filesz 0x00000112 memsz 0x00000112 flags r-x
With a bigger <val> (-Ttext=x100), this is the output of objdump.
Program Header:
LOAD off 0x00000000 vaddr 0x0000008c paddr 0x0000008c align 2**0
filesz 0x00000186 memsz 0x00000186 flags r-x
<snip>
Notice that the file offset is zero, and the addr fields are set to
<val> - sizeof(headers) (0x100 - 0x74, in this case.) This confuses the
"programmer", which reads the header information to write to FLASH - it
ends up writing the ELF + program headers also, instead of just the
.text section.
My question, again, is if comparing the headers size against the LMA of
the text section (section[0]) correct? Is there a way to "turn off"
placement of the headers in a segment, rather than the start of the
file?
Regards
Senthil