From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2124) id 8D9263882059; Thu, 13 Jun 2024 14:11:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D9263882059 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1718287864; bh=KAjg2qZe63hPclDlvGLMiGoNfGCOwugzZp4PCq3tjRY=; h=From:To:Subject:Date:From; b=QehkdiEKqftvuZOGswOkBMqlySsPGRSaUwVDOejaui5r++ExlRNISPIDzQ0DTTnLh Rb4bhIOWOfmbbxXzj8vtlrsk7wnJprLRIDFvfRQR05oHKh/kz1LCjUD511g77sNEAz Qt7JGXGe/ueczzQsb8EUpeScOqsZCO6UIf0vLc+k= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nick Clifton To: binutils-cvs@sourceware.org Subject: [binutils-gdb] Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only se X-Act-Checkin: binutils-gdb X-Git-Author: Nick Clifton X-Git-Refname: refs/heads/master X-Git-Oldrev: 888ff82e77d9ab8f04893a68cd6b4f518d6b50d9 X-Git-Newrev: e8e10743f7b207b21a1efb0cc9e42487080db013 Message-Id: <20240613141104.8D9263882059@sourceware.org> Date: Thu, 13 Jun 2024 14:11:04 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De8e10743f7b2= 07b21a1efb0cc9e42487080db013 commit e8e10743f7b207b21a1efb0cc9e42487080db013 Author: Nick Clifton Date: Thu Jun 13 15:10:15 2024 +0100 Add --rosegment option to BFD linker to stop the '-z separate-code' fro= m generating two read-only segments. =20 PR 30907 Diff: --- bfd/elf.c | 4 +- include/bfdlink.h | 3 + ld/NEWS | 4 + ld/config.in | 4 + ld/configure | 22 ++++ ld/configure.ac | 17 +++ ld/emultempl/elf.em | 271 ++++++++++++++++++++++++++++++++++++= +--- ld/genscripts.sh | 186 +++++++++++++++++++++++++-- ld/ld.texi | 15 +++ ld/ldint.texi | 68 +++++++++- ld/ldlex.h | 2 + ld/lexsup.c | 11 ++ ld/scripttempl/elf.sc | 118 ++++++++++++++--- ld/testsuite/ld-elf/pr30907-1.d | 14 +++ ld/testsuite/ld-elf/pr30907-2.d | 15 +++ 15 files changed, 709 insertions(+), 45 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index 74236a658fd..b0b1e94d16c 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5335,7 +5335,9 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, thus not executable, and the first section is executable then put the file and program headers in their own PT_LOAD. */ - separate_phdr =3D true; + if (!info->one_rosegment) + separate_phdr =3D true; + if ((((phdr_lma + phdr_size - 1) & addr_mask & -maxpagesize) =3D=3D (sections[0]->lma & addr_mask & -maxpagesize))) { diff --git a/include/bfdlink.h b/include/bfdlink.h index eac07d78364..015370d268f 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -423,6 +423,9 @@ struct bfd_link_info /* TRUE if separate code segment should be created. */ unsigned int separate_code: 1; =20 + /* TRUE if only one read-only, non-code segment should be created. */ + unsigned int one_rosegment: 1; + /* Nonzero if .eh_frame_hdr section and PT_GNU_EH_FRAME ELF segment should be created. 1 for DWARF2 tables, 2 for compact tables. */ unsigned int eh_frame_hdr_type: 2; diff --git a/ld/NEWS b/ld/NEWS index 00eb46047d1..585ec09e241 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -1,5 +1,9 @@ -*- text -*- =20 +* Add --rosegment option which changes the -z separate-code option so that + only one read-only segment is created (instead of two). (The option name + is misleading, but it matches the name used by LLD and GOLD). + * Add --section-ordering-file option to add extra mapping of input sections to output sections. =20 diff --git a/ld/config.in b/ld/config.in index 52d62f06ff0..5f57a61def1 100644 --- a/ld/config.in +++ b/ld/config.in @@ -49,6 +49,10 @@ default. */ #undef DEFAULT_LD_Z_MARK_PLT =20 +/* Define to 1 if you want to enable --rosegment in the ELF linker by + default. */ +#undef DEFAULT_LD_ROSEGMENT + /* Define to 1 if you want to enable -z relro in ELF linker by default. */ #undef DEFAULT_LD_Z_RELRO =20 diff --git a/ld/configure b/ld/configure index 9151640ca60..83ea68f8e4b 100755 --- a/ld/configure +++ b/ld/configure @@ -852,6 +852,7 @@ enable_new_dtags enable_relro enable_textrel_check enable_separate_code +enable_rosegment enable_mark_plt enable_warn_execstack enable_error_execstack @@ -1547,6 +1548,7 @@ Optional Features: --enable-textrel-check=3D[yes|no|warning|error] enable DT_TEXTREL check in ELF linker --enable-separate-code enable -z separate-code in ELF linker by default + --enable-rosegment enable --rosegment in the ELF linker by default --enable-mark-plt enable -z mark-plt in ELF x86-64 linker by defau= lt --enable-warn-execstack enable warnings when creating an executable stack --enable-error-execstack @@ -15682,6 +15684,17 @@ esac fi =20 =20 +# Decide if --rosegment should be enabled in the ELF linker by default. +ac_default_ld_rosegment=3Dunset +# Check whether --enable-rosegment was given. +if test "${enable_rosegment+set}" =3D set; then : + enableval=3D$enable_rosegment; case "${enableval}" in + yes) ac_default_ld_rosegment=3D1 ;; + no) ac_default_ld_rosegment=3D0 ;; +esac +fi + + # Decide if -z mark-plt should be enabled in ELF x86-64 linker by default. ac_default_ld_z_mark_plt=3Dunset # Check whether --enable-mark-plt was given. @@ -19381,6 +19394,15 @@ cat >>confdefs.h <<_ACEOF _ACEOF =20 =20 +if test "${ac_default_ld_rosegment}" =3D unset; then + ac_default_ld_rosegment=3D0 +fi + +cat >>confdefs.h <<_ACEOF +#define DEFAULT_LD_ROSEGMENT $ac_default_ld_rosegment +_ACEOF + + if test "${ac_default_ld_z_mark_plt}" =3D unset; then ac_default_ld_z_mark_plt=3D0 fi diff --git a/ld/configure.ac b/ld/configure.ac index 8ba6cf9edfb..bdf51a062fa 100644 --- a/ld/configure.ac +++ b/ld/configure.ac @@ -212,6 +212,16 @@ AC_ARG_ENABLE(separate-code, no) ac_default_ld_z_separate_code=3D0 ;; esac]) =20 +# Decide if --rosegment should be enabled in the ELF linker by default. +ac_default_ld_rosegment=3Dunset +AC_ARG_ENABLE(rosegment, + AS_HELP_STRING([--enable-rosegment], + [enable --rosegment in the ELF linker by default]), +[case "${enableval}" in + yes) ac_default_ld_rosegment=3D1 ;; + no) ac_default_ld_rosegment=3D0 ;; +esac]) + # Decide if -z mark-plt should be enabled in ELF x86-64 linker by default. ac_default_ld_z_mark_plt=3Dunset AC_ARG_ENABLE(mark-plt, @@ -571,6 +581,13 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_SEPARATE_CODE, $ac_default_ld_z_separate_code, [Define to 1 if you want to enable -z separate-code in ELF linker by def= ault.]) =20 +if test "${ac_default_ld_rosegment}" =3D unset; then + ac_default_ld_rosegment=3D0 +fi +AC_DEFINE_UNQUOTED(DEFAULT_LD_ROSEGMENT, + $ac_default_ld_rosegment, + [Define to 1 if you want to enable --rosegment in the ELF linker by defa= ult.]) + if test "${ac_default_ld_z_mark_plt}" =3D unset; then ac_default_ld_z_mark_plt=3D0 fi diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em index 55a870f7d2d..863657e12f5 100644 --- a/ld/emultempl/elf.em +++ b/ld/emultempl/elf.em @@ -93,6 +93,7 @@ EOF fi fragment <> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULAT= ION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c + echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c + if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; th= en : ; else -echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAM= E}.c -sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c + echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_N= AME}.c + sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c fi + if test -n "$GENERATE_PIE_SCRIPT" ; then if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then + +echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c +echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xdwer >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xdwe >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.relro' >> e${EMULATION_NAME}.c echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + +echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAM= E}.c +echo ' && link_info.combreloc' >> e${EMULATION_NAM= E}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAM= E}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xdceor >> e${EMULATION_NAM= E}.c + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.combreloc' >> e${EMULATION_NAM= E}.c echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xdceo >> e${EMULATION_NAM= E}.c + fi + +echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c +echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xdcer >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xdce >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.combreloc' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xdco >> e${EMULATION_NAM= E}.c + fi + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + +echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAM= E}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAM= E}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xdeor >> e${EMULATION_NAM= E}.c + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xdeo >> e${EMULATION_NAM= E}.c + fi + fi + +echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAM= E}.c +echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xder >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xde >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xdo >> e${EMULATION_NAM= E}.c + fi + echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME= }.c sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c fi + if test -n "$GENERATE_SHLIB_SCRIPT" ; then if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then + +echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c +echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xswer >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xswe >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.relro' >> e${EMULATION_NAME}.c echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + +echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAM= E}.c +echo ' && link_info.combreloc' >> e${EMULATION_NAM= E}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAM= E}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xsceor >> e${EMULATION_NAM= E}.c + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.combreloc' >> e${EMULATION_NAM= E}.c echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xsceo >> e${EMULATION_NAM= E}.c + fi + +echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xscer >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xsce >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.combreloc' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xsco >> e${EMULATION_NAM= E}.c + fi + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + +echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAM= E}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAM= E}.c +echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xseor >> e${EMULATION_NAM= E}.c + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.separate_code' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xseo >> e${EMULATION_NAM= E}.c + fi + fi + +echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xser >> e${EMULATION_NAME}.c + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xse >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAM= E}.c echo ' && link_info.relro) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xso >> e${EMULATION_NAME= }.c + fi + echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME= }.c sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c + fi + if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then + echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xwe >> e${EMULATION_NAME}.c + +echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c +echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c +sed $sc ldscripts/${EMULATION_NAME}.xwer >> e${EMULATION_NAME}.c + echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.relro' >> e${EMULATION_NAME}.c echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULA= TION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + +echo ' ; else if (link_info.combreloc' >> e${EMULATION_NA= ME}.c +echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NA= ME}.c +sed $sc ldscripts/${EMULATION_NAME}.xceor >> e${EMULATION_NA= ME}.c + echo ' ; else if (link_info.combreloc' >> e${EMULATION_NA= ME}.c echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c echo ' && link_info.relro) return' >> e${EMULATION_NA= ME}.c sed $sc ldscripts/${EMULATION_NAME}.xceo >> e${EMULATION_NA= ME}.c + fi + +echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NAM= E}.c +echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c +sed $sc ldscripts/${EMULATION_NAME}.xcer >> e${EMULATION_NAME}.c + echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c echo ' && link_info.separate_code) return' >> e${EMULATION_NAM= E}.c sed $sc ldscripts/${EMULATION_NAME}.xce >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + echo ' ; else if (link_info.combreloc' >> e${EMULATION_NA= ME}.c echo ' && link_info.relro) return' >> e${EMULATION_NA= ME}.c sed $sc ldscripts/${EMULATION_NAME}.xco >> e${EMULATION_NA= ME}.c + fi + echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c + fi + if test -n "$GENERATE_RELRO_SCRIPT" ; then + +echo ' ; else if (link_info.separate_code' >> e${EMULATION_NA= ME}.c +echo ' && link_info.one_rosegment' >> e${EMULATION_NA= ME}.c +echo ' && link_info.relro) return' >> e${EMULATION_NA= ME}.c +sed $sc ldscripts/${EMULATION_NAME}.xeor >> e${EMULATION_NA= ME}.c + echo ' ; else if (link_info.separate_code' >> e${EMULATION_NA= ME}.c echo ' && link_info.relro) return' >> e${EMULATION_NA= ME}.c sed $sc ldscripts/${EMULATION_NAME}.xeo >> e${EMULATION_NA= ME}.c + fi + +echo ' ; else if (link_info.separate_code' >> e${EMULATION_NA= ME}.c +echo ' && link_info.one_rosegment) return' >> e${EMULATION_NA= ME}.c +sed $sc ldscripts/${EMULATION_NAME}.xer >> e${EMULATION_NAME}.c + echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NA= ME}.c sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c + if test -n "$GENERATE_RELRO_SCRIPT" ; then + echo ' ; else if (link_info.relro) return' >> e${EMULATION_NA= ME}.c sed $sc ldscripts/${EMULATION_NAME}.xo >> e${EMULATION_NA= ME}.c + fi + echo ' ; else return' >> e${EMULATION_NAME}.c sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c echo '; }' >> e${EMULATION_NAME}.c @@ -391,7 +544,12 @@ fragment < ldscripts/${EMULATION_NAME}.xe =20 +LD_FLAG=3Drotextonly +( echo "/* Script for -z separate-code -z one-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc +) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xer + if test -n "$GENERATE_RELRO_SCRIPT"; then - LD_FLAG=3D RELRO=3D" " + + LD_FLAG=3D ( echo "/* Script for -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xo + LD_FLAG=3Dtextonly ( echo "/* Script for -z separate-code -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xeo + + LD_FLAG=3Drotextonly + ( echo "/* Script for -z separate-code -z relro -z one-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xeor + unset RELRO fi + LD_FLAG=3Dn DATA_ALIGNMENT=3D${DATA_ALIGNMENT_n} ( echo "/* Script for -n */" @@ -362,6 +395,7 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc rm -f ${COMBRELOC} + =20 LD_FLAG=3Dctextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xce.tmp ( echo "/* Script for -z combreloc -z separate-code */" @@ -369,7 +403,17 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xce rm -f ${COMBRELOC} + + LD_FLAG=3Droctextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xcer.tmp + ( echo "/* Script for -z combreloc -z separate-code -z one-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xcer + rm -f ${COMBRELOC} + RELRO_NOW=3D" " + LD_FLAG=3Dw COMBRELOC=3Dldscripts/${EMULATION_NAME}.xw.tmp ( echo "/* Script for -z combreloc -z relro -z now */" @@ -377,6 +421,7 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw rm -f ${COMBRELOC} + LD_FLAG=3Dwtextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xwe.tmp ( echo "/* Script for -z combreloc -z separate-code -z relro -z now */" @@ -385,16 +430,29 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xwe rm -f ${COMBRELOC} COMBRELOC=3D + + LD_FLAG=3Drowtextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xwer.tmp + ( echo "/* Script for -z combreloc -z separate-code -z relro -z now -z o= ne-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xwer + rm -f ${COMBRELOC} + COMBRELOC=3D + unset RELRO_NOW + if test -n "$GENERATE_RELRO_SCRIPT"; then - LD_FLAG=3Dc RELRO=3D" " + + LD_FLAG=3Dc COMBRELOC=3Dldscripts/${EMULATION_NAME}.xco.tmp ( echo "/* Script for -z combreloc -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xco rm -f ${COMBRELOC} + LD_FLAG=3Dctextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xceo.tmp ( echo "/* Script for -z combreloc -z separate-code -z relro */" @@ -403,38 +461,66 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT"; then ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xceo rm -f ${COMBRELOC} COMBRELOC=3D + + LD_FLAG=3Droctextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xceor.tmp + ( echo "/* Script for -z combreloc -z separate-code -z relro -z one-= rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xceor + rm -f ${COMBRELOC} + COMBRELOC=3D + unset RELRO fi fi =20 if test -n "$GENERATE_SHLIB_SCRIPT"; then - DATA_ALIGNMENT=3D${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} CREATE_SHLIB=3D" " + DATA_ALIGNMENT=3D${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} + LD_FLAG=3Dshared ( echo "/* Script for -shared */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs + LD_FLAG=3Dsharedtextonly ( echo "/* Script for -shared -z separate-code */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xse =20 + LD_FLAG=3Drosharedtextonly + ( echo "/* Script for -shared -z separate-code -z one-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xser + if test -n "$GENERATE_RELRO_SCRIPT"; then RELRO=3D" " + LD_FLAG=3Dshared ( echo "/* Script for -shared -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xso + LD_FLAG=3Dsharedtextonly ( echo "/* Script for -shared -z separate-code -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xseo + + LD_FLAG=3Drosharedtextonly + ( echo "/* Script for -shared -z separate-code -z relro -z one-roseg= ment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xseor + unset RELRO fi + if test -n "$GENERATE_COMBRELOC_SCRIPT"; then DATA_ALIGNMENT=3D${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} LD_FLAG=3Dcshared @@ -444,6 +530,7 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc rm -f ${COMBRELOC} + LD_FLAG=3Dcsharedtextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xsce.tmp ( echo "/* Script for -shared -z combreloc -z separate-code */" @@ -451,7 +538,17 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsce rm -f ${COMBRELOC} + + LD_FLAG=3Drocsharedtextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xscer.tmp + ( echo "/* Script for -shared -z combreloc -z separate-code -z one-ros= egment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xscer + rm -f ${COMBRELOC} + RELRO_NOW=3D" " + LD_FLAG=3Dwshared COMBRELOC=3Dldscripts/${EMULATION_NAME}.xsw.tmp ( echo "/* Script for -shared -z combreloc -z relro -z now */" @@ -459,6 +556,7 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw rm -f ${COMBRELOC} + LD_FLAG=3Dwsharedtextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xswe.tmp ( echo "/* Script for -shared -z combreloc -z separate-code -z relro -= z now */" @@ -466,17 +564,28 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xswe rm -f ${COMBRELOC} + + LD_FLAG=3Drowsharedtextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xswe.tmp + ( echo "/* Script for -shared -z combreloc -z separate-code -z relro -= z now -z one-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xswer + rm -f ${COMBRELOC} + unset RELRO_NOW =20 if test -n "$GENERATE_RELRO_SCRIPT"; then - LD_FLAG=3Dwshared RELRO=3D" " + + LD_FLAG=3Dwshared COMBRELOC=3Dldscripts/${EMULATION_NAME}.xsco.tmp ( echo "/* Script for -shared -z combreloc -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsco rm -f ${COMBRELOC} + LD_FLAG=3Dwsharedtextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xsceo.tmp ( echo "/* Script for -shared -z combreloc -z separate-code -z relro */" @@ -484,40 +593,70 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsceo rm -f ${COMBRELOC} + + LD_FLAG=3Drowsharedtextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xsceor.tmp + ( echo "/* Script for -shared -z combreloc -z separate-code -z relro -z o= ne-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsceor + rm -f ${COMBRELOC} + unset RELRO fi + COMBRELOC=3D fi + unset CREATE_SHLIB fi =20 if test -n "$GENERATE_PIE_SCRIPT"; then - DATA_ALIGNMENT=3D${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} CREATE_PIE=3D" " + + DATA_ALIGNMENT=3D${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} LD_FLAG=3Dpie ( echo "/* Script for -pie */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd + LD_FLAG=3Dpietextonly ( echo "/* Script for -pie -z separate-code */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xde + + LD_FLAG=3Dropietextonly + ( echo "/* Script for -pie -z separate-code -z one-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xder + if test -n "$GENERATE_RELRO_SCRIPT"; then RELRO=3D" " + LD_FLAG=3Dpie ( echo "/* Script for -pie -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdo + LD_FLAG=3Dpietextonly ( echo "/* Script for -pie -z separate-code -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdeo + + LD_FLAG=3Dropietextonly + ( echo "/* Script for -pie -z separate-code -z relro -z one-rosegmen= t */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdeor + unset RELRO fi + if test -n "$GENERATE_COMBRELOC_SCRIPT"; then DATA_ALIGNMENT=3D${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdc.tmp @@ -527,6 +666,7 @@ if test -n "$GENERATE_PIE_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc rm -f ${COMBRELOC} + LD_FLAG=3Dcpietextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdce.tmp ( echo "/* Script for -pie -z combreloc -z separate-code */" @@ -534,7 +674,17 @@ if test -n "$GENERATE_PIE_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdce rm -f ${COMBRELOC} + + LD_FLAG=3Drocpietextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdcer.tmp + ( echo "/* Script for -pie -z combreloc -z separate-code -z one-rosegm= ent */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdcer + rm -f ${COMBRELOC} + RELRO_NOW=3D" " + LD_FLAG=3Dwpie COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdw.tmp ( echo "/* Script for -pie -z combreloc -z relro -z now */" @@ -542,6 +692,7 @@ if test -n "$GENERATE_PIE_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw rm -f ${COMBRELOC} + LD_FLAG=3Dwpietextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdwe.tmp ( echo "/* Script for -pie -z combreloc -z separate-code -z relro -z n= ow */" @@ -549,17 +700,28 @@ if test -n "$GENERATE_PIE_SCRIPT"; then source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdwe rm -f ${COMBRELOC} + + LD_FLAG=3Drowpietextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdwer.tmp + ( echo "/* Script for -pie -z combreloc -z separate-code -z relro -z n= ow -z one-rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdwer + rm -f ${COMBRELOC} + unset RELRO_NOW =20 if test -n "$GENERATE_RELRO_SCRIPT"; then - LD_FLAG=3Dwpie RELRO=3D" " + + LD_FLAG=3Dwpie COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdco.tmp ( echo "/* Script for -pie -z combreloc -z relro */" source_sh ${CUSTOMIZER_SCRIPT} source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdco rm -f ${COMBRELOC} + LD_FLAG=3Dwpietextonly COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdceo.tmp ( echo "/* Script for -pie -z combreloc -z separate-code -z relro */" @@ -568,10 +730,20 @@ if test -n "$GENERATE_PIE_SCRIPT"; then ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdceo rm -f ${COMBRELOC} =20 + LD_FLAG=3Drowpietextonly + COMBRELOC=3Dldscripts/${EMULATION_NAME}.xdceor.tmp + ( echo "/* Script for -pie -z combreloc -z separate-code -z relro -z one-= rosegment */" + source_sh ${CUSTOMIZER_SCRIPT} + source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc + ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdceor + rm -f ${COMBRELOC} + unset RELRO fi + COMBRELOC=3D fi + unset CREATE_PIE fi =20 diff --git a/ld/ld.texi b/ld/ld.texi index ef3706fa7ac..9f3fbbd245f 100644 --- a/ld/ld.texi +++ b/ld/ld.texi @@ -1121,6 +1121,21 @@ For compatibility with other ELF linkers, if the @op= tion{-R} option is followed by a directory name, rather than a file name, it is treated as the @option{-rpath} option. =20 +@item --rosegment +@itemx --no-rosegment +Attempt to ensure that only a single read-only, non-code segment is +created. Only useful when used in conjunction with the @option{-z +separate-code} option. The resulting binaries should be smaller than +if @option{-z separate-code} is used on its own. Without this option, +or if @option{--no-rosegment} is specified, the @option{-z separate-code} +option will create two read-only segments, one before the code segment +and one after it. + +The name of the options are misleading, but they have been chosen in +order for the linker to be compatible with the LLD and GOLD linkers. + +Thse options are only supported by ELF targets. + @kindex -s @kindex --strip-all @cindex strip all symbols diff --git a/ld/ldint.texi b/ld/ldint.texi index 2792a38901a..5549f50908d 100644 --- a/ld/ldint.texi +++ b/ld/ldint.texi @@ -252,18 +252,23 @@ Here is the list of values assigned to @code{LD_FLAG}. @item (empty) The script generated is used by default (when none of the following cases apply). The output has an extension of @file{.x}. + @item n The script generated is used when the linker is invoked with the @code{-n} option. The output has an extension of @file{.xn}. + @item N The script generated is used when the linker is invoked with the @code{-N} option. The output has an extension of @file{.xbn}. + @item r The script generated is used when the linker is invoked with the @code{-r} option. The output has an extension of @file{.xr}. + @item u The script generated is used when the linker is invoked with the @code{-Ur} option. The output has an extension of @file{.xu}. + @item shared The @file{scripttempl} script is only invoked with @code{LD_FLAG} set to this value if @code{GENERATE_SHLIB_SCRIPT} is defined in the @@ -271,14 +276,15 @@ this value if @code{GENERATE_SHLIB_SCRIPT} is defined= in the this script at the appropriate time, normally when the linker is invoked with the @code{-shared} option. The output has an extension of @file{.xs}. + @item c The @file{scripttempl} script is only invoked with @code{LD_FLAG} set to this value if @code{GENERATE_COMBRELOC_SCRIPT} is defined in the @file{emulparams} file or if @code{SCRIPT_NAME} is @code{elf}. The @file{emultempl} script must arrange to use this script at the appropriate time, normally when the linker is invoked with the @code{-z combreloc} -option. The output has an extension of -@file{.xc}. +option. The output has an extension of @file{.xc}. + @item cshared The @file{scripttempl} script is only invoked with @code{LD_FLAG} set to this value if @code{GENERATE_COMBRELOC_SCRIPT} is defined in the @@ -287,6 +293,62 @@ this value if @code{GENERATE_COMBRELOC_SCRIPT} is defi= ned in the The @file{emultempl} script must arrange to use this script at the appropriate time, normally when the linker is invoked with the @code{-shar= ed -z combreloc} option. The output has an extension of @file{.xsc}. + +@item wshared +Like @emph{cshared} but in addition to needing the @option{-shared} +and @option {-z combreloc} options, it also needs the +@option{-z relro} option. If the @option{-z now} option is also used +then the output has an extension of @file{.xsw}, otherwise it is +@file{.xsco}. + +@item pie +The @file{scripttempl} script is only invoked with @code{LD_FLAG} set to +this value if @code{GENERATE_PIE_SCRIPT} is defined in the +@file{emulparams} file. The @file{emultempl} script must arrange to use +this script at the appropriate time, normally when the linker is invoked +with the @code{-pie} option. The output has an extension of +@file{.xd}. + +In addition if the @file{scripttempl} script is also invoked with +@code{GENERATE_RELRO_SCRIPT} defined then a second script is created +with an extension of @file{.xdo} to match the @option{-pie} and +@option{-z relro} options. + +@item cpie +Like @code{pie} but this version is used when the @file{scripttempl} +script is invoked with both @code{GENERATE_PIE_SCRIPT} and +@code{GENERATE_COMBRELOC_SCRIPT} defined. The @file{emultempl} script +must arrange to use this script at the appropriate time, normally when +the linker is invoked with the @code{-pie} and @option{-z combreloc} +options. The output has an extension of @file{.xdc}. + +@item wpie +Like @code{cpie}, but in addition the @option{-z relro} and +@option{-z now} options need to be defined. The output has an +extension of @file{.xdw}. + +@item textonly +@item pietextonly +@item cpietextonly +@item wpietextonly + +@item ctextonly +@item wtextonly +@item sharedtextonly +@item csharedtextonly +@item wsharedtextonly + +@item rotextonly +@item roctextonly +@item rowtextonly +@item rosharedtextonly +@item rocsharedtextonly +@item rowsharedtextonly +@item ropietextonly +@item rocpietextonly +@item rowpietextonly + + @item auto_import The @file{scripttempl} script is only invoked with @code{LD_FLAG} set to this value if @code{GENERATE_AUTO_IMPORT_SCRIPT} is defined in the @@ -294,8 +356,10 @@ this value if @code{GENERATE_AUTO_IMPORT_SCRIPT} is de= fined in the use this script at the appropriate time, normally when the linker is invoked with the @code{--enable-auto-import} option. The output has an extension of @file{.xa}. + @end table =20 + Besides the shell variables set by the @file{emulparams} script, and the @code{LD_FLAG} variable, the @file{genscripts.sh} script will set certain variables for each run of the @file{scripttempl} script. diff --git a/ld/ldlex.h b/ld/ldlex.h index 7a0c3b4be94..defe3fcbbb9 100644 --- a/ld/ldlex.h +++ b/ld/ldlex.h @@ -287,6 +287,8 @@ enum option_values OPTION_PACKAGE_METADATA, OPTION_AUDIT, OPTION_COMPRESS_DEBUG, + OPTION_ROSEGMENT, + OPTION_NO_ROSEGMENT, /* Used by emultempl/hppaelf.em. */ OPTION_MULTI_SUBSPACE, /* Used by emultempl/ia64elf.em. */ diff --git a/ld/lexsup.c b/ld/lexsup.c index 4125d849f2c..5ceefb46424 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -2233,6 +2233,17 @@ elf_shlib_list_options (FILE *file) -z separate-code Create separate code program header\n")); fprintf (file, _("\ -z noseparate-code Don't create separate code program header (d= efault)\n")); +#endif +#if DEFAULT_LD_ROSEGMENT + fprintf (file, _("\ + --rosegment With -z separate-code, create a single read-= only segment (default)\n")); + fprintf (file, _("\ + --no-rosegment With -z separate-code, creste two read-only = segments\n")); +#else + fprintf (file, _("\ + --rosegment With -z separate-code, create a single read-= only segment\n")); + fprintf (file, _("\ + --no-rosegment With -z separate-code, creste two read-only = segments (default)\n")); #endif fprintf (file, _("\ -z common Generate common symbols with STT_COMMON type= \n")); diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index d5022fa502f..f1a61e7bcee 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -80,6 +80,8 @@ # for standard sections, without initial "." or suffixes. # SYMBOL_ABI_ALIGNMENT - minimum alignment in bytes which needs to be # applied to every symbol definition +# ALL_TEXT_BEFORE_RO - put all code sections before read-only +# sections # # When adding sections, do note that the names of some sections are used # when specifying the start address of the next. @@ -367,6 +369,11 @@ SHLIB_TEXT_START_ADDR=3D"SEGMENT_START(\"text-segment\= ", ${SHLIB_TEXT_START_ADDR:- # between .plt and .text. if test -z "$TINY_READONLY_SECTION"; then case "$LD_FLAG" in + *ro*textonly*) + ALL_TEXT_BEFORE_RO=3D" " + SEPARATE_TEXT=3D" " + TEXT_SEGMENT_ALIGN=3D + ;; *textonly*) SEPARATE_TEXT=3D" " TEXT_SEGMENT_ALIGN=3D". =3D ALIGN(${MAXPAGESIZE});" @@ -387,6 +394,11 @@ else test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS=3D"${TEXT_START_ADD= R}" fi =20 +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D +# Functions for generating parts of the linker script + +emit_header() +{ cat < ldscripts/dyntmp.$$ < $COMBRELOC" fi + eval $COMBRELOCCAT <> ldscripts/dyntmp.$$ <