ld: Pass -z textoff to linker for tests with DT_TEXTREL

Message ID 20200525033644.3487471-1-hjl.tools@gmail.com
State New
Headers show
Series
  • ld: Pass -z textoff to linker for tests with DT_TEXTREL
Related show

Commit Message

Some linker tests need DT_TEXTREL.  Pass -z textoff to linker for these
tests so that they will pass with DT_TEXTREL check defaulting to warning
or error.

	* testsuite/ld-elf/eh6.d: Pass -z textoff to linker.
	* testsuite/ld-elf/ehdr_start-shared.d: Likewise.
	* testsuite/ld-elf/pr19539.d: Likewise.
	* testsuite/ld-elfvers/vers.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-i386/i386.exp: Likewise.
	* testsuite/ld-i386/nogot1.d: Likewise.
	* testsuite/ld-i386/pr19539.d: Likewise.
	* testsuite/ld-i386/pr19636-2a.d: Likewise.
	* testsuite/ld-i386/pr19636-2b.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-i386/pr19636-2d.d: Likewise.
	* testsuite/ld-i386/pr19636-2e.d: Likewise.
	* testsuite/ld-i386/pr19636-3d.d: Likewise.
	* testsuite/ld-i386/pr19636-3e.d: Likewise.
	* testsuite/ld-i386/pr19939b.d: Likewise.
	* testsuite/ld-i386/undefweaka.d: Likewise.
	* testsuite/ld-i386/undefweakb.d: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-size/size.exp: Likewise.
	* testsuite/ld-unique/unique.exp: Likewise.
	* testsuite/ld-x86-64/pie1.d: Likewise.
	* testsuite/ld-x86-64/pr19539a.d: Likewise.
	* testsuite/ld-x86-64/pr19539b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19807-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19807-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2e.d: Likewise.
	* testsuite/ld-x86-64/pr19939b.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
---
 ld/testsuite/ld-elf/eh6.d               |  2 +-
 ld/testsuite/ld-elf/ehdr_start-shared.d |  2 +-
 ld/testsuite/ld-elf/pr19539.d           |  2 +-
 ld/testsuite/ld-elfvers/vers.exp        |  2 +-
 ld/testsuite/ld-elfvsb/elfvsb.exp       |  3 +++
 ld/testsuite/ld-i386/i386.exp           | 18 +++++++++++-------
 ld/testsuite/ld-i386/nogot1.d           |  2 +-
 ld/testsuite/ld-i386/pr19539.d          |  2 +-
 ld/testsuite/ld-i386/pr19636-2a.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2b.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2c.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2d.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2e.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-3d.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-3e.d       |  2 +-
 ld/testsuite/ld-i386/pr19939b.d         |  2 +-
 ld/testsuite/ld-i386/undefweaka.d       |  2 +-
 ld/testsuite/ld-i386/undefweakb.d       |  2 +-
 ld/testsuite/ld-shared/shared.exp       |  3 +++
 ld/testsuite/ld-size/size.exp           |  6 +++---
 ld/testsuite/ld-unique/unique.exp       |  2 +-
 ld/testsuite/ld-x86-64/pie1.d           |  2 +-
 ld/testsuite/ld-x86-64/pr19539a.d       |  2 +-
 ld/testsuite/ld-x86-64/pr19539b.d       |  2 +-
 ld/testsuite/ld-x86-64/pr19636-1d.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19636-1e.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-1a.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-1b.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2b.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2c.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2d.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2e.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19939b.d       |  2 +-
 ld/testsuite/ld-x86-64/x86-64.exp       | 25 +++++++++++++++----------
 34 files changed, 64 insertions(+), 49 deletions(-)

-- 
2.26.2

Comments

Fangrui Song May 25, 2020, 4:21 a.m. | #1
Thanks for the patch. I think Gentoo people will also appreciate you
making the lead
(https://sourceware.org/bugzilla/show_bug.cgi?id=22909)
Just a question, why is the option -z textoff instead of -z notext

(Honestly these options all appear to be very misleading: -z notext
stands for "enabling text relocations" while -z text means "disabling
text relocations"
I cannot associated "textoff" with "enabling text relocations"...
)

On Sun, May 24, 2020 at 8:36 PM H.J. Lu via Binutils
<binutils@sourceware.org> wrote:
>

> Some linker tests need DT_TEXTREL.  Pass -z textoff to linker for these

> tests so that they will pass with DT_TEXTREL check defaulting to warning

> or error.

>

>         * testsuite/ld-elf/eh6.d: Pass -z textoff to linker.

>         * testsuite/ld-elf/ehdr_start-shared.d: Likewise.

>         * testsuite/ld-elf/pr19539.d: Likewise.

>         * testsuite/ld-elfvers/vers.exp: Likewise.

>         * testsuite/ld-elfvsb/elfvsb.exp: Likewise.

>         * testsuite/ld-i386/i386.exp: Likewise.

>         * testsuite/ld-i386/nogot1.d: Likewise.

>         * testsuite/ld-i386/pr19539.d: Likewise.

>         * testsuite/ld-i386/pr19636-2a.d: Likewise.

>         * testsuite/ld-i386/pr19636-2b.d: Likewise.

>         * testsuite/ld-i386/pr19636-2c.d: Likewise.

>         * testsuite/ld-i386/pr19636-2d.d: Likewise.

>         * testsuite/ld-i386/pr19636-2e.d: Likewise.

>         * testsuite/ld-i386/pr19636-3d.d: Likewise.

>         * testsuite/ld-i386/pr19636-3e.d: Likewise.

>         * testsuite/ld-i386/pr19939b.d: Likewise.

>         * testsuite/ld-i386/undefweaka.d: Likewise.

>         * testsuite/ld-i386/undefweakb.d: Likewise.

>         * testsuite/ld-shared/shared.exp: Likewise.

>         * testsuite/ld-size/size.exp: Likewise.

>         * testsuite/ld-unique/unique.exp: Likewise.

>         * testsuite/ld-x86-64/pie1.d: Likewise.

>         * testsuite/ld-x86-64/pr19539a.d: Likewise.

>         * testsuite/ld-x86-64/pr19539b.d: Likewise.

>         * testsuite/ld-x86-64/pr19636-1d.d: Likewise.

>         * testsuite/ld-x86-64/pr19636-1e.d: Likewise.

>         * testsuite/ld-x86-64/pr19807-1a.d: Likewise.

>         * testsuite/ld-x86-64/pr19807-1b.d: Likewise.

>         * testsuite/ld-x86-64/pr19807-2b.d: Likewise.

>         * testsuite/ld-x86-64/pr19807-2c.d: Likewise.

>         * testsuite/ld-x86-64/pr19807-2d.d: Likewise.

>         * testsuite/ld-x86-64/pr19807-2e.d: Likewise.

>         * testsuite/ld-x86-64/pr19939b.d: Likewise.

>         * testsuite/ld-x86-64/x86-64.exp: Likewise.

> ---

>  ld/testsuite/ld-elf/eh6.d               |  2 +-

>  ld/testsuite/ld-elf/ehdr_start-shared.d |  2 +-

>  ld/testsuite/ld-elf/pr19539.d           |  2 +-

>  ld/testsuite/ld-elfvers/vers.exp        |  2 +-

>  ld/testsuite/ld-elfvsb/elfvsb.exp       |  3 +++

>  ld/testsuite/ld-i386/i386.exp           | 18 +++++++++++-------

>  ld/testsuite/ld-i386/nogot1.d           |  2 +-

>  ld/testsuite/ld-i386/pr19539.d          |  2 +-

>  ld/testsuite/ld-i386/pr19636-2a.d       |  2 +-

>  ld/testsuite/ld-i386/pr19636-2b.d       |  2 +-

>  ld/testsuite/ld-i386/pr19636-2c.d       |  2 +-

>  ld/testsuite/ld-i386/pr19636-2d.d       |  2 +-

>  ld/testsuite/ld-i386/pr19636-2e.d       |  2 +-

>  ld/testsuite/ld-i386/pr19636-3d.d       |  2 +-

>  ld/testsuite/ld-i386/pr19636-3e.d       |  2 +-

>  ld/testsuite/ld-i386/pr19939b.d         |  2 +-

>  ld/testsuite/ld-i386/undefweaka.d       |  2 +-

>  ld/testsuite/ld-i386/undefweakb.d       |  2 +-

>  ld/testsuite/ld-shared/shared.exp       |  3 +++

>  ld/testsuite/ld-size/size.exp           |  6 +++---

>  ld/testsuite/ld-unique/unique.exp       |  2 +-

>  ld/testsuite/ld-x86-64/pie1.d           |  2 +-

>  ld/testsuite/ld-x86-64/pr19539a.d       |  2 +-

>  ld/testsuite/ld-x86-64/pr19539b.d       |  2 +-

>  ld/testsuite/ld-x86-64/pr19636-1d.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19636-1e.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19807-1a.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19807-1b.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19807-2b.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19807-2c.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19807-2d.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19807-2e.d     |  2 +-

>  ld/testsuite/ld-x86-64/pr19939b.d       |  2 +-

>  ld/testsuite/ld-x86-64/x86-64.exp       | 25 +++++++++++++++----------

>  34 files changed, 64 insertions(+), 49 deletions(-)

>

> diff --git a/ld/testsuite/ld-elf/eh6.d b/ld/testsuite/ld-elf/eh6.d

> index 69c4c85acd..4ea2ba5087 100644

> --- a/ld/testsuite/ld-elf/eh6.d

> +++ b/ld/testsuite/ld-elf/eh6.d

> @@ -1,5 +1,5 @@

>  #source: eh6.s

> -#ld: --gc-sections -shared

> +#ld: --gc-sections -shared -z textoff

>  #readelf: -wf -rW

>  #target: x86_64-*-linux-gnu* i?86-*-linux-gnu i?86-*-gnu*

>

> diff --git a/ld/testsuite/ld-elf/ehdr_start-shared.d b/ld/testsuite/ld-elf/ehdr_start-shared.d

> index 6cbaa3a341..a013588765 100644

> --- a/ld/testsuite/ld-elf/ehdr_start-shared.d

> +++ b/ld/testsuite/ld-elf/ehdr_start-shared.d

> @@ -1,5 +1,5 @@

>  #source: ehdr_start.s

> -#ld: -e _start -shared

> +#ld: -e _start -shared -z textoff

>  #nm: -n

>  #target: *-*-linux* *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi

>  #xfail: cris*-*-* frv-*-* ![check_shared_lib_support]

> diff --git a/ld/testsuite/ld-elf/pr19539.d b/ld/testsuite/ld-elf/pr19539.d

> index c9f91ce663..5a5685e7c2 100644

> --- a/ld/testsuite/ld-elf/pr19539.d

> +++ b/ld/testsuite/ld-elf/pr19539.d

> @@ -1,6 +1,6 @@

>  #source: start.s

>  #source: pr19539.s

> -#ld: -pie -T pr19539.t

> +#ld: -pie -T pr19539.t -z textoff

>  #readelf : --dyn-syms --wide

>  #target: *-*-linux* *-*-gnu* *-*-solaris* arm*-*-uclinuxfdpiceabi

>  #xfail: cris*-*-* ![check_pie_support]

> diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp

> index ed48e1a697..897bf3a3b0 100644

> --- a/ld/testsuite/ld-elfvers/vers.exp

> +++ b/ld/testsuite/ld-elfvers/vers.exp

> @@ -576,7 +576,7 @@ proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp

>    global shared

>    # Make sure that PLT is used since PLT is expected.

>    global PLT_CFLAGS

> -  build_binary $shared $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""

> +  build_binary "$shared -z textoff" $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""

>  }

>

