ld/ 2009-01-13 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. * scripttempl/elf.sc (TEXT_START_ADDR): Use SEGMENT_START. (SHLIB_TEXT_START_ADDR): Likewise. ld/testsuite/ 2009-01-13 H.J. Lu * ld-elf/textaddr1.d: New. * ld-elf/textaddr2.d: Likewise. Index: ld/lexsup.c =================================================================== --- ld/lexsup.c (revision 4969) +++ ld/lexsup.c (working copy) @@ -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; Index: ld/testsuite/ld-elf/textaddr1.d =================================================================== --- ld/testsuite/ld-elf/textaddr1.d (revision 0) +++ ld/testsuite/ld-elf/textaddr1.d (revision 0) @@ -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 Index: ld/testsuite/ld-elf/textaddr2.d =================================================================== --- ld/testsuite/ld-elf/textaddr2.d (revision 0) +++ ld/testsuite/ld-elf/textaddr2.d (revision 0) @@ -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 Index: ld/scripttempl/elf.sc =================================================================== --- ld/scripttempl/elf.sc (revision 4969) +++ ld/scripttempl/elf.sc (working copy) @@ -242,6 +242,9 @@ STACK=" .stack ${RELOCATING-0}${ *(.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 Index: ld/ld.texinfo =================================================================== --- ld/ld.texinfo (revision 4969) +++ ld/ld.texinfo (working copy) @@ -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