This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Moving _etext to after all read-only sections
- To: binutils at sources dot redhat dot com
- Subject: Moving _etext to after all read-only sections
- From: Jason R Thorpe <thorpej at zembu dot com>
- Date: Fri, 19 Jan 2001 15:31:55 -0800
- Organization: Zembu Labs, Inc.
- Reply-To: thorpej at zembu dot com
Something else caused me to notice this, but it seems like a bug
in any case.
In Binutils 2.9 and also in Binutils-current, _etext is placed
after .text but before .rodata, etc. This is fine for normal
applications (the read-only sections are gathered together in
a single, contiguous read-only section from the point of view
of a program loader). But for e.g. an operating system kernel,
this is problematic. The kernel, while bootstrapping VM, only
really has the _etext symbol to work with if it wants to map
the text and read-only data of the kernel as read-only. The
end result is that const data ends up being writable.
A simple patch to the 2.9 elf.sc fixes this... but it looks
like it might be more complicated in Binutils-current (what
is WRITABLE_RODATA anyhow? -- also I'm not completely clear
on the CREATE_SHLIB-SDATA2 and CREATE_SHLIB-SBSS2 stuff).
Does anyone have any thoughts as to the wisdom of this change?
It occurred to me as the obvious one (over e.g. adding a new
_ereadonly symbol, or something) because of the comment near
the beginning of the template:
/* Read-only sections, merged into text segment: */
Index: elf.sc
===================================================================
RCS file: /cvsroot/gnusrc/gnu/dist/ld/scripttempl/elf.sc,v
retrieving revision 1.3
diff -c -r1.3 elf.sc
*** elf.sc 1999/02/02 20:27:21 1.3
--- elf.sc 2001/01/19 23:03:57
***************
*** 112,123 ****
${RELOCATING+*(.gnu.linkonce.t*)}
${RELOCATING+${OTHER_TEXT_SECTIONS}}
} =${NOP-0}
- ${RELOCATING+_etext = .;}
- ${RELOCATING+PROVIDE (etext = .);}
.fini ${RELOCATING-0} : { *(.fini) } =${NOP-0}
.rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.gnu.linkonce.r*)} }
.rodata1 ${RELOCATING-0} : { *(.rodata1) }
${RELOCATING+${OTHER_READONLY_SECTIONS}}
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
--- 112,123 ----
${RELOCATING+*(.gnu.linkonce.t*)}
${RELOCATING+${OTHER_TEXT_SECTIONS}}
} =${NOP-0}
.fini ${RELOCATING-0} : { *(.fini) } =${NOP-0}
.rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.gnu.linkonce.r*)} }
.rodata1 ${RELOCATING-0} : { *(.rodata1) }
${RELOCATING+${OTHER_READONLY_SECTIONS}}
+ ${RELOCATING+_etext = .;}
+ ${RELOCATING+PROVIDE (etext = .);}
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
--
-- Jason R. Thorpe <thorpej@zembu.com>