This is the mail archive of the 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]

generating ELF layout with ehdr in the middle of the address space

I have an ELF target that has these constraints:

1. code and non-code must be entirely in disjoint segments
   i.e. no PT_LOAD with PF_X can contain anything but actual instructions
2. The code is in the low part of the address space, the non-code higher up.

Furthermore I would like to preserve the nice property that some PT_LOAD
segment covers the beginning of the file, containing the ehdr and phdrs.

ELF specifies that PT_LOAD must appear in ascending address order.
But nothing says that this must also be ascending file offset order.

Hence, the layout I would like to produce is:

	PT_LOAD p_vaddr=0x20000 p_flags=PF_R|PF_X p_offset>0
		.text et al
	PT_LOAD p_vaddr>0x20000 p_flags=PF_R p_offset=0
		.rodata et al
	PT_LOAD p_vaddr>0x20000 p_flags=PF_R|PF_W p_offset=whatever
		.data et al

That is, the sections and address space are organized as usual, but the
lowest-addressed section/segment does not appear at the beginning of the
file.  Instead, the lowest-addressed non-executable, read-only segment
appears at the beginning of the file, with its first section starting at
p_vaddr+SIZEOF_HEADERS.  (The executable segment has to be page-aligned
anyway, so there is no problem about the segments overlapping in the file.)

I had no trouble hacking the linker emulation scripts to produce linker
scripts that place the sections how I want them.  But now I'm trying to
figure out what I'd have to hack to get the unusual mapping of segments to
file positions that I want.  I've been poring over the bfd/elf.c code but I
don't have much idea yet where to start.



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