>  proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } {

> diff --git a/ld/testsuite/ld-elfvsb/elfvsb.exp b/ld/testsuite/ld-elfvsb/elfvsb.exp

> index 58dea0b0c8..5f6cb2bd63 100644

> --- a/ld/testsuite/ld-elfvsb/elfvsb.exp

> +++ b/ld/testsuite/ld-elfvsb/elfvsb.exp

> @@ -142,6 +142,9 @@ proc visibility_test { visibility progname testname main sh1 sh2 dat args } {

>      if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {

>         set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"

>      }

> +    if { [is_elf_format] && [check_shared_lib_support] } {

> +       append shared " -Wl,-z,textoff"

> +    }

>      if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {

>         if { [ string match $visibility "hidden_undef" ]

>              && [regexp "undefined reference to \`\.?visibility\'" $link_output]

> diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp

> index e3a5f8b195..f5f5fdb5da 100644

> --- a/ld/testsuite/ld-i386/i386.exp

> +++ b/ld/testsuite/ld-i386/i386.exp

> @@ -181,7 +181,7 @@ set i386tests {

>        {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}}

>        "tlsbindesc"}

>      {"TLS -fno-pic -shared"

> -     "-shared -melf_i386 --no-ld-generated-unwind-info \

> +     "-shared -melf_i386 --no-ld-generated-unwind-info -z textoff \

>        -z noseparate-code --hash-style=sysv" ""

>       "--32" {tlsnopic1.s tlsnopic2.s}

>       {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}

> @@ -197,7 +197,8 @@ set i386tests {

>       {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}

>      {"TLS @indntpoff with %eax" "-melf_i386" "" "--32" {tlsindntpoff.s}

>       {{objdump -drj.text tlsindntpoff.dd}} "tlsindntpoff"}

> -    {"Reloc section order" "-shared -melf_i386 -z nocombreloc" "" "--32"

> +    {"Reloc section order"

> +     "-shared -melf_i386 -z nocombreloc -z textoff" "" "--32"

>       {reloc.s} {{objdump -hw reloc.d}} "reloc.so"}

>      {"Basic --emit-relocs support" "-shared -melf_i386 --emit-relocs" "" "--32"

>       {emit-relocs.s} {{readelf --relocs emit-relocs.rd}} "emit-relocs.so"}

> @@ -238,10 +239,13 @@ set i386tests {

>      {"Build pr19827b.so" "-melf_i386 -shared" ""

>       "--32 -mx86-used-note=yes"

>       { pr19827b.S } {} "pr19827b.so"}

> -    {"Build pr19827" "-melf_i386 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""

> +    {"Build pr19827"

> +     "-melf_i386 -pie -z textoff tmpdir/pr19827a.o tmpdir/pr19827b.so"

> +     ""

>       "--32 -mx86-used-note=yes"

>       { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}

> -    {"Build pr19827.so" "-melf_i386 -shared -Bsymbolic" ""

> +    {"Build pr19827.so"

> +     "-melf_i386 -shared -Bsymbolic -z textoff" ""

>       "--32 -mx86-used-note=yes"

>       { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}

>  }

> @@ -1316,7 +1320,7 @@ if { [isnative]

>      run_cc_link_tests [list \

>         [list \

>             "Build pr22001-1.so" \

> -           "-shared" \

> +           "-shared -Wl,-z,textoff" \

>             "-Wa,-mx86-used-note=yes" \

>             { pr22001-1a.c } \

>             {} \

> @@ -1352,7 +1356,7 @@ if { [isnative]

>         ] \

>         [list \

>             "Run pr22001-1" \

> -           "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \

> +           "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,textoff tmpdir/pr22001-1.so" \

>             "-Wa,-mx86-used-note=yes" \

>             { pr22001-1b.c } \

>             "pr22001-1" \

> @@ -1395,7 +1399,7 @@ if { [isnative]

>         ] \

>         [list \

>             "Run pr21997-1" \

> -           "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \

> +           "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/pr21997-1.so" \

>             "-Wa,-mx86-used-note=yes" \

>             { pr21997-1b.c } \

>             "pr21997-1" \

> diff --git a/ld/testsuite/ld-i386/nogot1.d b/ld/testsuite/ld-i386/nogot1.d

> index 018c24d3a9..0ee92d965a 100644

> --- a/ld/testsuite/ld-i386/nogot1.d

> +++ b/ld/testsuite/ld-i386/nogot1.d

> @@ -1,4 +1,4 @@

> -#ld: --shared -melf_i386

> +#ld: --shared -melf_i386 -z textoff

>  #readelf: -S --wide

>  #as: --32

>

> diff --git a/ld/testsuite/ld-i386/pr19539.d b/ld/testsuite/ld-i386/pr19539.d

> index 7fe6e89a0d..1d02599481 100644

> --- a/ld/testsuite/ld-i386/pr19539.d

> +++ b/ld/testsuite/ld-i386/pr19539.d

> @@ -1,5 +1,5 @@

>  #as: --32

> -#ld: -pie -m elf_i386 -T pr19539.t

> +#ld: -pie -m elf_i386 -T pr19539.t -z textoff

>  #readelf: -r --wide

>

>  Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-i386/pr19636-2a.d b/ld/testsuite/ld-i386/pr19636-2a.d

> index a3eafecb3b..f03598464e 100644

> --- a/ld/testsuite/ld-i386/pr19636-2a.d

> +++ b/ld/testsuite/ld-i386/pr19636-2a.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-2.s

>  #as: --32 -mrelax-relocations=no

> -#ld: -pie -m elf_i386

> +#ld: -pie -m elf_i386 -z textoff

>  #readelf : -r --wide -x .got -x .got.plt --dyn-syms

>

>  Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-i386/pr19636-2b.d b/ld/testsuite/ld-i386/pr19636-2b.d

> index 57965f2775..8973e3f787 100644

> --- a/ld/testsuite/ld-i386/pr19636-2b.d

> +++ b/ld/testsuite/ld-i386/pr19636-2b.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-2.s

>  #as: --32 -mrelax-relocations=no

> -#ld: -pie -E -m elf_i386

> +#ld: -pie -E -m elf_i386 -z textoff

>  #readelf : -r --wide -x .got -x .got.plt --dyn-syms

>

>  Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-i386/pr19636-2c.d b/ld/testsuite/ld-i386/pr19636-2c.d

> index 3c7cd6def3..0dc722fb63 100644

> --- a/ld/testsuite/ld-i386/pr19636-2c.d

> +++ b/ld/testsuite/ld-i386/pr19636-2c.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-2.s

>  #as: --32 -mrelax-relocations=no

> -#ld: -pie -m elf_i386

> +#ld: -pie -m elf_i386 -z textoff

>  #objdump: -dw

>  #notarget: i?86-*-nacl* x86_64-*-nacl*

>

> diff --git a/ld/testsuite/ld-i386/pr19636-2d.d b/ld/testsuite/ld-i386/pr19636-2d.d

> index 28eaa04d2b..363e0f64b8 100644

> --- a/ld/testsuite/ld-i386/pr19636-2d.d

> +++ b/ld/testsuite/ld-i386/pr19636-2d.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-2.s

>  #as: --32 -mrelax-relocations=no

> -#ld: -shared -m elf_i386

> +#ld: -shared -m elf_i386 -z textoff

>  #readelf : -r --wide --dyn-syms

>  #notarget: i?86-*-nacl* x86_64-*-nacl*

>

> diff --git a/ld/testsuite/ld-i386/pr19636-2e.d b/ld/testsuite/ld-i386/pr19636-2e.d

> index 148e3060a7..51b32a1e52 100644

> --- a/ld/testsuite/ld-i386/pr19636-2e.d

> +++ b/ld/testsuite/ld-i386/pr19636-2e.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-2.s

>  #as: --32 -mrelax-relocations=no

> -#ld: -shared -Bsymbolic -m elf_i386

> +#ld: -shared -Bsymbolic -m elf_i386 -z textoff

>  #readelf : -r --wide --dyn-syms

>  #notarget: i?86-*-nacl* x86_64-*-nacl*

>

> diff --git a/ld/testsuite/ld-i386/pr19636-3d.d b/ld/testsuite/ld-i386/pr19636-3d.d

> index 7004bb14f0..b7e691ac26 100644

> --- a/ld/testsuite/ld-i386/pr19636-3d.d

> +++ b/ld/testsuite/ld-i386/pr19636-3d.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-3.s

>  #as: --32

> -#ld: -shared -m elf_i386

> +#ld: -shared -m elf_i386 -z textoff

>  #readelf : -r --wide --dyn-syms

>

>  Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):

> diff --git a/ld/testsuite/ld-i386/pr19636-3e.d b/ld/testsuite/ld-i386/pr19636-3e.d

> index aeb4e7e171..c2693560d7 100644

> --- a/ld/testsuite/ld-i386/pr19636-3e.d

> +++ b/ld/testsuite/ld-i386/pr19636-3e.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-3.s

>  #as: --32

> -#ld: -shared -Bsymbolic -m elf_i386

> +#ld: -shared -Bsymbolic -m elf_i386 -z textoff

>  #readelf : -r --wide --dyn-syms

>

>  Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):

> diff --git a/ld/testsuite/ld-i386/pr19939b.d b/ld/testsuite/ld-i386/pr19939b.d

> index 5124ae10dc..a90cfd9d12 100644

> --- a/ld/testsuite/ld-i386/pr19939b.d

> +++ b/ld/testsuite/ld-i386/pr19939b.d

> @@ -1,6 +1,6 @@

>  #source: pr19939.s

>  #as: --32

> -#ld: -melf_i386 -shared

> +#ld: -melf_i386 -shared -z textoff

>  #readelf: -d --wide

>

>  #...

> diff --git a/ld/testsuite/ld-i386/undefweaka.d b/ld/testsuite/ld-i386/undefweaka.d

> index c106ebf54f..a970aaeb45 100644

> --- a/ld/testsuite/ld-i386/undefweaka.d

> +++ b/ld/testsuite/ld-i386/undefweaka.d

> @@ -1,6 +1,6 @@

>  #source: undefweak.s

>  #as: --32

> -#ld: -shared -melf_i386

> +#ld: -shared -melf_i386 -z textoff

>  #readelf: -r --wide

>

>  Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 2 entries:

> diff --git a/ld/testsuite/ld-i386/undefweakb.d b/ld/testsuite/ld-i386/undefweakb.d

> index e6d6d5f7c3..446519a080 100644

> --- a/ld/testsuite/ld-i386/undefweakb.d

> +++ b/ld/testsuite/ld-i386/undefweakb.d

> @@ -1,6 +1,6 @@

>  #source: undefweak.s

>  #as: --32

> -#ld: -pie -melf_i386

> +#ld: -pie -melf_i386 -z textoff

>  #readelf: -r --wide -x .data.rel.ro

>

>  Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp

> index 32cdbe8a41..f9e980f22a 100644

> --- a/ld/testsuite/ld-shared/shared.exp

> +++ b/ld/testsuite/ld-shared/shared.exp

> @@ -133,6 +133,9 @@ proc shared_test { progname testname main sh1 sh2 dat args } {

>      if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {

>         set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"

>      }

> +    if { [is_elf_format] && [check_shared_lib_support] } {

> +       append shared " -Wl,-z,textoff"

> +    }

>      if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {

>          fail "$testname"

>         return

> diff --git a/ld/testsuite/ld-size/size.exp b/ld/testsuite/ld-size/size.exp

> index 23b0b87558..9a171c1693 100644

> --- a/ld/testsuite/ld-size/size.exp

> +++ b/ld/testsuite/ld-size/size.exp

> @@ -114,7 +114,7 @@ run_cc_link_tests [list \

>      ] \

>      [list \

>         "Build size-7" \

> -       "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \

> +       "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/libsize-7.so" \

>         "$NOPIE_CFLAGS" \

>         {size-7a.c} \

>         {{readelf -rW size-7.rd}} \

> @@ -129,7 +129,7 @@ run_cc_link_tests [list \

>      ] \

>      [list \

>         "Build size-8" \

> -       "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \

> +       "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/libsize-8.so" \

>         "$NOPIE_CFLAGS" \

>         {size-8a.c} \

>         {{readelf -rW size-8.rd}} \

> @@ -277,7 +277,7 @@ run_ld_link_exec_tests [list \

>      ] \

>      [list \

>         "Run size-8" \

> -       "$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu \

> +       "$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu,-z,textoff \

>          tmpdir/libsize-8.so" \

>         "" \

>         {size-8a.c} \

> diff --git a/ld/testsuite/ld-unique/unique.exp b/ld/testsuite/ld-unique/unique.exp

> index 0775c7d64a..5dec7ec7b5 100644

> --- a/ld/testsuite/ld-unique/unique.exp

> +++ b/ld/testsuite/ld-unique/unique.exp

> @@ -208,7 +208,7 @@ if {![ld_link "$CC $board_cflags" "tmpdir/unique_shared_prog" "-Ltmpdir tmpdir/u

>  }

>

>  # Create shared library containing unique symbol with reference.

> -if {![ld_link $ld "tmpdir/libunique_shared_ref.so" "-shared tmpdir/unique_shared.o tmpdir/unique_empty.o"] } {

> +if {![ld_link $ld "tmpdir/libunique_shared_ref.so" "-shared -z textoff tmpdir/unique_shared.o tmpdir/unique_empty.o"] } {

>      fail "Could not create a shared library containing an unique symbol with reference"

>      set fails [expr $fails + 1]

>  }

> diff --git a/ld/testsuite/ld-x86-64/pie1.d b/ld/testsuite/ld-x86-64/pie1.d

> index 3e64c150bc..a1bd27fd33 100644

> --- a/ld/testsuite/ld-x86-64/pie1.d

> +++ b/ld/testsuite/ld-x86-64/pie1.d

> @@ -1,6 +1,6 @@

>  #name: PIE with undefined symbol

>  #as: --64

> -#ld: -pie -melf_x86_64 --noinhibit-exec

> +#ld: -pie -melf_x86_64 --noinhibit-exec -z textoff

>  #readelf: -s --wide

>  #warning: \A[^\n]*\.o[^\n]*in function `_start':\n[^\n]*: undefined reference to `foo'\Z

>

> diff --git a/ld/testsuite/ld-x86-64/pr19539a.d b/ld/testsuite/ld-x86-64/pr19539a.d

> index 8c456d8482..e85fb90b14 100644

> --- a/ld/testsuite/ld-x86-64/pr19539a.d

> +++ b/ld/testsuite/ld-x86-64/pr19539a.d

> @@ -1,6 +1,6 @@

>  #source: pr19539.s

>  #as: --64

> -#ld: -pie -m elf_x86_64 -T pr19539.t

> +#ld: -pie -m elf_x86_64 -T pr19539.t -z textoff

>  #readelf: -r --wide

>

>  Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-x86-64/pr19539b.d b/ld/testsuite/ld-x86-64/pr19539b.d

> index f338987def..86dc47e0de 100644

> --- a/ld/testsuite/ld-x86-64/pr19539b.d

> +++ b/ld/testsuite/ld-x86-64/pr19539b.d

> @@ -1,6 +1,6 @@

>  #source: pr19539.s

>  #as: --x32

> -#ld: -pie -m elf32_x86_64 -T pr19539.t

> +#ld: -pie -m elf32_x86_64 -T pr19539.t -z textoff

>  #readelf: -r --wide

>

>  Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-x86-64/pr19636-1d.d b/ld/testsuite/ld-x86-64/pr19636-1d.d

> index ccab633190..50f5e1e9a6 100644

> --- a/ld/testsuite/ld-x86-64/pr19636-1d.d

> +++ b/ld/testsuite/ld-x86-64/pr19636-1d.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-1.s

>  #as: --64

> -#ld: -shared -m elf_x86_64

> +#ld: -shared -m elf_x86_64 -z textoff

>  #readelf : -r --wide --dyn-syms

>

>  Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):

> diff --git a/ld/testsuite/ld-x86-64/pr19636-1e.d b/ld/testsuite/ld-x86-64/pr19636-1e.d

> index 8516149390..472d14a381 100644

> --- a/ld/testsuite/ld-x86-64/pr19636-1e.d

> +++ b/ld/testsuite/ld-x86-64/pr19636-1e.d

> @@ -1,6 +1,6 @@

>  #source: pr19636-1.s

>  #as: --64

> -#ld: -shared -Bsymbolic -m elf_x86_64

> +#ld: -shared -Bsymbolic -m elf_x86_64 -z textoff

>  #readelf : -r --wide --dyn-syms

>

>  Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):

> diff --git a/ld/testsuite/ld-x86-64/pr19807-1a.d b/ld/testsuite/ld-x86-64/pr19807-1a.d

> index f3c5390b28..fbb8b159ac 100644

> --- a/ld/testsuite/ld-x86-64/pr19807-1a.d

> +++ b/ld/testsuite/ld-x86-64/pr19807-1a.d

> @@ -1,6 +1,6 @@

>  #source: pr19807-1.s

>  #as: --64

> -#ld: -pie -melf_x86_64 -z noreloc-overflow

> +#ld: -pie -melf_x86_64 -z noreloc-overflow -z textoff

>  #objdump: -dw

>

>  .*: +file format .*

> diff --git a/ld/testsuite/ld-x86-64/pr19807-1b.d b/ld/testsuite/ld-x86-64/pr19807-1b.d

> index 6af4985463..3b9b3c2c41 100644

> --- a/ld/testsuite/ld-x86-64/pr19807-1b.d

> +++ b/ld/testsuite/ld-x86-64/pr19807-1b.d

> @@ -1,6 +1,6 @@

>  #source: pr19807-1.s

>  #as: --x32

> -#ld: -pie -melf32_x86_64 -z noreloc-overflow

> +#ld: -pie -melf32_x86_64 -z noreloc-overflow -z textoff

>  #objdump: -dw

>

>  .*: +file format .*

> diff --git a/ld/testsuite/ld-x86-64/pr19807-2b.d b/ld/testsuite/ld-x86-64/pr19807-2b.d

> index 44205f2308..98cca8465d 100644

> --- a/ld/testsuite/ld-x86-64/pr19807-2b.d

> +++ b/ld/testsuite/ld-x86-64/pr19807-2b.d

> @@ -1,6 +1,6 @@

>  #source: pr19807-2.s

>  #as: --x32

> -#ld: -pie -melf32_x86_64

> +#ld: -pie -melf32_x86_64 -z textoff

>  #readelf: -r --wide

>

>  Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-x86-64/pr19807-2c.d b/ld/testsuite/ld-x86-64/pr19807-2c.d

> index 83ac641624..cd6e563492 100644

> --- a/ld/testsuite/ld-x86-64/pr19807-2c.d

> +++ b/ld/testsuite/ld-x86-64/pr19807-2c.d

> @@ -1,6 +1,6 @@

>  #source: pr19807-2.s

>  #as: --x32

> -#ld: -pie -melf32_x86_64

> +#ld: -pie -melf32_x86_64 -z textoff

>  #objdump: -dw

>

>  .*: +file format .*

> diff --git a/ld/testsuite/ld-x86-64/pr19807-2d.d b/ld/testsuite/ld-x86-64/pr19807-2d.d

> index 5394615158..b9ae5cbaec 100644

> --- a/ld/testsuite/ld-x86-64/pr19807-2d.d

> +++ b/ld/testsuite/ld-x86-64/pr19807-2d.d

> @@ -1,6 +1,6 @@

>  #source: pr19807-2.s

>  #as: --64

> -#ld: -pie -melf_x86_64 -z noreloc-overflow

> +#ld: -pie -melf_x86_64 -z noreloc-overflow -z textoff

>  #readelf: -r --wide

>

>  Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:

> diff --git a/ld/testsuite/ld-x86-64/pr19807-2e.d b/ld/testsuite/ld-x86-64/pr19807-2e.d

> index f26616a20a..fd08746d3e 100644

> --- a/ld/testsuite/ld-x86-64/pr19807-2e.d

> +++ b/ld/testsuite/ld-x86-64/pr19807-2e.d

> @@ -1,6 +1,6 @@

>  #source: pr19807-2.s

>  #as: --64

> -#ld: -pie -melf_x86_64 -z noreloc-overflow

> +#ld: -pie -melf_x86_64 -z noreloc-overflow -z textoff

>  #objdump: -dw

>

>  .*: +file format .*

> diff --git a/ld/testsuite/ld-x86-64/pr19939b.d b/ld/testsuite/ld-x86-64/pr19939b.d

> index 2616151550..a5605bf260 100644

> --- a/ld/testsuite/ld-x86-64/pr19939b.d

> +++ b/ld/testsuite/ld-x86-64/pr19939b.d

> @@ -1,6 +1,6 @@

>  #source: pr19939.s

>  #as: --64

> -#ld: -melf_x86_64 -shared

> +#ld: -melf_x86_64 -shared -z textoff

>  #readelf: -d --wide

>

>  #...

> diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp

> index 9db16c6b6e..f955f63dc3 100644

> --- a/ld/testsuite/ld-x86-64/x86-64.exp

> +++ b/ld/testsuite/ld-x86-64/x86-64.exp

> @@ -212,9 +212,12 @@ set x86_64tests {

>       "--64" { pr19827a.S }}

>      {"Build pr19827b.so" "-melf_x86_64 -shared" ""

>       "--64" { pr19827b.S } {} "pr19827b.so"}

> -    {"Build pr19827" "-melf_x86_64 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""

> +    {"Build pr19827"

> +     "-melf_x86_64 -pie -z textoff tmpdir/pr19827a.o tmpdir/pr19827b.so"

> +     ""

>       "--64" { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}

> -    {"Build pr19827.so" "-melf_x86_64 -shared -Bsymbolic" ""

> +    {"Build pr19827.so"

> +     "-melf_x86_64 -shared -Bsymbolic -z textoff" ""

>       "--64" { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}

>      {"Build pr19969.so" "-melf_x86_64 -shared" ""

>       "--64" { pr19969a.S } {} "pr19969.so"}

> @@ -222,7 +225,9 @@ set x86_64tests {

>       "--64" { pr20550a.s }}

>      {"Build pr20550b.so" "-melf_x86_64 -shared" ""

>       "--64" { pr20550b.s } {} "pr20550b.so"}

> -    {"Build pr20550" "-melf_x86_64 -pie tmpdir/pr20550a.o tmpdir/pr20550b.so" ""

> +    {"Build pr20550"

> +     "-melf_x86_64 -pie -z textoff tmpdir/pr20550a.o tmpdir/pr20550b.so"

> +     ""

>       "--64" { dummy.s } {} "pr20550"}

>  }

>

> @@ -1172,7 +1177,7 @@ if { [isnative] && [check_compiler_available] } {

>         ] \

>         [list \

>             "Build pr22001-1a" \

> -           "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \

> +           "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,textoff tmpdir/pr22001-1.so" \

>             "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \

>             { pr22001-1b.c } \

>             {{error_output "pr22001-1a.err"}} \

> @@ -1188,7 +1193,7 @@ if { [isnative] && [check_compiler_available] } {

>         ] \

>         [list \

>             "Build pr21997-1a" \

> -           "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \

> +           "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/pr21997-1.so" \

>             "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \

>             { pr21997-1b.c } \

>             {{error_output "pr21997-1a.err"}} \

> @@ -1263,7 +1268,7 @@ if { [isnative] && [check_compiler_available] } {

>         ] \

>         [list \

>             "Build pr22791-1" \

> -           "-pie -Wl,--no-as-needed tmpdir/pr22791-1.so" \

> +           "-pie -Wl,--no-as-needed,-z,textoff tmpdir/pr22791-1.so" \

>             "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \

>             { pr22791-1b.s } \

>             {{error_output "pr22791-1.err"}} \

> @@ -1359,7 +1364,7 @@ if { [isnative] && [check_compiler_available] } {

>         run_ld_link_exec_tests [list \

>             [list \

>                 "Run pr22001-1b" \

> -               "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \

> +               "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,textoff tmpdir/pr22001-1.so" \

>                 "-Wa,-mx86-used-note=yes" \

>                 { pr22001-1c.c } \

>                 "pr22001-1b" \

> @@ -1368,7 +1373,7 @@ if { [isnative] && [check_compiler_available] } {

>             ] \

>             [list \

>                 "Run pr21997-1b" \

> -               "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \

> +               "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/pr21997-1.so" \

>                 "-Wa,-mx86-used-note=yes" \

>                 { pr21997-1c.c } \

>                 "pr21997-1b" \

> @@ -1422,7 +1427,7 @@ if { [isnative] && [check_compiler_available] } {

>             ] \

>             [list \

>                 "Run pr25416-5f (PIE GDesc -> LE -maddress-mode=short)" \

> -               "-pie tmpdir/pr25416-5b.o tmpdir/pr25416-5d.o" \

> +               "-pie -Wl,-z,textoff tmpdir/pr25416-5b.o tmpdir/pr25416-5d.o" \

>                 "-Wa,-mx86-used-note=yes" \

>                 { pr25416-5a.c } \

>                 "pr25416-5f" \

> @@ -1430,7 +1435,7 @@ if { [isnative] && [check_compiler_available] } {

>             ] \

>             [list \

>                 "Run pr25416-5g (PIE GDesc -> LE -maddress-mode=long)" \

> -               "-pie tmpdir/pr25416-5c.o tmpdir/pr25416-5d.o" \

> +               "-pie -Wl,-z,textoff tmpdir/pr25416-5c.o tmpdir/pr25416-5d.o" \

>                 "-Wa,-mx86-used-note=yes" \

>                 { pr25416-5a.c } \

>                 "pr25416-5g" \

> --

> 2.26.2

>
On Sun, May 24, 2020 at 9:30 PM Fangrui Song <i@maskray.me> wrote:
>

> Thanks for the patch. I think Gentoo people will also appreciate you

> making the lead

> (https://sourceware.org/bugzilla/show_bug.cgi?id=22909)

> Just a question, why is the option -z textoff instead of -z notext


This is the patch I am checking in.

> (Honestly these options all appear to be very misleading: -z notext

> stands for "enabling text relocations" while -z text means "disabling

> text relocations"

> I cannot associated "textoff" with "enabling text relocations"...

> )


We can't change these options now.

> On Sun, May 24, 2020 at 8:36 PM H.J. Lu via Binutils

> <binutils@sourceware.org> wrote:

> >

> > Some linker tests need DT_TEXTREL.  Pass -z textoff to linker for these

> > tests so that they will pass with DT_TEXTREL check defaulting to warning

> > or error.

> >

> >         * testsuite/ld-elf/eh6.d: Pass -z textoff to linker.

> >         * testsuite/ld-elf/ehdr_start-shared.d: Likewise.

> >         * testsuite/ld-elf/pr19539.d: Likewise.

> >         * testsuite/ld-elfvers/vers.exp: Likewise.

> >         * testsuite/ld-elfvsb/elfvsb.exp: Likewise.

> >         * testsuite/ld-i386/i386.exp: Likewise.

> >         * testsuite/ld-i386/nogot1.d: Likewise.

> >         * testsuite/ld-i386/pr19539.d: Likewise.

> >         * testsuite/ld-i386/pr19636-2a.d: Likewise.

> >         * testsuite/ld-i386/pr19636-2b.d: Likewise.

> >         * testsuite/ld-i386/pr19636-2c.d: Likewise.

> >         * testsuite/ld-i386/pr19636-2d.d: Likewise.

> >         * testsuite/ld-i386/pr19636-2e.d: Likewise.

> >         * testsuite/ld-i386/pr19636-3d.d: Likewise.

> >         * testsuite/ld-i386/pr19636-3e.d: Likewise.

> >         * testsuite/ld-i386/pr19939b.d: Likewise.

> >         * testsuite/ld-i386/undefweaka.d: Likewise.

> >         * testsuite/ld-i386/undefweakb.d: Likewise.

> >         * testsuite/ld-shared/shared.exp: Likewise.

> >         * testsuite/ld-size/size.exp: Likewise.

> >         * testsuite/ld-unique/unique.exp: Likewise.

> >         * testsuite/ld-x86-64/pie1.d: Likewise.

> >         * testsuite/ld-x86-64/pr19539a.d: Likewise.

> >         * testsuite/ld-x86-64/pr19539b.d: Likewise.

> >         * testsuite/ld-x86-64/pr19636-1d.d: Likewise.

> >         * testsuite/ld-x86-64/pr19636-1e.d: Likewise.

> >         * testsuite/ld-x86-64/pr19807-1a.d: Likewise.

> >         * testsuite/ld-x86-64/pr19807-1b.d: Likewise.

> >         * testsuite/ld-x86-64/pr19807-2b.d: Likewise.

> >         * testsuite/ld-x86-64/pr19807-2c.d: Likewise.

> >         * testsuite/ld-x86-64/pr19807-2d.d: Likewise.

> >         * testsuite/ld-x86-64/pr19807-2e.d: Likewise.

> >         * testsuite/ld-x86-64/pr19939b.d: Likewise.

> >         * testsuite/ld-x86-64/x86-64.exp: Likewise.



-- 
H.J.
From c839723917e92b3cd6a9f8348da261e4f0333b42 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sun, 24 May 2020 20:17:50 -0700
Subject: [PATCH] ld: Pass -z notext to linker for tests with DT_TEXTREL

Some linker tests need DT_TEXTREL.  Pass -z notext to linker for these
tests so that they will pass with DT_TEXTREL check defaulting to warning
or error.

	* testsuite/ld-elf/eh6.d: Pass -z notext to linker.
	* testsuite/ld-elf/ehdr_start-shared.d: Likewise.
	* testsuite/ld-elf/pr19539.d: Likewise.
	* testsuite/ld-elfvers/vers.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-i386/i386.exp: Likewise.
	* testsuite/ld-i386/nogot1.d: Likewise.
	* testsuite/ld-i386/pr19539.d: Likewise.
	* testsuite/ld-i386/pr19636-2a.d: Likewise.
	* testsuite/ld-i386/pr19636-2b.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-i386/pr19636-2d.d: Likewise.
	* testsuite/ld-i386/pr19636-2e.d: Likewise.
	* testsuite/ld-i386/pr19636-3d.d: Likewise.
	* testsuite/ld-i386/pr19636-3e.d: Likewise.
	* testsuite/ld-i386/pr19939b.d: Likewise.
	* testsuite/ld-i386/undefweaka.d: Likewise.
	* testsuite/ld-i386/undefweakb.d: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-size/size.exp: Likewise.
	* testsuite/ld-unique/unique.exp: Likewise.
	* testsuite/ld-x86-64/pie1.d: Likewise.
	* testsuite/ld-x86-64/pr19539a.d: Likewise.
	* testsuite/ld-x86-64/pr19539b.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-1e.d: Likewise.
	* testsuite/ld-x86-64/pr19807-1a.d: Likewise.
	* testsuite/ld-x86-64/pr19807-1b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2b.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2c.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19807-2e.d: Likewise.
	* testsuite/ld-x86-64/pr19939b.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
---
 ld/testsuite/ld-elf/eh6.d               |  2 +-
 ld/testsuite/ld-elf/ehdr_start-shared.d |  2 +-
 ld/testsuite/ld-elf/pr19539.d           |  2 +-
 ld/testsuite/ld-elfvers/vers.exp        |  2 +-
 ld/testsuite/ld-elfvsb/elfvsb.exp       |  3 +++
 ld/testsuite/ld-i386/i386.exp           | 18 +++++++++++-------
 ld/testsuite/ld-i386/nogot1.d           |  2 +-
 ld/testsuite/ld-i386/pr19539.d          |  2 +-
 ld/testsuite/ld-i386/pr19636-2a.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2b.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2c.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2d.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-2e.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-3d.d       |  2 +-
 ld/testsuite/ld-i386/pr19636-3e.d       |  2 +-
 ld/testsuite/ld-i386/pr19939b.d         |  2 +-
 ld/testsuite/ld-i386/undefweaka.d       |  2 +-
 ld/testsuite/ld-i386/undefweakb.d       |  2 +-
 ld/testsuite/ld-shared/shared.exp       |  3 +++
 ld/testsuite/ld-size/size.exp           |  6 +++---
 ld/testsuite/ld-unique/unique.exp       |  2 +-
 ld/testsuite/ld-x86-64/pie1.d           |  2 +-
 ld/testsuite/ld-x86-64/pr19539a.d       |  2 +-
 ld/testsuite/ld-x86-64/pr19539b.d       |  2 +-
 ld/testsuite/ld-x86-64/pr19636-1d.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19636-1e.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-1a.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-1b.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2b.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2c.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2d.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19807-2e.d     |  2 +-
 ld/testsuite/ld-x86-64/pr19939b.d       |  2 +-
 ld/testsuite/ld-x86-64/x86-64.exp       | 25 +++++++++++++++----------
 34 files changed, 64 insertions(+), 49 deletions(-)

diff --git a/ld/testsuite/ld-elf/eh6.d b/ld/testsuite/ld-elf/eh6.d
index 69c4c85acd..08e9d7b2bd 100644
--- a/ld/testsuite/ld-elf/eh6.d
+++ b/ld/testsuite/ld-elf/eh6.d
@@ -1,5 +1,5 @@
 #source: eh6.s
-#ld: --gc-sections -shared
+#ld: --gc-sections -shared -z notext
 #readelf: -wf -rW
 #target: x86_64-*-linux-gnu* i?86-*-linux-gnu i?86-*-gnu*
 
diff --git a/ld/testsuite/ld-elf/ehdr_start-shared.d b/ld/testsuite/ld-elf/ehdr_start-shared.d
index 6cbaa3a341..af6bec0a5a 100644
--- a/ld/testsuite/ld-elf/ehdr_start-shared.d
+++ b/ld/testsuite/ld-elf/ehdr_start-shared.d
@@ -1,5 +1,5 @@
 #source: ehdr_start.s
-#ld: -e _start -shared
+#ld: -e _start -shared -z notext
 #nm: -n
 #target: *-*-linux* *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
 #xfail: cris*-*-* frv-*-* ![check_shared_lib_support] 
diff --git a/ld/testsuite/ld-elf/pr19539.d b/ld/testsuite/ld-elf/pr19539.d
index c9f91ce663..56e6502ca6 100644
--- a/ld/testsuite/ld-elf/pr19539.d
+++ b/ld/testsuite/ld-elf/pr19539.d
@@ -1,6 +1,6 @@
 #source: start.s
 #source: pr19539.s
-#ld: -pie -T pr19539.t
+#ld: -pie -T pr19539.t -z notext
 #readelf : --dyn-syms --wide
 #target: *-*-linux* *-*-gnu* *-*-solaris* arm*-*-uclinuxfdpiceabi
 #xfail: cris*-*-* ![check_pie_support] 
diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp
index ed48e1a697..8efbac21b9 100644
--- a/ld/testsuite/ld-elfvers/vers.exp
+++ b/ld/testsuite/ld-elfvers/vers.exp
@@ -576,7 +576,7 @@ proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp
   global shared
   # Make sure that PLT is used since PLT is expected.
   global PLT_CFLAGS
-  build_binary $shared $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
+  build_binary "$shared -z notext" $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
 }
 
 proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } {
diff --git a/ld/testsuite/ld-elfvsb/elfvsb.exp b/ld/testsuite/ld-elfvsb/elfvsb.exp
index 58dea0b0c8..5e19d32ae6 100644
--- a/ld/testsuite/ld-elfvsb/elfvsb.exp
+++ b/ld/testsuite/ld-elfvsb/elfvsb.exp
@@ -142,6 +142,9 @@ proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
 	set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
     }
+    if { [is_elf_format] && [check_shared_lib_support] } {
+	append shared " -Wl,-z,notext"
+    }
     if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
 	if { [ string match $visibility "hidden_undef" ]
 	     && [regexp "undefined reference to \`\.?visibility\'" $link_output]
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index e3a5f8b195..2956c44c73 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -181,7 +181,7 @@ set i386tests {
       {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}}
       "tlsbindesc"}
     {"TLS -fno-pic -shared"
-     "-shared -melf_i386 --no-ld-generated-unwind-info \
+     "-shared -melf_i386 --no-ld-generated-unwind-info -z notext \
       -z noseparate-code --hash-style=sysv" ""
      "--32" {tlsnopic1.s tlsnopic2.s}
      {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}
@@ -197,7 +197,8 @@ set i386tests {
      {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
     {"TLS @indntpoff with %eax" "-melf_i386" "" "--32" {tlsindntpoff.s}
      {{objdump -drj.text tlsindntpoff.dd}} "tlsindntpoff"}
-    {"Reloc section order" "-shared -melf_i386 -z nocombreloc" "" "--32"
+    {"Reloc section order"
+     "-shared -melf_i386 -z nocombreloc -z notext" "" "--32"
      {reloc.s} {{objdump -hw reloc.d}} "reloc.so"}
     {"Basic --emit-relocs support" "-shared -melf_i386 --emit-relocs" "" "--32"
      {emit-relocs.s} {{readelf --relocs emit-relocs.rd}} "emit-relocs.so"}
@@ -238,10 +239,13 @@ set i386tests {
     {"Build pr19827b.so" "-melf_i386 -shared" ""
      "--32 -mx86-used-note=yes"
      { pr19827b.S } {} "pr19827b.so"}
-    {"Build pr19827" "-melf_i386 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""
+    {"Build pr19827"
+     "-melf_i386 -pie -z notext tmpdir/pr19827a.o tmpdir/pr19827b.so"
+     ""
      "--32 -mx86-used-note=yes"
      { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}
-    {"Build pr19827.so" "-melf_i386 -shared -Bsymbolic" ""
+    {"Build pr19827.so"
+     "-melf_i386 -shared -Bsymbolic -z notext" ""
      "--32 -mx86-used-note=yes"
      { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
 }
@@ -1316,7 +1320,7 @@ if { [isnative]
     run_cc_link_tests [list \
 	[list \
 	    "Build pr22001-1.so" \
-	    "-shared" \
+	    "-shared -Wl,-z,notext" \
 	    "-Wa,-mx86-used-note=yes" \
 	    { pr22001-1a.c } \
 	    {} \
@@ -1352,7 +1356,7 @@ if { [isnative]
 	] \
 	[list \
 	    "Run pr22001-1" \
-	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext tmpdir/pr22001-1.so" \
 	    "-Wa,-mx86-used-note=yes" \
 	    { pr22001-1b.c } \
 	    "pr22001-1" \
@@ -1395,7 +1399,7 @@ if { [isnative]
 	] \
 	[list \
 	    "Run pr21997-1" \
-	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
 	    "-Wa,-mx86-used-note=yes" \
 	    { pr21997-1b.c } \
 	    "pr21997-1" \
diff --git a/ld/testsuite/ld-i386/nogot1.d b/ld/testsuite/ld-i386/nogot1.d
index 018c24d3a9..0e721dc5ca 100644
--- a/ld/testsuite/ld-i386/nogot1.d
+++ b/ld/testsuite/ld-i386/nogot1.d
@@ -1,4 +1,4 @@
-#ld: --shared -melf_i386
+#ld: --shared -melf_i386 -z notext
 #readelf: -S --wide
 #as: --32
 
diff --git a/ld/testsuite/ld-i386/pr19539.d b/ld/testsuite/ld-i386/pr19539.d
index 7fe6e89a0d..f0644a3a84 100644
--- a/ld/testsuite/ld-i386/pr19539.d
+++ b/ld/testsuite/ld-i386/pr19539.d
@@ -1,5 +1,5 @@
 #as: --32
-#ld: -pie -m elf_i386 -T pr19539.t
+#ld: -pie -m elf_i386 -T pr19539.t -z notext
 #readelf: -r --wide
 
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-i386/pr19636-2a.d b/ld/testsuite/ld-i386/pr19636-2a.d
index a3eafecb3b..98fb23c5a5 100644
--- a/ld/testsuite/ld-i386/pr19636-2a.d
+++ b/ld/testsuite/ld-i386/pr19636-2a.d
@@ -1,6 +1,6 @@
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -pie -m elf_i386
+#ld: -pie -m elf_i386 -z notext
 #readelf : -r --wide -x .got -x .got.plt --dyn-syms
 
 Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-i386/pr19636-2b.d b/ld/testsuite/ld-i386/pr19636-2b.d
index 57965f2775..d7c0a47cdd 100644
--- a/ld/testsuite/ld-i386/pr19636-2b.d
+++ b/ld/testsuite/ld-i386/pr19636-2b.d
@@ -1,6 +1,6 @@
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -pie -E -m elf_i386
+#ld: -pie -E -m elf_i386 -z notext
 #readelf : -r --wide -x .got -x .got.plt --dyn-syms
 
 Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-i386/pr19636-2c.d b/ld/testsuite/ld-i386/pr19636-2c.d
index 3c7cd6def3..b126480b4f 100644
--- a/ld/testsuite/ld-i386/pr19636-2c.d
+++ b/ld/testsuite/ld-i386/pr19636-2c.d
@@ -1,6 +1,6 @@
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -pie -m elf_i386
+#ld: -pie -m elf_i386 -z notext
 #objdump: -dw
 #notarget: i?86-*-nacl* x86_64-*-nacl*
 
diff --git a/ld/testsuite/ld-i386/pr19636-2d.d b/ld/testsuite/ld-i386/pr19636-2d.d
index 28eaa04d2b..694be367eb 100644
--- a/ld/testsuite/ld-i386/pr19636-2d.d
+++ b/ld/testsuite/ld-i386/pr19636-2d.d
@@ -1,6 +1,6 @@
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -shared -m elf_i386
+#ld: -shared -m elf_i386 -z notext
 #readelf : -r --wide --dyn-syms
 #notarget: i?86-*-nacl* x86_64-*-nacl*
 
diff --git a/ld/testsuite/ld-i386/pr19636-2e.d b/ld/testsuite/ld-i386/pr19636-2e.d
index 148e3060a7..c039fcb0a3 100644
--- a/ld/testsuite/ld-i386/pr19636-2e.d
+++ b/ld/testsuite/ld-i386/pr19636-2e.d
@@ -1,6 +1,6 @@
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -shared -Bsymbolic -m elf_i386
+#ld: -shared -Bsymbolic -m elf_i386 -z notext
 #readelf : -r --wide --dyn-syms
 #notarget: i?86-*-nacl* x86_64-*-nacl*
 
diff --git a/ld/testsuite/ld-i386/pr19636-3d.d b/ld/testsuite/ld-i386/pr19636-3d.d
index 7004bb14f0..7af7ba36e9 100644
--- a/ld/testsuite/ld-i386/pr19636-3d.d
+++ b/ld/testsuite/ld-i386/pr19636-3d.d
@@ -1,6 +1,6 @@
 #source: pr19636-3.s
 #as: --32
-#ld: -shared -m elf_i386
+#ld: -shared -m elf_i386 -z notext
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-i386/pr19636-3e.d b/ld/testsuite/ld-i386/pr19636-3e.d
index aeb4e7e171..2b692caf95 100644
--- a/ld/testsuite/ld-i386/pr19636-3e.d
+++ b/ld/testsuite/ld-i386/pr19636-3e.d
@@ -1,6 +1,6 @@
 #source: pr19636-3.s
 #as: --32
-#ld: -shared -Bsymbolic -m elf_i386
+#ld: -shared -Bsymbolic -m elf_i386 -z notext
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-i386/pr19939b.d b/ld/testsuite/ld-i386/pr19939b.d
index 5124ae10dc..25d7188265 100644
--- a/ld/testsuite/ld-i386/pr19939b.d
+++ b/ld/testsuite/ld-i386/pr19939b.d
@@ -1,6 +1,6 @@
 #source: pr19939.s
 #as: --32
-#ld: -melf_i386 -shared
+#ld: -melf_i386 -shared -z notext
 #readelf: -d --wide
 
 #...
diff --git a/ld/testsuite/ld-i386/undefweaka.d b/ld/testsuite/ld-i386/undefweaka.d
index c106ebf54f..e7e7a17471 100644
--- a/ld/testsuite/ld-i386/undefweaka.d
+++ b/ld/testsuite/ld-i386/undefweaka.d
@@ -1,6 +1,6 @@
 #source: undefweak.s
 #as: --32
-#ld: -shared -melf_i386
+#ld: -shared -melf_i386 -z notext
 #readelf: -r --wide
 
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
diff --git a/ld/testsuite/ld-i386/undefweakb.d b/ld/testsuite/ld-i386/undefweakb.d
index e6d6d5f7c3..e823a68c4d 100644
--- a/ld/testsuite/ld-i386/undefweakb.d
+++ b/ld/testsuite/ld-i386/undefweakb.d
@@ -1,6 +1,6 @@
 #source: undefweak.s
 #as: --32
-#ld: -pie -melf_i386
+#ld: -pie -melf_i386 -z notext
 #readelf: -r --wide -x .data.rel.ro
 
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
index 32cdbe8a41..fa64730775 100644
--- a/ld/testsuite/ld-shared/shared.exp
+++ b/ld/testsuite/ld-shared/shared.exp
@@ -133,6 +133,9 @@ proc shared_test { progname testname main sh1 sh2 dat args } {
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
 	set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
     }
+    if { [is_elf_format] && [check_shared_lib_support] } {
+	append shared " -Wl,-z,notext"
+    }
     if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
         fail "$testname"
     	return
diff --git a/ld/testsuite/ld-size/size.exp b/ld/testsuite/ld-size/size.exp
index 23b0b87558..20ebc01cc6 100644
--- a/ld/testsuite/ld-size/size.exp
+++ b/ld/testsuite/ld-size/size.exp
@@ -114,7 +114,7 @@ run_cc_link_tests [list \
     ] \
     [list \
 	"Build size-7" \
-	"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-7.so" \
 	"$NOPIE_CFLAGS" \
 	{size-7a.c} \
 	{{readelf -rW size-7.rd}} \
@@ -129,7 +129,7 @@ run_cc_link_tests [list \
     ] \
     [list \
 	"Build size-8" \
-	"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-8.so" \
 	"$NOPIE_CFLAGS" \
 	{size-8a.c} \
 	{{readelf -rW size-8.rd}} \
@@ -277,7 +277,7 @@ run_ld_link_exec_tests [list \
     ] \
     [list \
 	"Run size-8" \
-	"$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu,-z,notext \
 	 tmpdir/libsize-8.so" \
 	"" \
 	{size-8a.c} \
diff --git a/ld/testsuite/ld-unique/unique.exp b/ld/testsuite/ld-unique/unique.exp
index 0775c7d64a..6f2112c5d7 100644
--- a/ld/testsuite/ld-unique/unique.exp
+++ b/ld/testsuite/ld-unique/unique.exp
@@ -208,7 +208,7 @@ if {![ld_link "$CC $board_cflags" "tmpdir/unique_shared_prog" "-Ltmpdir tmpdir/u
 }
 
 # Create shared library containing unique symbol with reference.
-if {![ld_link $ld "tmpdir/libunique_shared_ref.so" "-shared tmpdir/unique_shared.o tmpdir/unique_empty.o"] } {
+if {![ld_link $ld "tmpdir/libunique_shared_ref.so" "-shared -z notext tmpdir/unique_shared.o tmpdir/unique_empty.o"] } {
     fail "Could not create a shared library containing an unique symbol with reference"
     set fails [expr $fails + 1]
 }
diff --git a/ld/testsuite/ld-x86-64/pie1.d b/ld/testsuite/ld-x86-64/pie1.d
index 3e64c150bc..acd90b7952 100644
--- a/ld/testsuite/ld-x86-64/pie1.d
+++ b/ld/testsuite/ld-x86-64/pie1.d
@@ -1,6 +1,6 @@
 #name: PIE with undefined symbol
 #as: --64
-#ld: -pie -melf_x86_64 --noinhibit-exec
+#ld: -pie -melf_x86_64 --noinhibit-exec -z notext
 #readelf: -s --wide
 #warning: \A[^\n]*\.o[^\n]*in function `_start':\n[^\n]*: undefined reference to `foo'\Z
 
diff --git a/ld/testsuite/ld-x86-64/pr19539a.d b/ld/testsuite/ld-x86-64/pr19539a.d
index 8c456d8482..3b696c58cb 100644
--- a/ld/testsuite/ld-x86-64/pr19539a.d
+++ b/ld/testsuite/ld-x86-64/pr19539a.d
@@ -1,6 +1,6 @@
 #source: pr19539.s
 #as: --64
-#ld: -pie -m elf_x86_64 -T pr19539.t
+#ld: -pie -m elf_x86_64 -T pr19539.t -z notext
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19539b.d b/ld/testsuite/ld-x86-64/pr19539b.d
index f338987def..0e50f32646 100644
--- a/ld/testsuite/ld-x86-64/pr19539b.d
+++ b/ld/testsuite/ld-x86-64/pr19539b.d
@@ -1,6 +1,6 @@
 #source: pr19539.s
 #as: --x32
-#ld: -pie -m elf32_x86_64 -T pr19539.t
+#ld: -pie -m elf32_x86_64 -T pr19539.t -z notext
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19636-1d.d b/ld/testsuite/ld-x86-64/pr19636-1d.d
index ccab633190..6b33d9c91b 100644
--- a/ld/testsuite/ld-x86-64/pr19636-1d.d
+++ b/ld/testsuite/ld-x86-64/pr19636-1d.d
@@ -1,6 +1,6 @@
 #source: pr19636-1.s
 #as: --64
-#ld: -shared -m elf_x86_64
+#ld: -shared -m elf_x86_64 -z notext
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-x86-64/pr19636-1e.d b/ld/testsuite/ld-x86-64/pr19636-1e.d
index 8516149390..fb01a235b5 100644
--- a/ld/testsuite/ld-x86-64/pr19636-1e.d
+++ b/ld/testsuite/ld-x86-64/pr19636-1e.d
@@ -1,6 +1,6 @@
 #source: pr19636-1.s
 #as: --64
-#ld: -shared -Bsymbolic -m elf_x86_64
+#ld: -shared -Bsymbolic -m elf_x86_64 -z notext
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-x86-64/pr19807-1a.d b/ld/testsuite/ld-x86-64/pr19807-1a.d
index f3c5390b28..6792e381fc 100644
--- a/ld/testsuite/ld-x86-64/pr19807-1a.d
+++ b/ld/testsuite/ld-x86-64/pr19807-1a.d
@@ -1,6 +1,6 @@
 #source: pr19807-1.s
 #as: --64
-#ld: -pie -melf_x86_64 -z noreloc-overflow
+#ld: -pie -melf_x86_64 -z noreloc-overflow -z notext
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19807-1b.d b/ld/testsuite/ld-x86-64/pr19807-1b.d
index 6af4985463..1983a81dd9 100644
--- a/ld/testsuite/ld-x86-64/pr19807-1b.d
+++ b/ld/testsuite/ld-x86-64/pr19807-1b.d
@@ -1,6 +1,6 @@
 #source: pr19807-1.s
 #as: --x32
-#ld: -pie -melf32_x86_64 -z noreloc-overflow
+#ld: -pie -melf32_x86_64 -z noreloc-overflow -z notext
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19807-2b.d b/ld/testsuite/ld-x86-64/pr19807-2b.d
index 44205f2308..8e3af447a3 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2b.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2b.d
@@ -1,6 +1,6 @@
 #source: pr19807-2.s
 #as: --x32
-#ld: -pie -melf32_x86_64
+#ld: -pie -melf32_x86_64 -z notext
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19807-2c.d b/ld/testsuite/ld-x86-64/pr19807-2c.d
index 83ac641624..96e9254451 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2c.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2c.d
@@ -1,6 +1,6 @@
 #source: pr19807-2.s
 #as: --x32
-#ld: -pie -melf32_x86_64
+#ld: -pie -melf32_x86_64 -z notext
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19807-2d.d b/ld/testsuite/ld-x86-64/pr19807-2d.d
index 5394615158..413df228ef 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2d.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2d.d
@@ -1,6 +1,6 @@
 #source: pr19807-2.s
 #as: --64
-#ld: -pie -melf_x86_64 -z noreloc-overflow
+#ld: -pie -melf_x86_64 -z noreloc-overflow -z notext
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19807-2e.d b/ld/testsuite/ld-x86-64/pr19807-2e.d
index f26616a20a..2d57596279 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2e.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2e.d
@@ -1,6 +1,6 @@
 #source: pr19807-2.s
 #as: --64
-#ld: -pie -melf_x86_64 -z noreloc-overflow
+#ld: -pie -melf_x86_64 -z noreloc-overflow -z notext
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19939b.d b/ld/testsuite/ld-x86-64/pr19939b.d
index 2616151550..e239f2da0e 100644
--- a/ld/testsuite/ld-x86-64/pr19939b.d
+++ b/ld/testsuite/ld-x86-64/pr19939b.d
@@ -1,6 +1,6 @@
 #source: pr19939.s
 #as: --64
-#ld: -melf_x86_64 -shared
+#ld: -melf_x86_64 -shared -z notext
 #readelf: -d --wide
 
 #...
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 9db16c6b6e..07b70a4b8a 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -212,9 +212,12 @@ set x86_64tests {
      "--64" { pr19827a.S }}
     {"Build pr19827b.so" "-melf_x86_64 -shared" ""
      "--64" { pr19827b.S } {} "pr19827b.so"}
-    {"Build pr19827" "-melf_x86_64 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""
+    {"Build pr19827"
+     "-melf_x86_64 -pie -z notext tmpdir/pr19827a.o tmpdir/pr19827b.so"
+     ""
      "--64" { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}
-    {"Build pr19827.so" "-melf_x86_64 -shared -Bsymbolic" ""
+    {"Build pr19827.so"
+     "-melf_x86_64 -shared -Bsymbolic -z notext" ""
      "--64" { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
     {"Build pr19969.so" "-melf_x86_64 -shared" ""
      "--64" { pr19969a.S } {} "pr19969.so"}
@@ -222,7 +225,9 @@ set x86_64tests {
      "--64" { pr20550a.s }}
     {"Build pr20550b.so" "-melf_x86_64 -shared" ""
      "--64" { pr20550b.s } {} "pr20550b.so"}
-    {"Build pr20550" "-melf_x86_64 -pie tmpdir/pr20550a.o tmpdir/pr20550b.so" ""
+    {"Build pr20550"
+     "-melf_x86_64 -pie -z notext tmpdir/pr20550a.o tmpdir/pr20550b.so"
+     ""
      "--64" { dummy.s } {} "pr20550"}
 }
 
@@ -1172,7 +1177,7 @@ if { [isnative] && [check_compiler_available] } {
 	] \
 	[list \
 	    "Build pr22001-1a" \
-	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext tmpdir/pr22001-1.so" \
 	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
 	    { pr22001-1b.c } \
 	    {{error_output "pr22001-1a.err"}} \
@@ -1188,7 +1193,7 @@ if { [isnative] && [check_compiler_available] } {
 	] \
 	[list \
 	    "Build pr21997-1a" \
-	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
 	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
 	    { pr21997-1b.c } \
 	    {{error_output "pr21997-1a.err"}} \
@@ -1263,7 +1268,7 @@ if { [isnative] && [check_compiler_available] } {
 	] \
 	[list \
 	    "Build pr22791-1" \
-	    "-pie -Wl,--no-as-needed tmpdir/pr22791-1.so" \
+	    "-pie -Wl,--no-as-needed,-z,notext tmpdir/pr22791-1.so" \
 	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
 	    { pr22791-1b.s } \
 	    {{error_output "pr22791-1.err"}} \
@@ -1359,7 +1364,7 @@ if { [isnative] && [check_compiler_available] } {
 	run_ld_link_exec_tests [list \
 	    [list \
 		"Run pr22001-1b" \
-		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext tmpdir/pr22001-1.so" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr22001-1c.c } \
 		"pr22001-1b" \
@@ -1368,7 +1373,7 @@ if { [isnative] && [check_compiler_available] } {
 	    ] \
 	    [list \
 		"Run pr21997-1b" \
-		"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
+		"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr21997-1c.c } \
 		"pr21997-1b" \
@@ -1422,7 +1427,7 @@ if { [isnative] && [check_compiler_available] } {
 	    ] \
 	    [list \
 		"Run pr25416-5f (PIE GDesc -> LE -maddress-mode=short)" \
-		"-pie tmpdir/pr25416-5b.o tmpdir/pr25416-5d.o" \
+		"-pie -Wl,-z,notext tmpdir/pr25416-5b.o tmpdir/pr25416-5d.o" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr25416-5a.c } \
 		"pr25416-5f" \
@@ -1430,7 +1435,7 @@ if { [isnative] && [check_compiler_available] } {
 	    ] \
 	    [list \
 		"Run pr25416-5g (PIE GDesc -> LE -maddress-mode=long)" \
-		"-pie tmpdir/pr25416-5c.o tmpdir/pr25416-5d.o" \
+		"-pie -Wl,-z,notext tmpdir/pr25416-5c.o tmpdir/pr25416-5d.o" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr25416-5a.c } \
 		"pr25416-5g" \

Patch

diff --git a/ld/testsuite/ld-elf/eh6.d b/ld/testsuite/ld-elf/eh6.d
index 69c4c85acd..4ea2ba5087 100644
--- a/ld/testsuite/ld-elf/eh6.d
+++ b/ld/testsuite/ld-elf/eh6.d
@@ -1,5 +1,5 @@ 
 #source: eh6.s
-#ld: --gc-sections -shared
+#ld: --gc-sections -shared -z textoff
 #readelf: -wf -rW
 #target: x86_64-*-linux-gnu* i?86-*-linux-gnu i?86-*-gnu*
 
diff --git a/ld/testsuite/ld-elf/ehdr_start-shared.d b/ld/testsuite/ld-elf/ehdr_start-shared.d
index 6cbaa3a341..a013588765 100644
--- a/ld/testsuite/ld-elf/ehdr_start-shared.d
+++ b/ld/testsuite/ld-elf/ehdr_start-shared.d
@@ -1,5 +1,5 @@ 
 #source: ehdr_start.s
-#ld: -e _start -shared
+#ld: -e _start -shared -z textoff
 #nm: -n
 #target: *-*-linux* *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
 #xfail: cris*-*-* frv-*-* ![check_shared_lib_support] 
diff --git a/ld/testsuite/ld-elf/pr19539.d b/ld/testsuite/ld-elf/pr19539.d
index c9f91ce663..5a5685e7c2 100644
--- a/ld/testsuite/ld-elf/pr19539.d
+++ b/ld/testsuite/ld-elf/pr19539.d
@@ -1,6 +1,6 @@ 
 #source: start.s
 #source: pr19539.s
-#ld: -pie -T pr19539.t
+#ld: -pie -T pr19539.t -z textoff
 #readelf : --dyn-syms --wide
 #target: *-*-linux* *-*-gnu* *-*-solaris* arm*-*-uclinuxfdpiceabi
 #xfail: cris*-*-* ![check_pie_support] 
diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp
index ed48e1a697..897bf3a3b0 100644
--- a/ld/testsuite/ld-elfvers/vers.exp
+++ b/ld/testsuite/ld-elfvers/vers.exp
@@ -576,7 +576,7 @@  proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp
   global shared
   # Make sure that PLT is used since PLT is expected.
   global PLT_CFLAGS
-  build_binary $shared $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
+  build_binary "$shared -z textoff" $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
 }
 
 proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } {
diff --git a/ld/testsuite/ld-elfvsb/elfvsb.exp b/ld/testsuite/ld-elfvsb/elfvsb.exp
index 58dea0b0c8..5f6cb2bd63 100644
--- a/ld/testsuite/ld-elfvsb/elfvsb.exp
+++ b/ld/testsuite/ld-elfvsb/elfvsb.exp
@@ -142,6 +142,9 @@  proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
 	set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
     }
+    if { [is_elf_format] && [check_shared_lib_support] } {
+	append shared " -Wl,-z,textoff"
+    }
     if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
 	if { [ string match $visibility "hidden_undef" ]
 	     && [regexp "undefined reference to \`\.?visibility\'" $link_output]
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index e3a5f8b195..f5f5fdb5da 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -181,7 +181,7 @@  set i386tests {
       {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}}
       "tlsbindesc"}
     {"TLS -fno-pic -shared"
-     "-shared -melf_i386 --no-ld-generated-unwind-info \
+     "-shared -melf_i386 --no-ld-generated-unwind-info -z textoff \
       -z noseparate-code --hash-style=sysv" ""
      "--32" {tlsnopic1.s tlsnopic2.s}
      {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}
@@ -197,7 +197,8 @@  set i386tests {
      {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
     {"TLS @indntpoff with %eax" "-melf_i386" "" "--32" {tlsindntpoff.s}
      {{objdump -drj.text tlsindntpoff.dd}} "tlsindntpoff"}
-    {"Reloc section order" "-shared -melf_i386 -z nocombreloc" "" "--32"
+    {"Reloc section order" 
+     "-shared -melf_i386 -z nocombreloc -z textoff" "" "--32"
      {reloc.s} {{objdump -hw reloc.d}} "reloc.so"}
     {"Basic --emit-relocs support" "-shared -melf_i386 --emit-relocs" "" "--32"
      {emit-relocs.s} {{readelf --relocs emit-relocs.rd}} "emit-relocs.so"}
@@ -238,10 +239,13 @@  set i386tests {
     {"Build pr19827b.so" "-melf_i386 -shared" ""
      "--32 -mx86-used-note=yes"
      { pr19827b.S } {} "pr19827b.so"}
-    {"Build pr19827" "-melf_i386 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""
+    {"Build pr19827"
+     "-melf_i386 -pie -z textoff tmpdir/pr19827a.o tmpdir/pr19827b.so"
+     ""
      "--32 -mx86-used-note=yes"
      { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}
-    {"Build pr19827.so" "-melf_i386 -shared -Bsymbolic" ""
+    {"Build pr19827.so"
+     "-melf_i386 -shared -Bsymbolic -z textoff" ""
      "--32 -mx86-used-note=yes"
      { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
 }
@@ -1316,7 +1320,7 @@  if { [isnative]
     run_cc_link_tests [list \
 	[list \
 	    "Build pr22001-1.so" \
-	    "-shared" \
+	    "-shared -Wl,-z,textoff" \
 	    "-Wa,-mx86-used-note=yes" \
 	    { pr22001-1a.c } \
 	    {} \
@@ -1352,7 +1356,7 @@  if { [isnative]
 	] \
 	[list \
 	    "Run pr22001-1" \
-	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,textoff tmpdir/pr22001-1.so" \
 	    "-Wa,-mx86-used-note=yes" \
 	    { pr22001-1b.c } \
 	    "pr22001-1" \
@@ -1395,7 +1399,7 @@  if { [isnative]
 	] \
 	[list \
 	    "Run pr21997-1" \
-	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/pr21997-1.so" \
 	    "-Wa,-mx86-used-note=yes" \
 	    { pr21997-1b.c } \
 	    "pr21997-1" \
diff --git a/ld/testsuite/ld-i386/nogot1.d b/ld/testsuite/ld-i386/nogot1.d
index 018c24d3a9..0ee92d965a 100644
--- a/ld/testsuite/ld-i386/nogot1.d
+++ b/ld/testsuite/ld-i386/nogot1.d
@@ -1,4 +1,4 @@ 
-#ld: --shared -melf_i386
+#ld: --shared -melf_i386 -z textoff
 #readelf: -S --wide
 #as: --32
 
diff --git a/ld/testsuite/ld-i386/pr19539.d b/ld/testsuite/ld-i386/pr19539.d
index 7fe6e89a0d..1d02599481 100644
--- a/ld/testsuite/ld-i386/pr19539.d
+++ b/ld/testsuite/ld-i386/pr19539.d
@@ -1,5 +1,5 @@ 
 #as: --32
-#ld: -pie -m elf_i386 -T pr19539.t
+#ld: -pie -m elf_i386 -T pr19539.t -z textoff
 #readelf: -r --wide
 
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-i386/pr19636-2a.d b/ld/testsuite/ld-i386/pr19636-2a.d
index a3eafecb3b..f03598464e 100644
--- a/ld/testsuite/ld-i386/pr19636-2a.d
+++ b/ld/testsuite/ld-i386/pr19636-2a.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -pie -m elf_i386
+#ld: -pie -m elf_i386 -z textoff
 #readelf : -r --wide -x .got -x .got.plt --dyn-syms
 
 Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-i386/pr19636-2b.d b/ld/testsuite/ld-i386/pr19636-2b.d
index 57965f2775..8973e3f787 100644
--- a/ld/testsuite/ld-i386/pr19636-2b.d
+++ b/ld/testsuite/ld-i386/pr19636-2b.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -pie -E -m elf_i386
+#ld: -pie -E -m elf_i386 -z textoff
 #readelf : -r --wide -x .got -x .got.plt --dyn-syms
 
 Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-i386/pr19636-2c.d b/ld/testsuite/ld-i386/pr19636-2c.d
index 3c7cd6def3..0dc722fb63 100644
--- a/ld/testsuite/ld-i386/pr19636-2c.d
+++ b/ld/testsuite/ld-i386/pr19636-2c.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -pie -m elf_i386
+#ld: -pie -m elf_i386 -z textoff
 #objdump: -dw
 #notarget: i?86-*-nacl* x86_64-*-nacl*
 
diff --git a/ld/testsuite/ld-i386/pr19636-2d.d b/ld/testsuite/ld-i386/pr19636-2d.d
index 28eaa04d2b..363e0f64b8 100644
--- a/ld/testsuite/ld-i386/pr19636-2d.d
+++ b/ld/testsuite/ld-i386/pr19636-2d.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -shared -m elf_i386
+#ld: -shared -m elf_i386 -z textoff
 #readelf : -r --wide --dyn-syms
 #notarget: i?86-*-nacl* x86_64-*-nacl*
 
diff --git a/ld/testsuite/ld-i386/pr19636-2e.d b/ld/testsuite/ld-i386/pr19636-2e.d
index 148e3060a7..51b32a1e52 100644
--- a/ld/testsuite/ld-i386/pr19636-2e.d
+++ b/ld/testsuite/ld-i386/pr19636-2e.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-2.s
 #as: --32 -mrelax-relocations=no
-#ld: -shared -Bsymbolic -m elf_i386
+#ld: -shared -Bsymbolic -m elf_i386 -z textoff
 #readelf : -r --wide --dyn-syms
 #notarget: i?86-*-nacl* x86_64-*-nacl*
 
diff --git a/ld/testsuite/ld-i386/pr19636-3d.d b/ld/testsuite/ld-i386/pr19636-3d.d
index 7004bb14f0..b7e691ac26 100644
--- a/ld/testsuite/ld-i386/pr19636-3d.d
+++ b/ld/testsuite/ld-i386/pr19636-3d.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-3.s
 #as: --32
-#ld: -shared -m elf_i386
+#ld: -shared -m elf_i386 -z textoff
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-i386/pr19636-3e.d b/ld/testsuite/ld-i386/pr19636-3e.d
index aeb4e7e171..c2693560d7 100644
--- a/ld/testsuite/ld-i386/pr19636-3e.d
+++ b/ld/testsuite/ld-i386/pr19636-3e.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-3.s
 #as: --32
-#ld: -shared -Bsymbolic -m elf_i386
+#ld: -shared -Bsymbolic -m elf_i386 -z textoff
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-i386/pr19939b.d b/ld/testsuite/ld-i386/pr19939b.d
index 5124ae10dc..a90cfd9d12 100644
--- a/ld/testsuite/ld-i386/pr19939b.d
+++ b/ld/testsuite/ld-i386/pr19939b.d
@@ -1,6 +1,6 @@ 
 #source: pr19939.s
 #as: --32
-#ld: -melf_i386 -shared
+#ld: -melf_i386 -shared -z textoff
 #readelf: -d --wide
 
 #...
diff --git a/ld/testsuite/ld-i386/undefweaka.d b/ld/testsuite/ld-i386/undefweaka.d
index c106ebf54f..a970aaeb45 100644
--- a/ld/testsuite/ld-i386/undefweaka.d
+++ b/ld/testsuite/ld-i386/undefweaka.d
@@ -1,6 +1,6 @@ 
 #source: undefweak.s
 #as: --32
-#ld: -shared -melf_i386
+#ld: -shared -melf_i386 -z textoff
 #readelf: -r --wide
 
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
diff --git a/ld/testsuite/ld-i386/undefweakb.d b/ld/testsuite/ld-i386/undefweakb.d
index e6d6d5f7c3..446519a080 100644
--- a/ld/testsuite/ld-i386/undefweakb.d
+++ b/ld/testsuite/ld-i386/undefweakb.d
@@ -1,6 +1,6 @@ 
 #source: undefweak.s
 #as: --32
-#ld: -pie -melf_i386
+#ld: -pie -melf_i386 -z textoff
 #readelf: -r --wide -x .data.rel.ro
 
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
index 32cdbe8a41..f9e980f22a 100644
--- a/ld/testsuite/ld-shared/shared.exp
+++ b/ld/testsuite/ld-shared/shared.exp
@@ -133,6 +133,9 @@  proc shared_test { progname testname main sh1 sh2 dat args } {
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
 	set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
     }
+    if { [is_elf_format] && [check_shared_lib_support] } {
+	append shared " -Wl,-z,textoff"
+    }
     if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
         fail "$testname"
     	return
diff --git a/ld/testsuite/ld-size/size.exp b/ld/testsuite/ld-size/size.exp
index 23b0b87558..9a171c1693 100644
--- a/ld/testsuite/ld-size/size.exp
+++ b/ld/testsuite/ld-size/size.exp
@@ -114,7 +114,7 @@  run_cc_link_tests [list \
     ] \
     [list \
 	"Build size-7" \
-	"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/libsize-7.so" \
 	"$NOPIE_CFLAGS" \
 	{size-7a.c} \
 	{{readelf -rW size-7.rd}} \
@@ -129,7 +129,7 @@  run_cc_link_tests [list \
     ] \
     [list \
 	"Build size-8" \
-	"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/libsize-8.so" \
 	"$NOPIE_CFLAGS" \
 	{size-8a.c} \
 	{{readelf -rW size-8.rd}} \
@@ -277,7 +277,7 @@  run_ld_link_exec_tests [list \
     ] \
     [list \
 	"Run size-8" \
-	"$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu \
+	"$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu,-z,textoff \
 	 tmpdir/libsize-8.so" \
 	"" \
 	{size-8a.c} \
diff --git a/ld/testsuite/ld-unique/unique.exp b/ld/testsuite/ld-unique/unique.exp
index 0775c7d64a..5dec7ec7b5 100644
--- a/ld/testsuite/ld-unique/unique.exp
+++ b/ld/testsuite/ld-unique/unique.exp
@@ -208,7 +208,7 @@  if {![ld_link "$CC $board_cflags" "tmpdir/unique_shared_prog" "-Ltmpdir tmpdir/u
 }
 
 # Create shared library containing unique symbol with reference.
-if {![ld_link $ld "tmpdir/libunique_shared_ref.so" "-shared tmpdir/unique_shared.o tmpdir/unique_empty.o"] } {
+if {![ld_link $ld "tmpdir/libunique_shared_ref.so" "-shared -z textoff tmpdir/unique_shared.o tmpdir/unique_empty.o"] } {
     fail "Could not create a shared library containing an unique symbol with reference"
     set fails [expr $fails + 1]
 }
diff --git a/ld/testsuite/ld-x86-64/pie1.d b/ld/testsuite/ld-x86-64/pie1.d
index 3e64c150bc..a1bd27fd33 100644
--- a/ld/testsuite/ld-x86-64/pie1.d
+++ b/ld/testsuite/ld-x86-64/pie1.d
@@ -1,6 +1,6 @@ 
 #name: PIE with undefined symbol
 #as: --64
-#ld: -pie -melf_x86_64 --noinhibit-exec
+#ld: -pie -melf_x86_64 --noinhibit-exec -z textoff
 #readelf: -s --wide
 #warning: \A[^\n]*\.o[^\n]*in function `_start':\n[^\n]*: undefined reference to `foo'\Z
 
diff --git a/ld/testsuite/ld-x86-64/pr19539a.d b/ld/testsuite/ld-x86-64/pr19539a.d
index 8c456d8482..e85fb90b14 100644
--- a/ld/testsuite/ld-x86-64/pr19539a.d
+++ b/ld/testsuite/ld-x86-64/pr19539a.d
@@ -1,6 +1,6 @@ 
 #source: pr19539.s
 #as: --64
-#ld: -pie -m elf_x86_64 -T pr19539.t
+#ld: -pie -m elf_x86_64 -T pr19539.t -z textoff
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19539b.d b/ld/testsuite/ld-x86-64/pr19539b.d
index f338987def..86dc47e0de 100644
--- a/ld/testsuite/ld-x86-64/pr19539b.d
+++ b/ld/testsuite/ld-x86-64/pr19539b.d
@@ -1,6 +1,6 @@ 
 #source: pr19539.s
 #as: --x32
-#ld: -pie -m elf32_x86_64 -T pr19539.t
+#ld: -pie -m elf32_x86_64 -T pr19539.t -z textoff
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19636-1d.d b/ld/testsuite/ld-x86-64/pr19636-1d.d
index ccab633190..50f5e1e9a6 100644
--- a/ld/testsuite/ld-x86-64/pr19636-1d.d
+++ b/ld/testsuite/ld-x86-64/pr19636-1d.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-1.s
 #as: --64
-#ld: -shared -m elf_x86_64
+#ld: -shared -m elf_x86_64 -z textoff
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-x86-64/pr19636-1e.d b/ld/testsuite/ld-x86-64/pr19636-1e.d
index 8516149390..472d14a381 100644
--- a/ld/testsuite/ld-x86-64/pr19636-1e.d
+++ b/ld/testsuite/ld-x86-64/pr19636-1e.d
@@ -1,6 +1,6 @@ 
 #source: pr19636-1.s
 #as: --64
-#ld: -shared -Bsymbolic -m elf_x86_64
+#ld: -shared -Bsymbolic -m elf_x86_64 -z textoff
 #readelf : -r --wide --dyn-syms
 
 Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entr(y|ies):
diff --git a/ld/testsuite/ld-x86-64/pr19807-1a.d b/ld/testsuite/ld-x86-64/pr19807-1a.d
index f3c5390b28..fbb8b159ac 100644
--- a/ld/testsuite/ld-x86-64/pr19807-1a.d
+++ b/ld/testsuite/ld-x86-64/pr19807-1a.d
@@ -1,6 +1,6 @@ 
 #source: pr19807-1.s
 #as: --64
-#ld: -pie -melf_x86_64 -z noreloc-overflow
+#ld: -pie -melf_x86_64 -z noreloc-overflow -z textoff
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19807-1b.d b/ld/testsuite/ld-x86-64/pr19807-1b.d
index 6af4985463..3b9b3c2c41 100644
--- a/ld/testsuite/ld-x86-64/pr19807-1b.d
+++ b/ld/testsuite/ld-x86-64/pr19807-1b.d
@@ -1,6 +1,6 @@ 
 #source: pr19807-1.s
 #as: --x32
-#ld: -pie -melf32_x86_64 -z noreloc-overflow
+#ld: -pie -melf32_x86_64 -z noreloc-overflow -z textoff
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19807-2b.d b/ld/testsuite/ld-x86-64/pr19807-2b.d
index 44205f2308..98cca8465d 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2b.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2b.d
@@ -1,6 +1,6 @@ 
 #source: pr19807-2.s
 #as: --x32
-#ld: -pie -melf32_x86_64
+#ld: -pie -melf32_x86_64 -z textoff
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19807-2c.d b/ld/testsuite/ld-x86-64/pr19807-2c.d
index 83ac641624..cd6e563492 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2c.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2c.d
@@ -1,6 +1,6 @@ 
 #source: pr19807-2.s
 #as: --x32
-#ld: -pie -melf32_x86_64
+#ld: -pie -melf32_x86_64 -z textoff
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19807-2d.d b/ld/testsuite/ld-x86-64/pr19807-2d.d
index 5394615158..b9ae5cbaec 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2d.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2d.d
@@ -1,6 +1,6 @@ 
 #source: pr19807-2.s
 #as: --64
-#ld: -pie -melf_x86_64 -z noreloc-overflow
+#ld: -pie -melf_x86_64 -z noreloc-overflow -z textoff
 #readelf: -r --wide
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
diff --git a/ld/testsuite/ld-x86-64/pr19807-2e.d b/ld/testsuite/ld-x86-64/pr19807-2e.d
index f26616a20a..fd08746d3e 100644
--- a/ld/testsuite/ld-x86-64/pr19807-2e.d
+++ b/ld/testsuite/ld-x86-64/pr19807-2e.d
@@ -1,6 +1,6 @@ 
 #source: pr19807-2.s
 #as: --64
-#ld: -pie -melf_x86_64 -z noreloc-overflow
+#ld: -pie -melf_x86_64 -z noreloc-overflow -z textoff
 #objdump: -dw
 
 .*: +file format .*
diff --git a/ld/testsuite/ld-x86-64/pr19939b.d b/ld/testsuite/ld-x86-64/pr19939b.d
index 2616151550..a5605bf260 100644
--- a/ld/testsuite/ld-x86-64/pr19939b.d
+++ b/ld/testsuite/ld-x86-64/pr19939b.d
@@ -1,6 +1,6 @@ 
 #source: pr19939.s
 #as: --64
-#ld: -melf_x86_64 -shared
+#ld: -melf_x86_64 -shared -z textoff
 #readelf: -d --wide
 
 #...
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 9db16c6b6e..f955f63dc3 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -212,9 +212,12 @@  set x86_64tests {
      "--64" { pr19827a.S }}
     {"Build pr19827b.so" "-melf_x86_64 -shared" ""
      "--64" { pr19827b.S } {} "pr19827b.so"}
-    {"Build pr19827" "-melf_x86_64 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""
+    {"Build pr19827"
+     "-melf_x86_64 -pie -z textoff tmpdir/pr19827a.o tmpdir/pr19827b.so"
+     ""
      "--64" { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}
-    {"Build pr19827.so" "-melf_x86_64 -shared -Bsymbolic" ""
+    {"Build pr19827.so"
+     "-melf_x86_64 -shared -Bsymbolic -z textoff" ""
      "--64" { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
     {"Build pr19969.so" "-melf_x86_64 -shared" ""
      "--64" { pr19969a.S } {} "pr19969.so"}
@@ -222,7 +225,9 @@  set x86_64tests {
      "--64" { pr20550a.s }}
     {"Build pr20550b.so" "-melf_x86_64 -shared" ""
      "--64" { pr20550b.s } {} "pr20550b.so"}
-    {"Build pr20550" "-melf_x86_64 -pie tmpdir/pr20550a.o tmpdir/pr20550b.so" ""
+    {"Build pr20550"
+     "-melf_x86_64 -pie -z textoff tmpdir/pr20550a.o tmpdir/pr20550b.so"
+     ""
      "--64" { dummy.s } {} "pr20550"}
 }
 
@@ -1172,7 +1177,7 @@  if { [isnative] && [check_compiler_available] } {
 	] \
 	[list \
 	    "Build pr22001-1a" \
-	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,textoff tmpdir/pr22001-1.so" \
 	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
 	    { pr22001-1b.c } \
 	    {{error_output "pr22001-1a.err"}} \
@@ -1188,7 +1193,7 @@  if { [isnative] && [check_compiler_available] } {
 	] \
 	[list \
 	    "Build pr21997-1a" \
-	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
+	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/pr21997-1.so" \
 	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
 	    { pr21997-1b.c } \
 	    {{error_output "pr21997-1a.err"}} \
@@ -1263,7 +1268,7 @@  if { [isnative] && [check_compiler_available] } {
 	] \
 	[list \
 	    "Build pr22791-1" \
-	    "-pie -Wl,--no-as-needed tmpdir/pr22791-1.so" \
+	    "-pie -Wl,--no-as-needed,-z,textoff tmpdir/pr22791-1.so" \
 	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
 	    { pr22791-1b.s } \
 	    {{error_output "pr22791-1.err"}} \
@@ -1359,7 +1364,7 @@  if { [isnative] && [check_compiler_available] } {
 	run_ld_link_exec_tests [list \
 	    [list \
 		"Run pr22001-1b" \
-		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,textoff tmpdir/pr22001-1.so" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr22001-1c.c } \
 		"pr22001-1b" \
@@ -1368,7 +1373,7 @@  if { [isnative] && [check_compiler_available] } {
 	    ] \
 	    [list \
 		"Run pr21997-1b" \
-		"$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr21997-1.so" \
+		"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,textoff tmpdir/pr21997-1.so" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr21997-1c.c } \
 		"pr21997-1b" \
@@ -1422,7 +1427,7 @@  if { [isnative] && [check_compiler_available] } {
 	    ] \
 	    [list \
 		"Run pr25416-5f (PIE GDesc -> LE -maddress-mode=short)" \
-		"-pie tmpdir/pr25416-5b.o tmpdir/pr25416-5d.o" \
+		"-pie -Wl,-z,textoff tmpdir/pr25416-5b.o tmpdir/pr25416-5d.o" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr25416-5a.c } \
 		"pr25416-5f" \
@@ -1430,7 +1435,7 @@  if { [isnative] && [check_compiler_available] } {
 	    ] \
 	    [list \
 		"Run pr25416-5g (PIE GDesc -> LE -maddress-mode=long)" \
-		"-pie tmpdir/pr25416-5c.o tmpdir/pr25416-5d.o" \
+		"-pie -Wl,-z,textoff tmpdir/pr25416-5c.o tmpdir/pr25416-5d.o" \
 		"-Wa,-mx86-used-note=yes" \
 		{ pr25416-5a.c } \
 		"pr25416-5g" \