This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] -Ttext, -Tdata for ELF targets
- From: Dan Gohman <djg at cray dot com>
- To: binutils at sourceware dot org
- Date: Mon, 26 Jun 2006 15:14:30 -0500
- Subject: [PATCH] -Ttext, -Tdata for ELF targets
A while ago there was a patch to make -Ttext and friends not
useless/broken for ELF targets, but it ended up only being changed for
armbpabi.sc:
http://sourceware.org/ml/binutils/2004-10/msg00430.html
I need a linker that can do this on a different ELF target, so I wrote
up a patch for the generif elf.sc that uses the new SEGMENT_START
expression, similar to what was done for armbpabi.
Here's the patch that I'm using for now. Is it desirable to fix -Ttext
and -Tdata for all ELF targets this way?
BTW, currently there are a few test failures with this patch in tests
that use -Ttext because the new behavior is to set the text segment
address instead of the .text section address, so some symbols end up
with different addresses.
--
Dan Gohman
Cray Inc.
djg@cray.com
Index: elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.72
diff -u -r1.72 elf.sc
--- elf.sc 28 Dec 2005 06:01:48 -0000 1.72
+++ elf.sc 26 Jun 2006 19:38:06 -0000
@@ -95,10 +95,12 @@
test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT
DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
+DATA_SEGMENT_BEGIN=""
DATA_SEGMENT_RELRO_END=""
DATA_SEGMENT_END=""
if test -n "${COMMONPAGESIZE}"; then
- DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
+ DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1))"
+ DATA_SEGMENT_BEGIN=". = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE});"
DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
fi
@@ -229,6 +231,11 @@
*(.stack)
}"
+TEXT_START_ADDR="SEGMENT_START(\"text\", ${TEXT_START_ADDR})"
+SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text\", ${SHLIB_TEXT_START_ADDR:-0})"
+DATA_ADDR="SEGMENT_START(\"data\", ${DATA_ADDR-${DATA_SEGMENT_ALIGN}})"
+SHLIB_DATA_ADDR="SEGMENT_START(\"data\", ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}})"
+
# if this is for an embedded system, don't add SIZEOF_HEADERS.
if [ -z "$EMBEDDED" ]; then
test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
@@ -254,8 +261,8 @@
{
/* Read-only sections, merged into text segment: */
${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
- ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
- ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
+ ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR} + SIZEOF_HEADERS;}}
+ ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR} + SIZEOF_HEADERS;}}
${CREATE_SHLIB-${INTERP}}
${INITIAL_READONLY_SECTIONS}
${TEXT_DYNAMIC+${DYNAMIC}}
@@ -364,9 +371,10 @@
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
- ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
- ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
- ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
+ ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR};}}}
+ ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR};}}
+ ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR};}}
+ ${RELOCATING+${DATA_SEGMENT_BEGIN}}
/* Exception handling */
.eh_frame ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }