From 258795f524fca9d5b98441b81684c331c4d721b1 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 16 Jan 2009 14:14:07 +0000 Subject: [PATCH] ld/ 2009-01-16 H.J. Lu * lexsup.c (option_values): Add OPTION_TTEXT_SEGMENT. (ld_options): Add -Ttext-segment. (parse_args): Handle OPTION_TTEXT_SEGMENT. * ld.texinfo: Document -Ttext-segment. * NEWS: Mention -Ttext-segment. * scripttempl/elf.sc (TEXT_START_ADDR): Use SEGMENT_START. (SHLIB_TEXT_START_ADDR): Likewise. ld/testsuite/ 2009-01-16 H.J. Lu * ld-elf/textaddr1.d: New. * ld-elf/textaddr2.d: Likewise. --- ld/ChangeLog | 13 +++++++++++++ ld/NEWS | 3 +++ ld/ld.texinfo | 6 ++++++ ld/lexsup.c | 6 ++++++ ld/scripttempl/elf.sc | 7 +++++-- ld/testsuite/ChangeLog | 5 +++++ ld/testsuite/ld-elf/textaddr1.d | 8 ++++++++ ld/testsuite/ld-elf/textaddr2.d | 8 ++++++++ 8 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-elf/textaddr1.d create mode 100644 ld/testsuite/ld-elf/textaddr2.d diff --git a/ld/ChangeLog b/ld/ChangeLog index c9069cf195b..a73efc55659 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,16 @@ +2009-01-16 H.J. Lu + + * lexsup.c (option_values): Add OPTION_TTEXT_SEGMENT. + (ld_options): Add -Ttext-segment. + (parse_args): Handle OPTION_TTEXT_SEGMENT. + + * ld.texinfo: Document -Ttext-segment. + + * NEWS: Mention -Ttext-segment. + + * scripttempl/elf.sc (TEXT_START_ADDR): Use SEGMENT_START. + (SHLIB_TEXT_START_ADDR): Likewise. + 2009-01-13 Alan Modra * emultempl/spu_icache.o_c: Regenerate. diff --git a/ld/NEWS b/ld/NEWS index 9e56775923f..790cab3f428 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -1,5 +1,8 @@ -*- text -*- +* Add a new command line option, -Ttext-segment ADDR, for ELF targets + to set the address of the first byte of the text segment. + * Add new option --use-nul-prefixed-import-tables to ld for PE targets to allow fallback to old import table generation with null element prefix. diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 3f1654614de..35435053b3c 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -1723,6 +1723,12 @@ sign (``@key{=}''), and @var{org}. Same as --section-start, with @code{.bss}, @code{.data} or @code{.text} as the @var{sectionname}. +@kindex -Ttext-segment @var{org} +@itemx -Ttext-segment @var{org} +@cindex text segment origin, cmd line +When creating an ELF executable or shared object, it will set the address +of the first byte of the text segment. + @kindex --unresolved-symbols @item --unresolved-symbols=@var{method} Determine how to handle unresolved symbols. There are four possible diff --git a/ld/lexsup.c b/ld/lexsup.c index 60a8167d5dc..f9e6b1fcb46 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -103,6 +103,7 @@ enum option_values OPTION_TBSS, OPTION_TDATA, OPTION_TTEXT, + OPTION_TTEXT_SEGMENT, OPTION_TRADITIONAL_FORMAT, OPTION_UR, OPTION_VERBOSE, @@ -512,6 +513,8 @@ static const struct ld_option ld_options[] = '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH }, { {"Ttext", required_argument, NULL, OPTION_TTEXT}, '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH }, + { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT}, + '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH }, { {"unresolved-symbols=", required_argument, NULL, OPTION_UNRESOLVED_SYMBOLS}, '\0', NULL, N_("How to handle unresolved symbols. is:\n" @@ -1231,6 +1234,9 @@ parse_args (unsigned argc, char **argv) case OPTION_TTEXT: set_segment_start (".text", optarg); break; + case OPTION_TTEXT_SEGMENT: + set_segment_start (".text-segment", optarg); + break; case OPTION_TRADITIONAL_FORMAT: link_info.traditional_format = TRUE; break; diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index bb8c8080b26..123a9891f5d 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -242,6 +242,9 @@ STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : *(.stack) }" +TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})" +SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-0})" + # 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" @@ -267,8 +270,8 @@ SECTIONS { /* 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;}} ${INITIAL_READONLY_SECTIONS} .note.gnu.build-id : { *(.note.gnu.build-id) } EOF diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index fe0d80239a5..128e5e14d0b 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-01-16 H.J. Lu + + * ld-elf/textaddr1.d: New. + * ld-elf/textaddr2.d: Likewise. + 2009-01-14 H.J. Lu PR ld/9727 diff --git a/ld/testsuite/ld-elf/textaddr1.d b/ld/testsuite/ld-elf/textaddr1.d new file mode 100644 index 00000000000..f7a3ad953e1 --- /dev/null +++ b/ld/testsuite/ld-elf/textaddr1.d @@ -0,0 +1,8 @@ +#source: maxpage1.s +#ld: -Ttext-segment 0x7000000 -z max-page-size=0x200000 +#readelf: -l --wide +#target: *-*-linux-gnu + +#... + LOAD +0x0+ 0x0*7000000 0x0*7000000 0x0*[0-9a-f][0-9a-f][0-9a-f] 0x0*[0-9a-f][0-9a-f][0-9a-f] R E 0x200000 +#pass diff --git a/ld/testsuite/ld-elf/textaddr2.d b/ld/testsuite/ld-elf/textaddr2.d new file mode 100644 index 00000000000..9d1b0e51b13 --- /dev/null +++ b/ld/testsuite/ld-elf/textaddr2.d @@ -0,0 +1,8 @@ +#source: maxpage1.s +#ld: -shared -Ttext-segment 0x7000000 -z max-page-size=0x200000 +#readelf: -l --wide +#target: *-*-linux-gnu + +#... + LOAD +0x0+ 0x0*7000000 0x0*7000000 0x0*[0-9a-f][0-9a-f][0-9a-f] 0x0*[0-9a-f][0-9a-f][0-9a-f] R E 0x200000 +#pass -- 2.30.2