GENERATE_SHLIB_SCRIPT vs. EMBEDDED

Message ID 20191105040135.GG6708@bubble.grove.modra.org
State New
Headers show
Series
  • GENERATE_SHLIB_SCRIPT vs. EMBEDDED
Related show

Commit Message

Alan Modra Nov. 5, 2019, 4:01 a.m.
On Tue, Oct 29, 2019 at 10:23:41AM +1030, Alan Modra wrote:
> The error is

> ./ld-new: tmpdir/pr22471: error: PHDR segment not covered by LOAD segment

> which was the case before this patch but ld didn't diagnose the error.

> So not exactly a regression.

> 

> In more detail, we have a bunch of targets that have this nastiness in

> their setup: eg. from ld/emulparams/elf32bfin.sh

> GENERATE_SHLIB_SCRIPT=yes

> EMBEDDED=yes


A target that sets EMBEDDED non-empty is one that doesn't want to put
the ELF file header or program header in a memory image.  Likely the
target isn't interested in supporting dynamically loaded executables,
shared libraries, or PIEs, because loaders for such binaries generally
require program headers to be present.  This isn't 100% true though.
The target might be one where the loader accesses the file system in
order to retrieve headers.

Also, note that not all "shared libraries" require gcc -shared or the
shared library support in the linker.  I believe one implementation of
shared libraries on uclinux is like this.

So, this patch removes GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT
in most emulparams files where EMBEDDED is set, restoring the shared
lib and pie support in emulparams files that unset EMBEDDED after
including a file where the support is removed.

Exceptions to the general rule that EMBEDDED disables shared libs are:
  arm*-*-symbianelf*, where the OS wants shared library support
  without ELF program headers in the image, and

  sh*-*-uclinux*, where I've left things as they were, ie. both
  EMBEDDED and GENERATE_SHLIB_SCRIPT because I'm unsure as to the
  shared library scheme.

After this patch the targets I regularly test see these testsuite
changes:
bfin-elf  -FAIL: Build pr22471
bfin-elf  -FAIL: DT_TEXTREL in shared lib
bfin-elf  -FAIL: DT_TEXTREL map file warning
bfin-elf  -FAIL: PR ld/21233 dynamic symbols with section GC (--undefined)
bfin-elf  -FAIL: PR ld/21233 dynamic symbols with section GC (--require-defined)
bfin-elf  -FAIL: PR ld/21233 dynamic symbols with section GC (EXTERN)
bfin-elf  -FAIL: Build pr22150
bfin-elf  -FAIL: Build pr20995-2.so
bfin-elf  -FAIL: undefined symbols in shared lib (dyn reloc)
score-elf  -FAIL: Build pr22471
score-elf  -FAIL: DT_TEXTREL map file warning
score-elf  -FAIL: Build pr22150
score-elf  -FAIL: -Bsymbolic-functions
score-elf  -FAIL: Build pr20995-2.so
score-elf  -FAIL: pr20995
score-elf  -FAIL: pr20995-2
sh-rtems  -FAIL: Build pr22471
sh-rtems  -FAIL: Build pr20995-2.so
sh-rtems  -FAIL: pr20995
sh-rtems  -FAIL: pr20995-2

	* emulparams/aarch64elf.sh (GENERATE_SHLIB_SCRIPT),
	(GENERATE_PIE_SCRIPT): Don't set.
	* emulparams/aarch64elf32.sh (GENERATE_SHLIB_SCRIPT),
	(GENERATE_PIE_SCRIPT): Don't set.
	* emulparams/arcelf.sh (GENERATE_SHLIB_SCRIPT): Don't set.
	* emulparams/armelf.sh (GENERATE_SHLIB_SCRIPT),
	(GENERATE_PIE_SCRIPT): Don't set.
	* emulparams/armelf_fbsd.sh (GENERATE_SHLIB_SCRIPT): Set.
	* emulparams/armelf_nbsd.sh (GENERATE_SHLIB_SCRIPT),
	(GENERATE_PIE_SCRIPT): Set.
	* emulparams/armelf_vxworks.sh (GENERATE_SHLIB_SCRIPT): Set.
	* emulparams/armsymbian.sh (GENERATE_SHLIB_SCRIPT): Set.
	* emulparams/elf32bfin.sh (GENERATE_SHLIB_SCRIPT): Don't set.
	* emulparams/elf32microblaze.sh (GENERATE_SHLIB_SCRIPT): Don't set.
	* emulparams/score3_elf.sh (GENERATE_SHLIB_SCRIPT): Don't set.
	* emulparams/shelf.sh (GENERATE_SHLIB_SCRIPT): Don't set.
	* emulparams/shelf_nbsd.sh (GENERATE_SHLIB_SCRIPT),
	(GENERATE_PIE_SCRIPT): Set.
	* emulparams/shelf_uclinux.sh (GENERATE_SHLIB_SCRIPT): Set.


-- 
Alan Modra
Australia Development Lab, IBM

Comments

Christophe Lyon Nov. 5, 2019, 8:47 a.m. | #1
On Tue, 5 Nov 2019 at 05:01, Alan Modra <amodra@gmail.com> wrote:
>

> On Tue, Oct 29, 2019 at 10:23:41AM +1030, Alan Modra wrote:

> > The error is

> > ./ld-new: tmpdir/pr22471: error: PHDR segment not covered by LOAD segment

> > which was the case before this patch but ld didn't diagnose the error.

> > So not exactly a regression.

> >

> > In more detail, we have a bunch of targets that have this nastiness in

> > their setup: eg. from ld/emulparams/elf32bfin.sh

> > GENERATE_SHLIB_SCRIPT=yes

> > EMBEDDED=yes

>

> A target that sets EMBEDDED non-empty is one that doesn't want to put

> the ELF file header or program header in a memory image.  Likely the

> target isn't interested in supporting dynamically loaded executables,

> shared libraries, or PIEs, because loaders for such binaries generally

> require program headers to be present.  This isn't 100% true though.

> The target might be one where the loader accesses the file system in

> order to retrieve headers.

>

> Also, note that not all "shared libraries" require gcc -shared or the

> shared library support in the linker.  I believe one implementation of

> shared libraries on uclinux is like this.

>

> So, this patch removes GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT

> in most emulparams files where EMBEDDED is set, restoring the shared

> lib and pie support in emulparams files that unset EMBEDDED after

> including a file where the support is removed.

>

> Exceptions to the general rule that EMBEDDED disables shared libs are:

>   arm*-*-symbianelf*, where the OS wants shared library support

>   without ELF program headers in the image, and

>

>   sh*-*-uclinux*, where I've left things as they were, ie. both

>   EMBEDDED and GENERATE_SHLIB_SCRIPT because I'm unsure as to the

>   shared library scheme.

>

> After this patch the targets I regularly test see these testsuite

> changes:

> bfin-elf  -FAIL: Build pr22471

> bfin-elf  -FAIL: DT_TEXTREL in shared lib

> bfin-elf  -FAIL: DT_TEXTREL map file warning

> bfin-elf  -FAIL: PR ld/21233 dynamic symbols with section GC (--undefined)

> bfin-elf  -FAIL: PR ld/21233 dynamic symbols with section GC (--require-defined)

> bfin-elf  -FAIL: PR ld/21233 dynamic symbols with section GC (EXTERN)

> bfin-elf  -FAIL: Build pr22150

> bfin-elf  -FAIL: Build pr20995-2.so

> bfin-elf  -FAIL: undefined symbols in shared lib (dyn reloc)

> score-elf  -FAIL: Build pr22471

> score-elf  -FAIL: DT_TEXTREL map file warning

> score-elf  -FAIL: Build pr22150

> score-elf  -FAIL: -Bsymbolic-functions

> score-elf  -FAIL: Build pr20995-2.so

> score-elf  -FAIL: pr20995

> score-elf  -FAIL: pr20995-2

> sh-rtems  -FAIL: Build pr22471

> sh-rtems  -FAIL: Build pr20995-2.so

> sh-rtems  -FAIL: pr20995

> sh-rtems  -FAIL: pr20995-2

>


Hi Alan,

On my side, after your committed this patch, I've noticed many regressions on
aarch64*-elf and arm-none-eabi:
https://ci.linaro.org/job/tcwg-compare-results/9217/artifact/artifacts/logs/0-report.html

Aren't these targets part of the set you regularly test? Or don't they
regress for you?

Thanks,

Christophe

>         * emulparams/aarch64elf.sh (GENERATE_SHLIB_SCRIPT),

>         (GENERATE_PIE_SCRIPT): Don't set.

>         * emulparams/aarch64elf32.sh (GENERATE_SHLIB_SCRIPT),

>         (GENERATE_PIE_SCRIPT): Don't set.

>         * emulparams/arcelf.sh (GENERATE_SHLIB_SCRIPT): Don't set.

>         * emulparams/armelf.sh (GENERATE_SHLIB_SCRIPT),

>         (GENERATE_PIE_SCRIPT): Don't set.

>         * emulparams/armelf_fbsd.sh (GENERATE_SHLIB_SCRIPT): Set.

>         * emulparams/armelf_nbsd.sh (GENERATE_SHLIB_SCRIPT),

>         (GENERATE_PIE_SCRIPT): Set.

>         * emulparams/armelf_vxworks.sh (GENERATE_SHLIB_SCRIPT): Set.

>         * emulparams/armsymbian.sh (GENERATE_SHLIB_SCRIPT): Set.

>         * emulparams/elf32bfin.sh (GENERATE_SHLIB_SCRIPT): Don't set.

>         * emulparams/elf32microblaze.sh (GENERATE_SHLIB_SCRIPT): Don't set.

>         * emulparams/score3_elf.sh (GENERATE_SHLIB_SCRIPT): Don't set.

>         * emulparams/shelf.sh (GENERATE_SHLIB_SCRIPT): Don't set.

>         * emulparams/shelf_nbsd.sh (GENERATE_SHLIB_SCRIPT),

>         (GENERATE_PIE_SCRIPT): Set.

>         * emulparams/shelf_uclinux.sh (GENERATE_SHLIB_SCRIPT): Set.

>

> diff --git a/ld/emulparams/aarch64elf.sh b/ld/emulparams/aarch64elf.sh

> index 8f68e517b4..5c70b55686 100644

> --- a/ld/emulparams/aarch64elf.sh

> +++ b/ld/emulparams/aarch64elf.sh

> @@ -12,9 +12,6 @@ NO_REL_RELOCS=yes

>  TEMPLATE_NAME=elf

>  EXTRA_EM_FILE=aarch64elf

>

> -GENERATE_SHLIB_SCRIPT=yes

> -GENERATE_PIE_SCRIPT=yes

> -

>  MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"

>

>  ENTRY=_start

> diff --git a/ld/emulparams/aarch64elf32.sh b/ld/emulparams/aarch64elf32.sh

> index 5a08d9e29f..a94025a139 100644

> --- a/ld/emulparams/aarch64elf32.sh

> +++ b/ld/emulparams/aarch64elf32.sh

> @@ -12,9 +12,6 @@ NO_REL_RELOCS=yes

>  TEMPLATE_NAME=elf

>  EXTRA_EM_FILE=aarch64elf

>

> -GENERATE_SHLIB_SCRIPT=yes

> -GENERATE_PIE_SCRIPT=yes

> -

>  MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"

>

>  ENTRY=_start

> diff --git a/ld/emulparams/arcelf.sh b/ld/emulparams/arcelf.sh

> index 625ec39779..b6d8f9fdf7 100644

> --- a/ld/emulparams/arcelf.sh

> +++ b/ld/emulparams/arcelf.sh

> @@ -19,5 +19,3 @@ SDATA_START_SYMBOLS='__SDATA_BEGIN__ = . + 0x100;'

>  JLI_START_TABLE='__JLI_TABLE__ = .;'

>  OTHER_SECTIONS="/DISCARD/ : { *(.__arc_profile_*) }"

>  EMBEDDED=yes

> -

> -GENERATE_SHLIB_SCRIPT=yes

> diff --git a/ld/emulparams/armelf.sh b/ld/emulparams/armelf.sh

> index 0e3147c1f2..8977fd6fea 100644

> --- a/ld/emulparams/armelf.sh

> +++ b/ld/emulparams/armelf.sh

> @@ -32,9 +32,6 @@ OTHER_READONLY_SECTIONS="

>

>  DATA_START_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__data_start = .${CREATE_SHLIB+)};"

>

> -GENERATE_SHLIB_SCRIPT=yes

> -GENERATE_PIE_SCRIPT=yes

> -

>  ARCH=arm

>  MACHINE=

>  MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"

> diff --git a/ld/emulparams/armelf_fbsd.sh b/ld/emulparams/armelf_fbsd.sh

> index be88c2f2e0..4428b91a34 100644

> --- a/ld/emulparams/armelf_fbsd.sh

> +++ b/ld/emulparams/armelf_fbsd.sh

> @@ -5,7 +5,7 @@ TEXT_START_ADDR=0x00010000

>

>  TARGET2_TYPE=got-rel

>  MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"

> +GENERATE_SHLIB_SCRIPT=yes

>  GENERATE_PIE_SCRIPT=yes

> -

>  unset STACK_ADDR

>  unset EMBEDDED

> diff --git a/ld/emulparams/armelf_nbsd.sh b/ld/emulparams/armelf_nbsd.sh

> index 37e1a4afdd..45954597ee 100644

> --- a/ld/emulparams/armelf_nbsd.sh

> +++ b/ld/emulparams/armelf_nbsd.sh

> @@ -3,5 +3,7 @@ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"

>  TEXT_START_ADDR=0x00008000

>  TARGET2_TYPE=got-rel

>

> +GENERATE_SHLIB_SCRIPT=yes

> +GENERATE_PIE_SCRIPT=yes

>  unset STACK_ADDR

>  unset EMBEDDED

> diff --git a/ld/emulparams/armelf_vxworks.sh b/ld/emulparams/armelf_vxworks.sh

> index 5f57535fee..e344209905 100644

> --- a/ld/emulparams/armelf_vxworks.sh

> +++ b/ld/emulparams/armelf_vxworks.sh

> @@ -4,3 +4,4 @@ BIG_OUTPUT_FORMAT="elf32-bigarm-vxworks"

>  LITTLE_OUTPUT_FORMAT="$OUTPUT_FORMAT"

>  MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"

>  source_sh ${srcdir}/emulparams/vxworks.sh

> +GENERATE_SHLIB_SCRIPT=yes

> diff --git a/ld/emulparams/armsymbian.sh b/ld/emulparams/armsymbian.sh

> index 1959685f9b..183750a564 100644

> --- a/ld/emulparams/armsymbian.sh

> +++ b/ld/emulparams/armsymbian.sh

> @@ -8,6 +8,8 @@ TARGET1_IS_REL=1

>  TARGET2_TYPE=abs

>  # On BPABI systems, program headers should not be mapped.

>  EMBEDDED=yes

> +# Nonetheless, shared libraries are also supported

> +GENERATE_SHLIB_SCRIPT=yes

>

>  # As for armelf.sh, but add the SymbianOS-specific

>  # .ARM.exidx$${Base,Limit} symbols.

> diff --git a/ld/emulparams/elf32bfin.sh b/ld/emulparams/elf32bfin.sh

> index 8d298b467c..6e08035b6f 100644

> --- a/ld/emulparams/elf32bfin.sh

> +++ b/ld/emulparams/elf32bfin.sh

> @@ -6,7 +6,6 @@ TARGET_PAGE_SIZE=0x1000

>  ARCH=bfin

>  MACHINE=

>  TEMPLATE_NAME=elf

> -GENERATE_SHLIB_SCRIPT=yes

>  EMBEDDED=yes

>  USER_LABEL_PREFIX=_

>  EXTRA_EM_FILE=bfin

> diff --git a/ld/emulparams/elf32microblaze.sh b/ld/emulparams/elf32microblaze.sh

> index f867018eb3..698adb7cf8 100644

> --- a/ld/emulparams/elf32microblaze.sh

> +++ b/ld/emulparams/elf32microblaze.sh

> @@ -21,6 +21,3 @@ NOP=0x80000000

>  #OTHER_RELOCATING_SECTIONS='PROVIDE (_stack = _end + 0x1000);'

>

>  TEMPLATE_NAME=elf

> -#GENERATE_SHLIB_SCRIPT=yes

> -

> -

> diff --git a/ld/emulparams/score3_elf.sh b/ld/emulparams/score3_elf.sh

> index 7be7883363..78401876e5 100644

> --- a/ld/emulparams/score3_elf.sh

> +++ b/ld/emulparams/score3_elf.sh

> @@ -26,4 +26,3 @@ ARCH=score3

>  MACHINE=

>  ENTRY=_start

>  EMBEDDED=yes

> -GENERATE_SHLIB_SCRIPT=yes

> diff --git a/ld/emulparams/shelf.sh b/ld/emulparams/shelf.sh

> index 63c2ff19dc..96c18c0750 100644

> --- a/ld/emulparams/shelf.sh

> +++ b/ld/emulparams/shelf.sh

> @@ -9,7 +9,6 @@ MAXPAGESIZE=128

>  ARCH=sh

>  MACHINE=

>  TEMPLATE_NAME=elf

> -GENERATE_SHLIB_SCRIPT=yes

>  EMBEDDED=yes

>  # These are for compatibility with the COFF toolchain.

>  ENTRY=start

> diff --git a/ld/emulparams/shelf_nbsd.sh b/ld/emulparams/shelf_nbsd.sh

> index 391399660d..57db803d00 100644

> --- a/ld/emulparams/shelf_nbsd.sh

> +++ b/ld/emulparams/shelf_nbsd.sh

> @@ -11,5 +11,7 @@ DATA_START_SYMBOLS='PROVIDE (__data_start = .);';

>

>  ENTRY=_start

>

> +GENERATE_SHLIB_SCRIPT=yes

> +GENERATE_PIE_SCRIPT=yes

>  unset EMBEDDED

>  unset STACK_ADDR

> diff --git a/ld/emulparams/shelf_uclinux.sh b/ld/emulparams/shelf_uclinux.sh

> index a22c35a9a8..41044f028c 100644

> --- a/ld/emulparams/shelf_uclinux.sh

> +++ b/ld/emulparams/shelf_uclinux.sh

> @@ -2,3 +2,4 @@ source_sh ${srcdir}/emulparams/shelf.sh

>

>  # We do not want a .stack section

>  unset STACK_ADDR

> +GENERATE_SHLIB_SCRIPT=yes

>

> --

> Alan Modra

> Australia Development Lab, IBM
Alan Modra Nov. 5, 2019, 10:03 a.m. | #2
On Tue, Nov 05, 2019 at 09:47:52AM +0100, Christophe Lyon wrote:
> > So, this patch removes GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT

> > in most emulparams files where EMBEDDED is set, restoring the shared

> > lib and pie support in emulparams files that unset EMBEDDED after

> > including a file where the support is removed.

>

> On my side, after your committed this patch, I've noticed many regressions on

> aarch64*-elf and arm-none-eabi:

> https://ci.linaro.org/job/tcwg-compare-results/9217/artifact/artifacts/logs/0-report.html

> 

> Aren't these targets part of the set you regularly test? Or don't they

> regress for you?


Um, I see I only test aarch64-linux and aarch64_be-linux-gnu_ilp32 for
aarch64 so the aarch64-elf changes weren't tested at all.  I test
arm-linuxeabi, arm-nacl, arm-netbsdelf, arm-nto, arm-pe,
arm-symbianelf, arm-vxworks, arm-wince-pe, and armeb-linuxeabi but
that doesn't hit any of the arm-elf targets either.  :-(

Testsuite regressions aside, is the patch wrong for aarch64-elf and
arm-elf targets?  That's the real question here.  Or should
aarch64-elf and perhaps arm-elf *not* set EMBEDDED and instead
provide the usual shared lib and PIE support?

-- 
Alan Modra
Australia Development Lab, IBM
Richard Earnshaw (lists) Nov. 6, 2019, 10:12 a.m. | #3
On 05/11/2019 10:03, Alan Modra wrote:
> On Tue, Nov 05, 2019 at 09:47:52AM +0100, Christophe Lyon wrote:

>>> So, this patch removes GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT

>>> in most emulparams files where EMBEDDED is set, restoring the shared

>>> lib and pie support in emulparams files that unset EMBEDDED after

>>> including a file where the support is removed.

>>

>> On my side, after your committed this patch, I've noticed many regressions on

>> aarch64*-elf and arm-none-eabi:

>> https://ci.linaro.org/job/tcwg-compare-results/9217/artifact/artifacts/logs/0-report.html

>>

>> Aren't these targets part of the set you regularly test? Or don't they

>> regress for you?

> 

> Um, I see I only test aarch64-linux and aarch64_be-linux-gnu_ilp32 for

> aarch64 so the aarch64-elf changes weren't tested at all.  I test

> arm-linuxeabi, arm-nacl, arm-netbsdelf, arm-nto, arm-pe,

> arm-symbianelf, arm-vxworks, arm-wince-pe, and armeb-linuxeabi but

> that doesn't hit any of the arm-elf targets either.  :-(

> 

> Testsuite regressions aside, is the patch wrong for aarch64-elf and

> arm-elf targets?  That's the real question here.  Or should

> aarch64-elf and perhaps arm-elf *not* set EMBEDDED and instead

> provide the usual shared lib and PIE support?

> 


The ld.log file for arm-elf is showing a lot of messages like


/work/rearnsha/scratch/nightly/arm/trunk/ld/ld-new: -shared not supported
/work/rearnsha/scratch/nightly/arm/trunk/ld/ld-new: -shared not supported
FAIL: Thumb and -gc-sections

For the tests that previously passed.

Similarly for aarch64.

R.
Alan Modra Nov. 7, 2019, 1:27 a.m. | #4
On Wed, Nov 06, 2019 at 10:12:42AM +0000, Richard Earnshaw (lists) wrote:
> On 05/11/2019 10:03, Alan Modra wrote:

> > Testsuite regressions aside, is the patch wrong for aarch64-elf and

> > arm-elf targets?  That's the real question here.  Or should

> > aarch64-elf and perhaps arm-elf *not* set EMBEDDED and instead

> > provide the usual shared lib and PIE support?

> > 

> 

> The ld.log file for arm-elf is showing a lot of messages like

> 

> 

> /work/rearnsha/scratch/nightly/arm/trunk/ld/ld-new: -shared not supported

> /work/rearnsha/scratch/nightly/arm/trunk/ld/ld-new: -shared not supported

> FAIL: Thumb and -gc-sections

> 

> For the tests that previously passed.

> 

> Similarly for aarch64.


Yes, that's what I'd expect.  I'll commit the following to tidy the
testsuite results.

	* testsuite/ld-aarch64/aarch64-elf.exp: Run tests requiring pie
	or shared library support only when check_shared_lib_support.
	* testsuite/ld-aarch64/bti-pac-plt-1.d: Likewise.
	* testsuite/ld-aarch64/bti-pac-plt-2.d: Likewise.
	* testsuite/ld-aarch64/bti-plt-1.d: Likewise.
	* testsuite/ld-aarch64/bti-plt-2.d: Likewise.
	* testsuite/ld-aarch64/bti-plt-3.d: Likewise.
	* testsuite/ld-aarch64/bti-plt-4.d: Likewise.
	* testsuite/ld-aarch64/bti-plt-6.d: Likewise.
	* testsuite/ld-aarch64/bti-plt-7.d: Likewise.
	* testsuite/ld-aarch64/bti-warn.d: Likewise.
	* testsuite/ld-aarch64/dt_textrel.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-264-bad.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-266-bad.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-268-bad.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-269-bad.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-515-be.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-515.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-516-be.d: Likewise.
	* testsuite/ld-aarch64/emit-relocs-516.d: Likewise.
	* testsuite/ld-aarch64/farcall-b-plt.d: Likewise.
	* testsuite/ld-aarch64/farcall-bl-plt.d: Likewise.
	* testsuite/ld-aarch64/gc-plt-relocs.d: Likewise.
	* testsuite/ld-aarch64/gc-relocs-257-dyn.d: Likewise.
	* testsuite/ld-aarch64/ifunc-1-local.d: Likewise.
	* testsuite/ld-aarch64/ifunc-1.d: Likewise.
	* testsuite/ld-aarch64/ifunc-12.d: Likewise.
	* testsuite/ld-aarch64/ifunc-13.d: Likewise.
	* testsuite/ld-aarch64/ifunc-14a.d: Likewise.
	* testsuite/ld-aarch64/ifunc-14b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-14c.d: Likewise.
	* testsuite/ld-aarch64/ifunc-14d.d: Likewise.
	* testsuite/ld-aarch64/ifunc-14e.d: Likewise.
	* testsuite/ld-aarch64/ifunc-14f.d: Likewise.
	* testsuite/ld-aarch64/ifunc-15.d: Likewise.
	* testsuite/ld-aarch64/ifunc-16.d: Likewise.
	* testsuite/ld-aarch64/ifunc-18a.d: Likewise.
	* testsuite/ld-aarch64/ifunc-18b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-19a.d: Likewise.
	* testsuite/ld-aarch64/ifunc-19b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-2-local.d: Likewise.
	* testsuite/ld-aarch64/ifunc-2.d: Likewise.
	* testsuite/ld-aarch64/ifunc-20.d: Likewise.
	* testsuite/ld-aarch64/ifunc-21.d: Likewise.
	* testsuite/ld-aarch64/ifunc-3a.d: Likewise.
	* testsuite/ld-aarch64/ifunc-3b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-5b-local.d: Likewise.
	* testsuite/ld-aarch64/ifunc-5b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-6b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-7b.d: Likewise.
	* testsuite/ld-aarch64/ifunc-7c.d: Likewise.
	* testsuite/ld-aarch64/pac-plt-1.d: Likewise.
	* testsuite/ld-aarch64/pac-plt-2.d: Likewise.
	* testsuite/ld-aarch64/pcrel_pic_defined.d: Likewise.
	* testsuite/ld-aarch64/pcrel_pic_undefined.d: Likewise.
	* testsuite/ld-aarch64/pie-bind-locally.d: Likewise.
	* testsuite/ld-aarch64/plt_mapping_symbol.d: Likewise.
	* testsuite/ld-aarch64/pr20402.d: Likewise.
	* testsuite/ld-aarch64/pr22764.d: Likewise.
	* testsuite/ld-aarch64/property-bti-pac1.d: Likewise.
	* testsuite/ld-aarch64/protected-data.d: Likewise.
	* testsuite/ld-aarch64/rela-abs-relative-be.d: Likewise.
	* testsuite/ld-aarch64/rela-abs-relative-opt.d: Likewise.
	* testsuite/ld-aarch64/rela-abs-relative.d: Likewise.
	* testsuite/ld-aarch64/relasz.d: Likewise.
	* testsuite/ld-aarch64/relocs-1027-symbolic-func.d: Likewise.
	* testsuite/ld-aarch64/tls-desc-ie-ilp32.d: Likewise.
	* testsuite/ld-aarch64/tls-desc-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-large-desc-be.d: Likewise.
	* testsuite/ld-aarch64/tls-large-desc.d: Likewise.
	* testsuite/ld-aarch64/tls-large-ie-be.d: Likewise.
	* testsuite/ld-aarch64/tls-large-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-relax-gdesc-le-now.d: Likewise.
	* testsuite/ld-aarch64/tls-small-ld.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-desc.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-gd.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-ie.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-ld.d: Likewise.
	* testsuite/ld-aarch64/tlsle-symbol-offset.d: Likewise.
	* testsuite/ld-aarch64/tlsle.d: Likewise.
	* testsuite/ld-aarch64/variant_pcs-now.d: Likewise.
	* testsuite/ld-aarch64/variant_pcs-shared.d: Likewise.
	* testsuite/ld-arm/arm-elf.exp: Likewise.  Remove --hash-style=sysv
	from static tests.  Consolidate armelftests_common_* vars into one.
	* testsuite/ld-arm/gc-hidden-1.d: Require check_shared_lib_support.
	* testsuite/ld-arm/movw-shared-1.d: Likewise.
	* testsuite/ld-arm/movw-shared-2.d: Likewise.
	* testsuite/ld-arm/movw-shared-3.d: Likewise.
	* testsuite/ld-arm/movw-shared-4.d: Likewise.
	* testsuite/ld-arm/pie-bind-locally.d: Likewise.
	* testsuite/ld-arm/protected-data.d: Likewise.
	* testsuite/ld-arm/rel32-reject-pie.d: Likewise.
	* testsuite/ld-arm/rel32-reject.d: Likewise.
	* testsuite/ld-arm/thumb2-bl-undefweak.d: Likewise.
	* testsuite/ld-arm/thumb2-bl-undefweak1.d: Likewise.

diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 631fde0f31..2b053d1ee7 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -37,11 +37,14 @@ set aarch64elftests {
      "--fix-cortex-a53-835769" "" "" {erratum835769.s}
      {{objdump -dr erratum835769.d}}
      "erratum835769"}
+}
+set tmp {
     {"Erratum 835769 dump test -shared"
      "--fix-cortex-a53-835769 -shared" "" "" {erratum835769.s}
      {{objdump -dr erratum835769.d}}
      "erratum835769"}
 }
+if [check_shared_lib_support] { append aarch64elftests $tmp }
 
 proc aarch64_choose_ilp32_emul {} {
     if [istarget *linux*] then {
@@ -410,7 +413,9 @@ set aarch64elflinktests {
     {} "libbti-plt-so.so"}
 }
 
-run_ld_link_tests $aarch64elflinktests
+if [check_shared_lib_support] {
+    run_ld_link_tests $aarch64elflinktests
+}
 
 run_dump_test "bti-plt-3"
 run_dump_test "bti-plt-4"
diff --git a/ld/testsuite/ld-aarch64/bti-pac-plt-1.d b/ld/testsuite/ld-aarch64/bti-pac-plt-1.d
index e1c6eb7f25..495b304be2 100644
--- a/ld/testsuite/ld-aarch64/bti-pac-plt-1.d
+++ b/ld/testsuite/ld-aarch64/bti-pac-plt-1.d
@@ -1,4 +1,5 @@
 #source: bti-plt-1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64
 #ld: -shared -z force-bti -z pac-plt -T bti-plt.ld
 #objdump: -dr -j .plt
diff --git a/ld/testsuite/ld-aarch64/bti-pac-plt-2.d b/ld/testsuite/ld-aarch64/bti-pac-plt-2.d
index 0c67615ac4..ed39e21ed8 100644
--- a/ld/testsuite/ld-aarch64/bti-pac-plt-2.d
+++ b/ld/testsuite/ld-aarch64/bti-pac-plt-2.d
@@ -1,4 +1,5 @@
 #source: bti-plt-1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64
 #ld: -z force-bti -z pac-plt -e _start -T bti-plt.ld -L./tmpdir -lbti-plt-so
 #objdump: -dr -j .plt
diff --git a/ld/testsuite/ld-aarch64/bti-plt-1.d b/ld/testsuite/ld-aarch64/bti-plt-1.d
index f8414a0164..9fd7c6b2ce 100644
--- a/ld/testsuite/ld-aarch64/bti-plt-1.d
+++ b/ld/testsuite/ld-aarch64/bti-plt-1.d
@@ -1,5 +1,6 @@
 #name: Check -z force-bti emits BTI PLT (shared)
 #source: bti-plt-1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64
 #ld: -shared -z force-bti -T bti-plt.ld
 #objdump: -dr -j .plt
diff --git a/ld/testsuite/ld-aarch64/bti-plt-2.d b/ld/testsuite/ld-aarch64/bti-plt-2.d
index f1c90b92c9..c34ab47bf5 100644
--- a/ld/testsuite/ld-aarch64/bti-plt-2.d
+++ b/ld/testsuite/ld-aarch64/bti-plt-2.d
@@ -1,6 +1,7 @@
 #name: Check -z force-bti emits BTI feature (shared)
 #source: bti-plt-1.s
 #source: bti-plt-2.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64
 #ld: -shared -z force-bti -T bti-plt.ld
 #readelf: -n
diff --git a/ld/testsuite/ld-aarch64/bti-plt-3.d b/ld/testsuite/ld-aarch64/bti-plt-3.d
index 82f08a9869..c82878e1eb 100644
--- a/ld/testsuite/ld-aarch64/bti-plt-3.d
+++ b/ld/testsuite/ld-aarch64/bti-plt-3.d
@@ -1,5 +1,6 @@
 #name: Check -z force-bti emits BTI PLT (exec)
 #source: bti-plt-1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64
 #ld: -z force-bti -e _start -T bti-plt.ld -L./tmpdir -lbti-plt-so
 #objdump: -dr -j .plt
diff --git a/ld/testsuite/ld-aarch64/bti-plt-4.d b/ld/testsuite/ld-aarch64/bti-plt-4.d
index 496e124215..04d3c7d963 100644
--- a/ld/testsuite/ld-aarch64/bti-plt-4.d
+++ b/ld/testsuite/ld-aarch64/bti-plt-4.d
@@ -1,5 +1,6 @@
 #name: Check -z force-bti emits BTI feature (exec)
 #source: bti-plt-1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64
 #ld: -z force-bti -e _start -T bti-plt.ld -L./tmpdir -lbti-plt-so
 #readelf: -n
diff --git a/ld/testsuite/ld-aarch64/bti-plt-6.d b/ld/testsuite/ld-aarch64/bti-plt-6.d
index efb368ba15..df5c063431 100644
--- a/ld/testsuite/ld-aarch64/bti-plt-6.d
+++ b/ld/testsuite/ld-aarch64/bti-plt-6.d
@@ -1,6 +1,7 @@
 #name: Warn with one missing GNU NOTE BTI input
 #source: property-bti-pac2.s
 #source: property-bti-pac1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64 -defsym __property_pac__=1
 #ld: -shared -z force-bti
 #warning: .*property-bti-pac2.*: warning: BTI turned on by -z force-bti.*$
diff --git a/ld/testsuite/ld-aarch64/bti-plt-7.d b/ld/testsuite/ld-aarch64/bti-plt-7.d
index e3e84c32f0..4d23290243 100644
--- a/ld/testsuite/ld-aarch64/bti-plt-7.d
+++ b/ld/testsuite/ld-aarch64/bti-plt-7.d
@@ -1,6 +1,7 @@
 #name: Warn when neither inputs has GNU NOTE BTI
 #source: property-bti-pac2.s
 #source: plt_mapping_symbol.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64
 #ld: -shared -z force-bti
 #warning: .*plt_mapping_symbol.*: warning: BTI turned on by -z force-bti.*
diff --git a/ld/testsuite/ld-aarch64/bti-warn.d b/ld/testsuite/ld-aarch64/bti-warn.d
index 0e3954d060..d10cd10400 100644
--- a/ld/testsuite/ld-aarch64/bti-warn.d
+++ b/ld/testsuite/ld-aarch64/bti-warn.d
@@ -1,6 +1,7 @@
 #name: Warn when both have GNU prop but neither BTI
 #source: property-bti-pac2.s
 #source: bti-plt-1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64 --defsym __guard_property_bti__=1 --defsym __property_pac__=1
 #ld: -shared -z force-bti
 #warning: .*property-bti-pac2.*: warning: BTI turned on by -z force-bti.*
diff --git a/ld/testsuite/ld-aarch64/dt_textrel.d b/ld/testsuite/ld-aarch64/dt_textrel.d
index e28d164699..356fea8c40 100644
--- a/ld/testsuite/ld-aarch64/dt_textrel.d
+++ b/ld/testsuite/ld-aarch64/dt_textrel.d
@@ -1,4 +1,5 @@
 #source: dt_textrel.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #readelf: -d
 #...
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d
index 4de6e55d0b..54a8dce69f 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d
@@ -1,4 +1,5 @@
 #name: LP64 R_AARCH64_ABS32 shared library test
 #source: emit-relocs-258.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #error: .*: relocation R_AARCH64_ABS32 against `dummy' can not be used when making a shared object
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d
index f133e8991e..eaa249833d 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d
@@ -1,4 +1,5 @@
 #name: R_AARCH64_ABS16 shared library test
 #source: emit-relocs-259.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #error: .*: relocation R_AARCH64_ABS16 against `dummy' can not be used when making a shared object
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-264-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-264-bad.d
index 22718cad60..26e16e1d83 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-264-bad.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-264-bad.d
@@ -1,3 +1,4 @@
 #source: emit-relocs-264.s
+#target: [check_shared_lib_support]
 #ld: -T relocs.ld --defsym tempy=0x11000 --defsym tempy2=0x45000 --defsym tempy3=0x1234  -e0 -shared
 #error: .*relocation R_AARCH64_MOVW_UABS_G0_NC.*can not.*shared object.*fPIC
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-266-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-266-bad.d
index 886494df51..b27ab4cd16 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-266-bad.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-266-bad.d
@@ -1,3 +1,4 @@
 #source: emit-relocs-266.s
+#target: [check_shared_lib_support]
 #ld: -T relocs.ld --defsym tempy=0x11000 --defsym tempy2=0x45000 --defsym tempy3=0x1234  -e0 -shared
 #error: .*relocation R_AARCH64_MOVW_UABS_G1_NC.*can not.*shared object.*fPIC
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-268-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-268-bad.d
index ea97541c86..bdc4a7de24 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-268-bad.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-268-bad.d
@@ -1,3 +1,4 @@
 #source: emit-relocs-268.s
+#target: [check_shared_lib_support]
 #ld: -T relocs.ld --defsym tempy=0x11000 --defsym tempy2=0x45000 --defsym tempy3=0x1234  -e0 -shared
 #error: .*relocation R_AARCH64_MOVW_UABS_G2_NC.*can not.*shared object.*fPIC
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-269-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-269-bad.d
index 9292855f73..b201fc7239 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-269-bad.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-269-bad.d
@@ -1,3 +1,4 @@
 #source: emit-relocs-269.s
+#target: [check_shared_lib_support]
 #ld: -T relocs.ld --defsym tempy=0x11000 --defsym tempy2=0x45000 --defsym tempy3=0x1234  -e0 -shared
 #error: .*relocation R_AARCH64_MOVW_UABS_G3.*can not.*shared object.*fPIC
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-515-be.d b/ld/testsuite/ld-aarch64/emit-relocs-515-be.d
index 82d5bd688b..7de1fb0c84 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-515-be.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-515-be.d
@@ -1,4 +1,5 @@
 #source: emit-relocs-515.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-515.d b/ld/testsuite/ld-aarch64/emit-relocs-515.d
index 9d84bf16e6..535f5f5bd0 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-515.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-515.d
@@ -1,4 +1,5 @@
 #source: emit-relocs-515.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64_be-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-516-be.d b/ld/testsuite/ld-aarch64/emit-relocs-516-be.d
index 23332b0b94..5a0b05cadc 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-516-be.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-516-be.d
@@ -1,4 +1,5 @@
 #source: emit-relocs-516.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-516.d b/ld/testsuite/ld-aarch64/emit-relocs-516.d
index e2ad1d6bd6..72b36312cd 100644
--- a/ld/testsuite/ld-aarch64/emit-relocs-516.d
+++ b/ld/testsuite/ld-aarch64/emit-relocs-516.d
@@ -1,4 +1,5 @@
 #source: emit-relocs-516.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64_be-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/farcall-b-plt.d b/ld/testsuite/ld-aarch64/farcall-b-plt.d
index e20b9c3946..90dc243b68 100644
--- a/ld/testsuite/ld-aarch64/farcall-b-plt.d
+++ b/ld/testsuite/ld-aarch64/farcall-b-plt.d
@@ -1,5 +1,6 @@
 #name: aarch64-farcall-b-plt
 #source: farcall-b-plt.s
+#target: [check_shared_lib_support]
 #as:
 #ld: -shared
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/farcall-bl-plt.d b/ld/testsuite/ld-aarch64/farcall-bl-plt.d
index 7c3de4a446..a8d78d3897 100644
--- a/ld/testsuite/ld-aarch64/farcall-bl-plt.d
+++ b/ld/testsuite/ld-aarch64/farcall-bl-plt.d
@@ -1,5 +1,6 @@
 #name: aarch64-farcall-bl-plt
 #source: farcall-bl-plt.s
+#target: [check_shared_lib_support]
 #as:
 #ld: -shared
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/gc-plt-relocs.d b/ld/testsuite/ld-aarch64/gc-plt-relocs.d
index 07c92ddf1f..5c9b5fe557 100644
--- a/ld/testsuite/ld-aarch64/gc-plt-relocs.d
+++ b/ld/testsuite/ld-aarch64/gc-plt-relocs.d
@@ -2,6 +2,7 @@
 #source: gc-plt-main.s
 #source: gc-plt-hidden.s
 #source: gc-plt2.s
+#target: [check_shared_lib_support]
 #ld: --gc-sections -T aarch64.ld --shared --hash-style=sysv
 #objdump: -dT
 
diff --git a/ld/testsuite/ld-aarch64/gc-relocs-257-dyn.d b/ld/testsuite/ld-aarch64/gc-relocs-257-dyn.d
index f1f7eb6d5b..56fcfa4fdc 100644
--- a/ld/testsuite/ld-aarch64/gc-relocs-257-dyn.d
+++ b/ld/testsuite/ld-aarch64/gc-relocs-257-dyn.d
@@ -1,5 +1,6 @@
 #source: gc-start.s
 #source: gc-relocs-257.s
+#target: [check_shared_lib_support]
 #ld: --defsym tempy=0x11012 --defsym tempy2=0x45034 --defsym tempy3=0x1234   -T aarch64.ld   -shared  --gc-sections
 #objdump: -R -d
 
diff --git a/ld/testsuite/ld-aarch64/ifunc-1-local.d b/ld/testsuite/ld-aarch64/ifunc-1-local.d
index 1783637865..0d4a92ce43 100644
--- a/ld/testsuite/ld-aarch64/ifunc-1-local.d
+++ b/ld/testsuite/ld-aarch64/ifunc-1-local.d
@@ -1,6 +1,6 @@
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv
 #objdump: -dw
-#target: aarch64*-*-*
 
 #...
 0+(110|180|1a0) <(__GI_)?foo>:
diff --git a/ld/testsuite/ld-aarch64/ifunc-1.d b/ld/testsuite/ld-aarch64/ifunc-1.d
index 0274ac0094..0f7a3fab33 100644
--- a/ld/testsuite/ld-aarch64/ifunc-1.d
+++ b/ld/testsuite/ld-aarch64/ifunc-1.d
@@ -1,6 +1,6 @@
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv
 #objdump: -dw
-#target: aarch64*-*-*
 
 #...
 0+(130|1a0|1c8) <foo>:
diff --git a/ld/testsuite/ld-aarch64/ifunc-12.d b/ld/testsuite/ld-aarch64/ifunc-12.d
index 8fa8ce0f35..7d01e766ea 100644
--- a/ld/testsuite/ld-aarch64/ifunc-12.d
+++ b/ld/testsuite/ld-aarch64/ifunc-12.d
@@ -1,5 +1,5 @@
+#target: [check_shared_lib_support]
 #ld: -shared -e bar --gc-sections
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 There are no relocations in this file.
diff --git a/ld/testsuite/ld-aarch64/ifunc-13.d b/ld/testsuite/ld-aarch64/ifunc-13.d
index 75ba03ff3f..7c0b7acc04 100644
--- a/ld/testsuite/ld-aarch64/ifunc-13.d
+++ b/ld/testsuite/ld-aarch64/ifunc-13.d
@@ -1,8 +1,8 @@
 #source: ifunc-13a.s
 #source: ifunc-13b.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.ifunc' at offset 0x[0-9a-f]+ contains 1 entry:
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-14a.d b/ld/testsuite/ld-aarch64/ifunc-14a.d
index ff580d0a3c..959b495180 100644
--- a/ld/testsuite/ld-aarch64/ifunc-14a.d
+++ b/ld/testsuite/ld-aarch64/ifunc-14a.d
@@ -1,8 +1,8 @@
 #source: ifunc-14a.s
 #source: ifunc-14b.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -d
-#target: aarch64*-*-*
 
 #failif
 #...
diff --git a/ld/testsuite/ld-aarch64/ifunc-14b.d b/ld/testsuite/ld-aarch64/ifunc-14b.d
index 52ed2b4e1e..ac4db0bdc2 100644
--- a/ld/testsuite/ld-aarch64/ifunc-14b.d
+++ b/ld/testsuite/ld-aarch64/ifunc-14b.d
@@ -1,8 +1,8 @@
 #source: ifunc-14b.s
 #source: ifunc-14a.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -d
-#target: aarch64*-*-*
 
 #failif
 #...
diff --git a/ld/testsuite/ld-aarch64/ifunc-14c.d b/ld/testsuite/ld-aarch64/ifunc-14c.d
index a83126f807..0618a22ea7 100644
--- a/ld/testsuite/ld-aarch64/ifunc-14c.d
+++ b/ld/testsuite/ld-aarch64/ifunc-14c.d
@@ -1,8 +1,8 @@
 #source: ifunc-14a.s
 #source: ifunc-14b.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 #failif
 #...
diff --git a/ld/testsuite/ld-aarch64/ifunc-14d.d b/ld/testsuite/ld-aarch64/ifunc-14d.d
index 4ae88d22ea..0aa505c276 100644
--- a/ld/testsuite/ld-aarch64/ifunc-14d.d
+++ b/ld/testsuite/ld-aarch64/ifunc-14d.d
@@ -1,8 +1,8 @@
 #source: ifunc-14b.s
 #source: ifunc-14a.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 #failif
 #...
diff --git a/ld/testsuite/ld-aarch64/ifunc-14e.d b/ld/testsuite/ld-aarch64/ifunc-14e.d
index 62de35ece4..0224bd0945 100644
--- a/ld/testsuite/ld-aarch64/ifunc-14e.d
+++ b/ld/testsuite/ld-aarch64/ifunc-14e.d
@@ -1,9 +1,9 @@
 #source: ifunc-14a.s
 #source: ifunc-14c.s
 #source: ifunc-14b.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 #failif
 #...
diff --git a/ld/testsuite/ld-aarch64/ifunc-14f.d b/ld/testsuite/ld-aarch64/ifunc-14f.d
index ab8bdbfed7..f4b4a64503 100644
--- a/ld/testsuite/ld-aarch64/ifunc-14f.d
+++ b/ld/testsuite/ld-aarch64/ifunc-14f.d
@@ -1,9 +1,9 @@
 #source: ifunc-14a.s
 #source: ifunc-14b.s
 #source: ifunc-14c.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 #failif
 #...
diff --git a/ld/testsuite/ld-aarch64/ifunc-15.d b/ld/testsuite/ld-aarch64/ifunc-15.d
index 66bb988abd..43ae8c59aa 100644
--- a/ld/testsuite/ld-aarch64/ifunc-15.d
+++ b/ld/testsuite/ld-aarch64/ifunc-15.d
@@ -1,7 +1,7 @@
 #source: ifunc-15.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.got' at offset 0x[0-9a-f]+ contains 1 entry:
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-16.d b/ld/testsuite/ld-aarch64/ifunc-16.d
index 9a20b617f6..eb49cfb15b 100644
--- a/ld/testsuite/ld-aarch64/ifunc-16.d
+++ b/ld/testsuite/ld-aarch64/ifunc-16.d
@@ -1,7 +1,7 @@
 #source: ifunc-16.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.plt' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-18a.d b/ld/testsuite/ld-aarch64/ifunc-18a.d
index 3db91d3486..0dcb09ee68 100644
--- a/ld/testsuite/ld-aarch64/ifunc-18a.d
+++ b/ld/testsuite/ld-aarch64/ifunc-18a.d
@@ -1,8 +1,8 @@
 #source: ifunc-18a.s
 #source: ifunc-18b.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.ifunc' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-18b.d b/ld/testsuite/ld-aarch64/ifunc-18b.d
index b27f526365..8694298f73 100644
--- a/ld/testsuite/ld-aarch64/ifunc-18b.d
+++ b/ld/testsuite/ld-aarch64/ifunc-18b.d
@@ -1,8 +1,8 @@
 #source: ifunc-18b.s
 #source: ifunc-18a.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.ifunc' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-19a.d b/ld/testsuite/ld-aarch64/ifunc-19a.d
index dd82b24787..c68dfd891e 100644
--- a/ld/testsuite/ld-aarch64/ifunc-19a.d
+++ b/ld/testsuite/ld-aarch64/ifunc-19a.d
@@ -1,8 +1,8 @@
 #source: ifunc-19a.s
 #source: ifunc-19b.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.ifunc' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-19b.d b/ld/testsuite/ld-aarch64/ifunc-19b.d
index 1e0819c0e8..6d66351c3f 100644
--- a/ld/testsuite/ld-aarch64/ifunc-19b.d
+++ b/ld/testsuite/ld-aarch64/ifunc-19b.d
@@ -1,8 +1,8 @@
 #source: ifunc-19b.s
 #source: ifunc-19a.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.ifunc' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-2-local.d b/ld/testsuite/ld-aarch64/ifunc-2-local.d
index a3d9e15f8b..c4054e7f80 100644
--- a/ld/testsuite/ld-aarch64/ifunc-2-local.d
+++ b/ld/testsuite/ld-aarch64/ifunc-2-local.d
@@ -1,6 +1,6 @@
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv
 #objdump: -dw
-#target: aarch64*-*-*
 
 #...
 0+(110|180|1a0) <__GI_foo>:
diff --git a/ld/testsuite/ld-aarch64/ifunc-2.d b/ld/testsuite/ld-aarch64/ifunc-2.d
index eb6fa0ccf0..ed8d47dfbb 100644
--- a/ld/testsuite/ld-aarch64/ifunc-2.d
+++ b/ld/testsuite/ld-aarch64/ifunc-2.d
@@ -1,6 +1,6 @@
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv
 #objdump: -dw
-#target: aarch64*-*-*
 
 #...
 0+(130|1a0|1c8) <foo>:
diff --git a/ld/testsuite/ld-aarch64/ifunc-20.d b/ld/testsuite/ld-aarch64/ifunc-20.d
index 603ba075cf..f00dea0a91 100644
--- a/ld/testsuite/ld-aarch64/ifunc-20.d
+++ b/ld/testsuite/ld-aarch64/ifunc-20.d
@@ -1,7 +1,7 @@
 #source: ifunc-20.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.ifunc' at offset 0x[0-9a-f]+ contains 1 entry:
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-21.d b/ld/testsuite/ld-aarch64/ifunc-21.d
index a16186b587..28115d2a9b 100644
--- a/ld/testsuite/ld-aarch64/ifunc-21.d
+++ b/ld/testsuite/ld-aarch64/ifunc-21.d
@@ -1,7 +1,7 @@
 #source: ifunc-21.s
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv -z nocombreloc
 #objdump: -d -s -j .got.plt -j .text
-#target: aarch64*-*-*
 
 # Ensure the .got.plt slot used is correct
 
diff --git a/ld/testsuite/ld-aarch64/ifunc-3a.d b/ld/testsuite/ld-aarch64/ifunc-3a.d
index 4919d96892..464364729f 100644
--- a/ld/testsuite/ld-aarch64/ifunc-3a.d
+++ b/ld/testsuite/ld-aarch64/ifunc-3a.d
@@ -1,7 +1,7 @@
 #source: ifunc-3.s
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv
 #objdump: -dw
-#target: aarch64*-*-*
 
 #...
 0+(150|1d0|1e8) <__GI_foo>:
diff --git a/ld/testsuite/ld-aarch64/ifunc-3b.d b/ld/testsuite/ld-aarch64/ifunc-3b.d
index 7e177a61e5..2d2ec411a4 100644
--- a/ld/testsuite/ld-aarch64/ifunc-3b.d
+++ b/ld/testsuite/ld-aarch64/ifunc-3b.d
@@ -1,7 +1,7 @@
 #source: ifunc-3.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 #...
 [0-9a-f]+[ ]+[0-9a-f]+[ ]+R_[_0-9A-Z]+_IRELATIVE[ ]*[0-9a-f]*
diff --git a/ld/testsuite/ld-aarch64/ifunc-5b-local.d b/ld/testsuite/ld-aarch64/ifunc-5b-local.d
index 1a7cab70fc..c69d05be57 100644
--- a/ld/testsuite/ld-aarch64/ifunc-5b-local.d
+++ b/ld/testsuite/ld-aarch64/ifunc-5b-local.d
@@ -1,7 +1,7 @@
 #source: ifunc-5-local.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.plt' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-5b.d b/ld/testsuite/ld-aarch64/ifunc-5b.d
index 03a7837b12..58beca2a54 100644
--- a/ld/testsuite/ld-aarch64/ifunc-5b.d
+++ b/ld/testsuite/ld-aarch64/ifunc-5b.d
@@ -1,7 +1,7 @@
 #source: ifunc-5.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.got' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-6b.d b/ld/testsuite/ld-aarch64/ifunc-6b.d
index d7248e83a2..a8ff819002 100644
--- a/ld/testsuite/ld-aarch64/ifunc-6b.d
+++ b/ld/testsuite/ld-aarch64/ifunc-6b.d
@@ -1,7 +1,7 @@
 #source: ifunc-6.s
+#target: [check_shared_lib_support]
 #ld: -shared -z nocombreloc
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.got' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-7b.d b/ld/testsuite/ld-aarch64/ifunc-7b.d
index ff1e73ea7c..aa871e940c 100644
--- a/ld/testsuite/ld-aarch64/ifunc-7b.d
+++ b/ld/testsuite/ld-aarch64/ifunc-7b.d
@@ -1,7 +1,7 @@
 #source: ifunc-7.s
 #ld: -shared
+#target: [check_shared_lib_support]
 #readelf: -r --wide
-#target: aarch64*-*-*
 
 Relocation section '.rela.plt' at .*
 [ ]+Offset[ ]+Info[ ]+Type[ ]+.*
diff --git a/ld/testsuite/ld-aarch64/ifunc-7c.d b/ld/testsuite/ld-aarch64/ifunc-7c.d
index e56322a4a2..e526fea4b7 100644
--- a/ld/testsuite/ld-aarch64/ifunc-7c.d
+++ b/ld/testsuite/ld-aarch64/ifunc-7c.d
@@ -1,7 +1,7 @@
 #source: ifunc-7.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #objdump: -dr -j .text
-#target: aarch64*-*-*
 
 # Check if adrp and ldr have been relocated correctly.
 
diff --git a/ld/testsuite/ld-aarch64/pac-plt-1.d b/ld/testsuite/ld-aarch64/pac-plt-1.d
index 06278ef15f..ac9467035c 100644
--- a/ld/testsuite/ld-aarch64/pac-plt-1.d
+++ b/ld/testsuite/ld-aarch64/pac-plt-1.d
@@ -1,4 +1,5 @@
 #source: bti-plt-1.s
+#target: [check_shared_lib_support]
 #as: -mabi=lp64 --defsym __guard_property_bti__=1
 #ld: -shared -z pac-plt -T bti-plt.ld
 #objdump: -dr -j .plt
diff --git a/ld/testsuite/ld-aarch64/pac-plt-2.d b/ld/testsuite/ld-aarch64/pac-plt-2.d
index b5cf43d3d4..611bf8bd50 100644
--- a/ld/testsuite/ld-aarch64/pac-plt-2.d
+++ b/ld/testsuite/ld-aarch64/pac-plt-2.d
@@ -1,4 +1,5 @@
 #source: tls-desc-ie.s
+#target: [check_shared_lib_support]
 #ld: -shared -z pac-plt -T bti-plt.ld
 #objdump: -dr -j .plt
 #...
diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_defined.d b/ld/testsuite/ld-aarch64/pcrel_pic_defined.d
index a611e313ff..26b70a6aa8 100644
--- a/ld/testsuite/ld-aarch64/pcrel_pic_defined.d
+++ b/ld/testsuite/ld-aarch64/pcrel_pic_defined.d
@@ -1,5 +1,6 @@
 #name: PC-Rel relocation against defined
 #source: pcrel.s
+#target: [check_shared_lib_support]
 #ld: -shared -e0 -defsym global_a=0x1000 -defsym global_b=0x2000
 #error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.*
 #error: .*: dangerous relocation: unsupported relocation
diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d b/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d
index b5d6372235..fd8ddb38a8 100644
--- a/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d
+++ b/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d
@@ -1,5 +1,6 @@
 #name: PC-Rel relocation against undefined
 #source: pcrel.s
+#target: [check_shared_lib_support]
 #ld: -shared -e0 -defsym global_b=0x2000
 #error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.*
 #error: .*: dangerous relocation: unsupported relocation
diff --git a/ld/testsuite/ld-aarch64/pie-bind-locally.d b/ld/testsuite/ld-aarch64/pie-bind-locally.d
index 3689543a9f..a8a27fbbf0 100644
--- a/ld/testsuite/ld-aarch64/pie-bind-locally.d
+++ b/ld/testsuite/ld-aarch64/pie-bind-locally.d
@@ -1,5 +1,6 @@
 #source: pie-bind-locally-a.s
 #source: pie-bind-locally-b.s
+#target: [check_shared_lib_support]
 #ld: -pie
 #readelf: -Wr
 
diff --git a/ld/testsuite/ld-aarch64/plt_mapping_symbol.d b/ld/testsuite/ld-aarch64/plt_mapping_symbol.d
index 3b86cff47e..f1ffd077fe 100644
--- a/ld/testsuite/ld-aarch64/plt_mapping_symbol.d
+++ b/ld/testsuite/ld-aarch64/plt_mapping_symbol.d
@@ -1,7 +1,8 @@
+#name: AArch64 mapping symbol for plt section test.
 #source: plt_mapping_symbol.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #objdump: --syms --special-syms
-#name: AArch64 mapping symbol for plt section test.
 #...
 
 SYMBOL TABLE:
diff --git a/ld/testsuite/ld-aarch64/pr20402.d b/ld/testsuite/ld-aarch64/pr20402.d
index 9cfeeb76dd..0c7ca17b83 100644
--- a/ld/testsuite/ld-aarch64/pr20402.d
+++ b/ld/testsuite/ld-aarch64/pr20402.d
@@ -1,3 +1,4 @@
+#target: [check_shared_lib_support]
 #ld: -pie -defsym foo=0x1 -defsym bar=0x2
 #readelf: -r
 
diff --git a/ld/testsuite/ld-aarch64/pr22764.d b/ld/testsuite/ld-aarch64/pr22764.d
index 997519f469..4830d223ce 100644
--- a/ld/testsuite/ld-aarch64/pr22764.d
+++ b/ld/testsuite/ld-aarch64/pr22764.d
@@ -1,4 +1,5 @@
 #source: pr22764.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -defsym sym_abs1=0x1 -defsym sym_abs2=0x2 -defsym sym_abs3=0x3 -e0 --emit-relocs
 #notarget: aarch64_be-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/property-bti-pac1.d b/ld/testsuite/ld-aarch64/property-bti-pac1.d
index 3acb850a32..59fa695165 100644
--- a/ld/testsuite/ld-aarch64/property-bti-pac1.d
+++ b/ld/testsuite/ld-aarch64/property-bti-pac1.d
@@ -1,9 +1,9 @@
 #name: GNU Property (single input, combine section)
 #source: property-bti-pac1.s
+#alltargets: [check_shared_lib_support] *linux*
 #as: -march=armv8.5-a -defsym __mult__=0
 #ld: -shared
 #readelf: -n
-#target: *linux*
 
 Displaying notes found in: .note.gnu.property
 [ 	]+Owner[ 	]+Data size[ 	]+Description
diff --git a/ld/testsuite/ld-aarch64/protected-data.d b/ld/testsuite/ld-aarch64/protected-data.d
index df106dc951..5dabf04748 100644
--- a/ld/testsuite/ld-aarch64/protected-data.d
+++ b/ld/testsuite/ld-aarch64/protected-data.d
@@ -1,3 +1,4 @@
+#target: [check_shared_lib_support]
 #ld: -shared
 #readelf: -r -W
 #...
diff --git a/ld/testsuite/ld-aarch64/rela-abs-relative-be.d b/ld/testsuite/ld-aarch64/rela-abs-relative-be.d
index 88ba58df17..333122a0bc 100644
--- a/ld/testsuite/ld-aarch64/rela-abs-relative-be.d
+++ b/ld/testsuite/ld-aarch64/rela-abs-relative-be.d
@@ -1,7 +1,7 @@
 #name: rela-abs-relative (big endian)
 #source: rela-abs-relative.s
+#alltargets: [check_shared_lib_support] aarch64_be-*-*
 #ld: -shared -Ttext-segment=0x100000 -Tdata=0x200000 -Trelocs.ld
-#target: aarch64_be-*-*
 #objdump: -dR -j .data
 #...
 
diff --git a/ld/testsuite/ld-aarch64/rela-abs-relative-opt.d b/ld/testsuite/ld-aarch64/rela-abs-relative-opt.d
index a1e5ca0fc1..7d76758cee 100644
--- a/ld/testsuite/ld-aarch64/rela-abs-relative-opt.d
+++ b/ld/testsuite/ld-aarch64/rela-abs-relative-opt.d
@@ -1,5 +1,6 @@
 #name: rela-abs-relative --no-apply-dynamic-relocs
 #source: rela-abs-relative.s
+#target: [check_shared_lib_support]
 #ld: -shared -Ttext-segment=0x100000 -Tdata=0x200000 -Trelocs.ld --no-apply-dynamic-relocs
 #notarget: aarch64_be-*-*
 #objdump: -dR -j .data
diff --git a/ld/testsuite/ld-aarch64/rela-abs-relative.d b/ld/testsuite/ld-aarch64/rela-abs-relative.d
index aba876b7b4..0d43bfc740 100644
--- a/ld/testsuite/ld-aarch64/rela-abs-relative.d
+++ b/ld/testsuite/ld-aarch64/rela-abs-relative.d
@@ -1,5 +1,6 @@
 #name: rela-abs-relative
 #source: rela-abs-relative.s
+#target: [check_shared_lib_support]
 #ld: -shared -Ttext-segment=0x100000 -Tdata=0x200000 -Trelocs.ld
 #notarget: aarch64_be-*-*
 #objdump: -dR -j .data
diff --git a/ld/testsuite/ld-aarch64/relasz.d b/ld/testsuite/ld-aarch64/relasz.d
index 28fe83a4d5..47f5de476f 100644
--- a/ld/testsuite/ld-aarch64/relasz.d
+++ b/ld/testsuite/ld-aarch64/relasz.d
@@ -1,4 +1,5 @@
 #source: relasz.s
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv -Taarch64.ld
 #readelf: -d
 # Check that the RELASZ section has the correct size even if we are
diff --git a/ld/testsuite/ld-aarch64/relocs-1027-symbolic-func.d b/ld/testsuite/ld-aarch64/relocs-1027-symbolic-func.d
index 19b81f313b..c3dd57c886 100644
--- a/ld/testsuite/ld-aarch64/relocs-1027-symbolic-func.d
+++ b/ld/testsuite/ld-aarch64/relocs-1027-symbolic-func.d
@@ -1,4 +1,5 @@
 #source: relocs-1027-symbolic-func.s
+#target: [check_shared_lib_support]
 #ld: -shared -Bsymbolic-functions
 #readelf: -r --wide
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-desc-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-desc-ie-ilp32.d
index 40680a69d3..2cf42dc634 100644
--- a/ld/testsuite/ld-aarch64/tls-desc-ie-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-desc-ie-ilp32.d
@@ -1,4 +1,5 @@
 #source: tls-desc-ie.s
+#target: [check_shared_lib_support]
 #as: -mabi=ilp32
 #ld: -shared -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/tls-desc-ie.d b/ld/testsuite/ld-aarch64/tls-desc-ie.d
index 1b1b9279e4..be6eb1c302 100644
--- a/ld/testsuite/ld-aarch64/tls-desc-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-desc-ie.d
@@ -1,4 +1,5 @@
 #source: tls-desc-ie.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-large-desc-be.d b/ld/testsuite/ld-aarch64/tls-large-desc-be.d
index 217794ce94..433b2b0d80 100644
--- a/ld/testsuite/ld-aarch64/tls-large-desc-be.d
+++ b/ld/testsuite/ld-aarch64/tls-large-desc-be.d
@@ -1,4 +1,5 @@
 #source: tls-large-desc.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/tls-large-desc.d b/ld/testsuite/ld-aarch64/tls-large-desc.d
index 9fa6dccfa4..f63cb9b16d 100644
--- a/ld/testsuite/ld-aarch64/tls-large-desc.d
+++ b/ld/testsuite/ld-aarch64/tls-large-desc.d
@@ -1,4 +1,5 @@
 #source: tls-large-desc.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64_be-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/tls-large-ie-be.d b/ld/testsuite/ld-aarch64/tls-large-ie-be.d
index 64a4384f41..5ef724be0c 100644
--- a/ld/testsuite/ld-aarch64/tls-large-ie-be.d
+++ b/ld/testsuite/ld-aarch64/tls-large-ie-be.d
@@ -1,4 +1,5 @@
 #source: tls-large-ie.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/tls-large-ie.d b/ld/testsuite/ld-aarch64/tls-large-ie.d
index 98606d6f96..55bb7a4abf 100644
--- a/ld/testsuite/ld-aarch64/tls-large-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-large-ie.d
@@ -1,4 +1,5 @@
 #source: tls-large-ie.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #notarget: aarch64_be-*-*
 #objdump: -dr
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
index f1565e9c11..8b6dceff81 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
@@ -1,4 +1,5 @@
 #source: tls-relax-gdesc-le.s
+#target: [check_shared_lib_support]
 #ld: -shared -z now
 #readelf: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-small-ld.d b/ld/testsuite/ld-aarch64/tls-small-ld.d
index dce10afabc..e39f8881a7 100644
--- a/ld/testsuite/ld-aarch64/tls-small-ld.d
+++ b/ld/testsuite/ld-aarch64/tls-small-ld.d
@@ -1,4 +1,5 @@
 #source: tls-small-ld.s
+#target: [check_shared_lib_support]
 #ld: -T relocs.ld -shared --hash-style=sysv
 #readelf: -Wr
 
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc.d b/ld/testsuite/ld-aarch64/tls-tiny-desc.d
index c17c448dda..6eb81ea315 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-desc.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-desc.d
@@ -1,4 +1,5 @@
 #source: tls-tiny-desc.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd.d b/ld/testsuite/ld-aarch64/tls-tiny-gd.d
index 9133492416..36d087916c 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-gd.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-gd.d
@@ -1,4 +1,5 @@
 #source: tls-tiny-gd.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-ie.d b/ld/testsuite/ld-aarch64/tls-tiny-ie.d
index 849e73ddf0..5f1e6da9ff 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-ie.d
@@ -1,4 +1,5 @@
 #source: tls-tiny-ie.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-ld.d b/ld/testsuite/ld-aarch64/tls-tiny-ld.d
index a9eb0a53fb..0a31ed9030 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-ld.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-ld.d
@@ -1,4 +1,5 @@
 #source: tls-tiny-ld.s
+#target: [check_shared_lib_support]
 #ld: -T relocs.ld -shared --hash-style=sysv
 #readelf: -Wr
 
diff --git a/ld/testsuite/ld-aarch64/tlsle-symbol-offset.d b/ld/testsuite/ld-aarch64/tlsle-symbol-offset.d
index cf61691300..f1c6abf911 100644
--- a/ld/testsuite/ld-aarch64/tlsle-symbol-offset.d
+++ b/ld/testsuite/ld-aarch64/tlsle-symbol-offset.d
@@ -1,4 +1,5 @@
 #source: tlsle-symbol-offset.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tlsle.d b/ld/testsuite/ld-aarch64/tlsle.d
index c74f662224..2340c9b6fb 100644
--- a/ld/testsuite/ld-aarch64/tlsle.d
+++ b/ld/testsuite/ld-aarch64/tlsle.d
@@ -1,4 +1,5 @@
 #source: tlsle.s
+#target: [check_shared_lib_support]
 #ld: -shared -T relocs.ld -e0
 #objdump: -dr
 
diff --git a/ld/testsuite/ld-aarch64/variant_pcs-now.d b/ld/testsuite/ld-aarch64/variant_pcs-now.d
index c3f48fe847..7ee9d8e16d 100644
--- a/ld/testsuite/ld-aarch64/variant_pcs-now.d
+++ b/ld/testsuite/ld-aarch64/variant_pcs-now.d
@@ -1,5 +1,6 @@
 #source: variant_pcs-1.s
 #source: variant_pcs-2.s
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv -T variant_pcs.ld -z now
 #readelf: -rsW
 
diff --git a/ld/testsuite/ld-aarch64/variant_pcs-shared.d b/ld/testsuite/ld-aarch64/variant_pcs-shared.d
index bdcc2c867f..15e548a70e 100644
--- a/ld/testsuite/ld-aarch64/variant_pcs-shared.d
+++ b/ld/testsuite/ld-aarch64/variant_pcs-shared.d
@@ -1,5 +1,6 @@
 #source: variant_pcs-1.s
 #source: variant_pcs-2.s
+#target: [check_shared_lib_support]
 #ld: -shared --hash-style=sysv -T variant_pcs.ld
 #readelf: -rsW
 
diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
index 118aa642d1..b4ff0442ff 100644
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -72,10 +72,12 @@ if { ![is_elf_format] || ![istarget "arm*-*-*"] } {
 # nm: Apply nm options on result.  Compare with regex (last arg).
 # readelf: Apply readelf options on result.  Compare with regex (last arg).
 
-set armelftests_common_1 {
+set armelftests_common {
     {"Group relocations" "-Ttext 0x8000 -Tdata 0x3000000 --section-start alpha=0xeef0 --section-start beta=0xffeef0" "" "" {group-relocs.s}
      {{objdump -dr group-relocs.d}}
      "group-relocs"}
+}
+set tmp {
     {"Indirect cross-library function reference (set-up)"
      "-shared" "" "" {arm-lib-plt-2a.s}
      {}
@@ -84,6 +86,9 @@ set armelftests_common_1 {
      "-shared tmpdir/arm-lib-plt-2a.so" "" "" {arm-lib-plt-2b.s}
      {{objdump -dr arm-lib-plt-2.dd} {readelf --relocs arm-lib-plt-2.rd}}
      "arm-lib-plt-2b.so"}
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
     {"Simple static application" "" "" "" {arm-static-app.s}
      {{objdump -fdw arm-static-app.d} {objdump -rw arm-static-app.r}}
      "arm-static-app"}
@@ -105,12 +110,21 @@ set armelftests_common_1 {
     {"arm-rel31" "-static -T arm.ld" "" "" {arm-rel31.s}
      {{objdump -s arm-rel31.d}}
      "arm-rel31"}
+}
+append armelftests_common $tmp
+set tmp {
     {"arm-rel32" "-shared -T arm-dyn.ld --hash-style=sysv" "" "" {arm-rel32.s}
      {{objdump -Rsj.data arm-rel32.d}}
      "arm-rel32"}
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
     {"arm-call" "--no-fix-arm1176 -static -T arm.ld" "" "-meabi=4" {arm-call1.s arm-call2.s}
      {{objdump -d arm-call.d}}
      "arm-call"}
+}
+append armelftests_common $tmp
+set tmp {
     {"TLS shared library" "-shared -T arm-lib.ld --hash-style=sysv" ""
      "" {tls-lib.s}
      {{objdump -fdw tls-lib.d} {objdump -Rw tls-lib.r}}
@@ -123,38 +137,53 @@ set armelftests_common_1 {
      "-shared -T arm-dyn.ld --hash-style=sysv" "" "" {tls-gdesc-got.s}
      {{objdump "-fDR -j .got" tls-gdesc-got.d}}
      "tls-lib2-got.so"}
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
     {"TLS gnu GD to IE relaxation"
-     "-static -T arm-dyn.ld --hash-style=sysv" "" "" {tls-gdierelax.s}
+     "-static -T arm-dyn.ld" "" "" {tls-gdierelax.s}
      {{objdump -fdw tls-gdierelax.d}}
      "tls-app-rel-ie"}
+}
+append armelftests_common $tmp
+set tmp  {
     {"TLS gnu GD to IE shared relaxation"
      "--no-fix-arm1176 -shared -T arm-dyn.ld --hash-style=sysv" ""
      "" {tls-gdierelax2.s}
      {{objdump -fdw tls-gdierelax2.d}}
      "tls-app-rel-ie2"}
-    {"TLS gnu GD to LE relaxation" "-T arm-dyn.ld --hash-style=sysv" ""
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
+    {"TLS gnu GD to LE relaxation" "-T arm-dyn.ld" ""
      "" {tls-gdlerelax.s}
      {{objdump -fdw tls-gdlerelax.d}}
      "tls-app-rel-le"}
+}
+append armelftests_common $tmp
+set tmp {
     {"TLS mixed models shared lib"
      "-shared -T arm-dyn.ld --hash-style=sysv" "" "" {tls-mixed.s}
      {{objdump -Rw tls-mixed.r}}
      "tls-mixed.so"}
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
     {"TLS descseq relaxation"
-     "-T arm-dyn.ld --hash-style=sysv" "" "" {tls-descrelax.s}
+     "-T arm-dyn.ld" "" "" {tls-descrelax.s}
      {{objdump -fdw tls-descrelax.d}}
      "tls-descrelax"}
     {"TLS descseq relaxation v7"
-     "-T arm-dyn.ld --hash-style=sysv" "" "" {tls-descrelax-v7.s}
+     "-T arm-dyn.ld" "" "" {tls-descrelax-v7.s}
      {{objdump -fdw tls-descrelax-v7.d}}
      "tls-descrelax-v7"}
     {"TLS descseq relaxation BE8"
-     "-T arm-dyn.ld --hash-style=sysv -EB --be8" ""
+     "-T arm-dyn.ld -EB --be8" ""
      "-mbig-endian" {tls-descrelax-be8.s}
      {{objdump -fdw tls-descrelax-be8.d}}
      "tls-descrelax-be8"}
     {"TLS descseq relaxation BE32"
-     "-T arm-dyn.ld --hash-style=sysv -EB" ""
+     "-T arm-dyn.ld -EB" ""
      "-mbig-endian" {tls-descrelax-be32.s}
      {{objdump -fdw tls-descrelax-be32.d}}
      "tls-descrelax-be32"}
@@ -203,14 +232,16 @@ set armelftests_common_1 {
      {{objdump -sj.data gc-unwind.d}}
 	"gc-unwind"}
 }
+append armelftests_common $tmp
 
-set armelftests_common_2 { 
+set tmp {
     {"script-type" "-static -T script-type.ld" "" "" {script-type.s}
 	{{readelf -s script-type.sym}}
 	"script-type"}
 }
+if ![istarget "arm*-*-netbsdelf"] { append armelftests_common $tmp }
 
-set armelftests_common_3 {
+set tmp {
     {"callweak" "-static -T arm.ld" "" "" {callweak.s}
      {{objdump -dr callweak.d}}
      "callweak"}
@@ -220,6 +251,9 @@ set armelftests_common_3 {
     {"Data only mapping symbols" "-T data-only-map.ld -Map map" "" "" {data-only-map.s}
      {{objdump -dr data-only-map.d}}
      "data-only-map"}
+}
+append armelftests_common $tmp
+set tmp {
     {"Data only mapping symbols for merged sections" "-T rodata-merge-map.ld" "" "" {rodata-merge-map1.s rodata-merge-map2.s rodata-merge-map3.s}
      {{readelf -s rodata-merge-map.sym}}
      "rodata-merge-map"}
@@ -234,25 +268,40 @@ set armelftests_common_3 {
     {"Simple non-PIC shared library (no PLT check)" "-shared" "" "" {arm-lib.s}
      {{objdump -Rw arm-lib.r}}
      "arm-lib.so"}
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
     {"EABI soft-float ET_EXEC ABI flag" "-T arm.ld" "" "-mfloat-abi=soft -meabi=5" {eabi-soft-float.s}
      {{readelf -h eabi-soft-float.d}}
      "eabi-soft-float"}
     {"EABI hard-float ET_EXEC ABI flag" "-T arm.ld" "" "-mfloat-abi=hard -meabi=5" {eabi-hard-float.s}
      {{readelf -h eabi-hard-float.d}}
      "eabi-hard-float"}
+}
+append armelftests_common $tmp
+set tmp {
     {"EABI hard-float ET_DYN ABI flag" "-shared" "" "-mfloat-abi=hard -meabi=5" {eabi-hard-float.s}
      {{readelf -h eabi-hard-float.d}}
      "eabi-hard-float.so"}
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
     {"EABI ABI flags wrong ABI version" "-T arm.ld" "" "-mfloat-abi=soft -meabi=4" {eabi-soft-float.s}
      {{readelf -h eabi-soft-float-ABI4.d}}
      "eabi-soft-float-no-flags"}
     {"EABI ABI flags ld -r" "-r" "" "-mfloat-abi=soft -meabi=5" {eabi-soft-float.s}
      {{readelf -h eabi-soft-float-r.d}}
      "eabi-soft-float-r.o"}
+}
+append armelftests_common $tmp
+set tmp {
     {"PC-relative in -shared" "-shared --hash-style=sysv" ""
      "" {pcrel-shared.s}
      {{readelf -dr pcrel-shared.rd}}
      "pcrel-shared.so"}
+}
+if [check_shared_lib_support] { append armelftests_common $tmp }
+set tmp {
     {"MOVS thumb1 relocations" "-static -T arm.ld" "" "" {thumb1-movs.s}
      {{objdump -dw thumb1-movs.d}}
      "thumb1-movs"}
@@ -270,13 +319,9 @@ set armelftests_common_3 {
       {{objdump -dw branch-futures.d}}
      "branch-futures"}
 }
+append armelftests_common $tmp
 
-run_ld_link_tests $armelftests_common_1
-if { ![istarget "arm*-*-netbsdelf"] } {
-    run_ld_link_tests $armelftests_common_2
-}
-run_ld_link_tests $armelftests_common_3
-
+run_ld_link_tests $armelftests_common
 
 set armelftests_nonacl {
     {"Thumb-1 BL" "-Ttext 0x1000 --section-start .foo=0x401000" "" "" {thumb1-bl.s}
@@ -291,6 +336,8 @@ set armelftests_nonacl {
     {"jump19" "-static -T arm.ld" "" "" {jump19.s}
      {{objdump -dr jump19.d}}
      "jump19"}
+}
+set tmp {
     {"Thumb and -gc-sections"
      "-shared -T arm-dyn.ld --hash-style=sysv" "" "" {gc-thumb-lib.s}
      {}
@@ -298,7 +345,6 @@ set armelftests_nonacl {
     {"Thumb and -gc-sections" "-pie -T arm.ld -gc-sections tmpdir/gc-thumb-lib.so" "" "" {gc-thumb.s}
      {{readelf --relocs gc-thumb.d}}
      "gc-thumb"}
-
     {"Simple non-PIC shared library" "-shared" "" "" {arm-lib.s}
      {{objdump -fdw arm-lib.d} {objdump -Rw arm-lib.r}}
      "arm-lib.so"}
@@ -308,10 +354,16 @@ set armelftests_nonacl {
     {"Simple dynamic application" "tmpdir/arm-lib.so" "" "" {arm-app.s}
      {{objdump -fdw arm-app.d} {objdump -Rw arm-app.r}}
      "arm-app"}
+}
+if [check_shared_lib_support] { append armelftests_nonacl $tmp }
+set tmp {
     {"Simple static application without .rel.plt in linker script"
 	"-T arm-no-rel-plt.ld" "" "" {arm-static-app.s}
      {{objdump -fdw arm-static-app.d} {objdump -rw arm-static-app.r}}
      "arm-static-app-no-rel-plt"}
+}
+append armelftests_nonacl $tmp
+set tmp {
     {"Simple dynamic application without .rel.plt in linker script"
 	"tmpdir/arm-lib.so -T arm-no-rel-plt.ld" "" "" {arm-app.s}
      {{readelf -dr arm-no-rel-plt.r}}
@@ -358,6 +410,7 @@ set armelftests_nonacl {
      {{objdump -fdw tls-lib-loc.d} {objdump -Rw tls-lib-loc.r}}
      "tls-lib-loc.so"}
 }
+if [check_shared_lib_support] { append armelftests_nonacl $tmp }
 
 if { ![istarget "arm*-*-nacl*"] } {
     run_ld_link_tests $armelftests_nonacl
diff --git a/ld/testsuite/ld-arm/gc-hidden-1.d b/ld/testsuite/ld-arm/gc-hidden-1.d
index f8cfabbbfb..9e20d431cb 100644
--- a/ld/testsuite/ld-arm/gc-hidden-1.d
+++ b/ld/testsuite/ld-arm/gc-hidden-1.d
@@ -1,6 +1,7 @@
 #source: main.s
 #source: gcdfn.s
 #source: hidfn.s
+#target: [check_shared_lib_support]
 #ld: --gc-sections --shared --version-script hideall.ld
 #objdump: -dRT
 # This test is only valid on ELF based ports.
diff --git a/ld/testsuite/ld-arm/movw-shared-1.d b/ld/testsuite/ld-arm/movw-shared-1.d
index 5a058185b5..f67b372097 100644
--- a/ld/testsuite/ld-arm/movw-shared-1.d
+++ b/ld/testsuite/ld-arm/movw-shared-1.d
@@ -1,4 +1,5 @@
 #name: MOVW/MOVT shared libraries test 1
 #source: movw-shared-1.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #error: .*: relocation R_ARM_MOVW_ABS_NC against `a' can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-arm/movw-shared-2.d b/ld/testsuite/ld-arm/movw-shared-2.d
index 08ceaf07bd..76f5d5c59f 100644
--- a/ld/testsuite/ld-arm/movw-shared-2.d
+++ b/ld/testsuite/ld-arm/movw-shared-2.d
@@ -1,4 +1,5 @@
 #name: MOVW/MOVT shared libraries test 2
 #source: movw-shared-2.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #error: .*: relocation R_ARM_MOVT_ABS against `b' can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-arm/movw-shared-3.d b/ld/testsuite/ld-arm/movw-shared-3.d
index 90b9cf148e..7dafda30dc 100644
--- a/ld/testsuite/ld-arm/movw-shared-3.d
+++ b/ld/testsuite/ld-arm/movw-shared-3.d
@@ -1,4 +1,5 @@
 #name: MOVW/MOVT shared libraries test 3
 #source: movw-shared-3.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #error: .*: relocation R_ARM_THM_MOVW_ABS_NC against `c' can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-arm/movw-shared-4.d b/ld/testsuite/ld-arm/movw-shared-4.d
index cc7a418b52..fbfd92c1c5 100644
--- a/ld/testsuite/ld-arm/movw-shared-4.d
+++ b/ld/testsuite/ld-arm/movw-shared-4.d
@@ -1,4 +1,5 @@
 #name: MOVW/MOVT shared libraries test 4
 #source: movw-shared-4.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #error: .*: relocation R_ARM_THM_MOVT_ABS against `d' can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-arm/pie-bind-locally.d b/ld/testsuite/ld-arm/pie-bind-locally.d
index 7ea031c79b..d90085b9b9 100644
--- a/ld/testsuite/ld-arm/pie-bind-locally.d
+++ b/ld/testsuite/ld-arm/pie-bind-locally.d
@@ -1,5 +1,6 @@
 #source: pie-bind-locally-a.s
 #source: pie-bind-locally-b.s
+#target: [check_shared_lib_support]
 #ld: -pie
 #readelf: -Wr
 
diff --git a/ld/testsuite/ld-arm/protected-data.d b/ld/testsuite/ld-arm/protected-data.d
index 51c51c6b95..3f266dea1b 100644
--- a/ld/testsuite/ld-arm/protected-data.d
+++ b/ld/testsuite/ld-arm/protected-data.d
@@ -1,3 +1,4 @@
+#target: [check_shared_lib_support]
 #ld: -shared
 #readelf: -r -W
 #...
diff --git a/ld/testsuite/ld-arm/rel32-reject-pie.d b/ld/testsuite/ld-arm/rel32-reject-pie.d
index 475b3242c9..8e1962ba4a 100644
--- a/ld/testsuite/ld-arm/rel32-reject-pie.d
+++ b/ld/testsuite/ld-arm/rel32-reject-pie.d
@@ -1,3 +1,4 @@
 #source: rel32-reject-pie.s
+#target: [check_shared_lib_support]
 #ld: -pie
 #error: .*relocation R_ARM_REL32.*can not.*PIE executable.*
diff --git a/ld/testsuite/ld-arm/rel32-reject.d b/ld/testsuite/ld-arm/rel32-reject.d
index c82fd4df6a..b7bd469adf 100644
--- a/ld/testsuite/ld-arm/rel32-reject.d
+++ b/ld/testsuite/ld-arm/rel32-reject.d
@@ -1,3 +1,4 @@
 #source: rel32-reject.s
+#target: [check_shared_lib_support]
 #ld: -shared
 #error: .*relocation R_ARM_REL32.*can not.*shared object.*
diff --git a/ld/testsuite/ld-arm/thumb2-bl-undefweak.d b/ld/testsuite/ld-arm/thumb2-bl-undefweak.d
index c501aa2c1f..af92bbd59e 100644
--- a/ld/testsuite/ld-arm/thumb2-bl-undefweak.d
+++ b/ld/testsuite/ld-arm/thumb2-bl-undefweak.d
@@ -1,5 +1,6 @@
 #source: thumb2-bl-undefweak.s
 #as:
+#target: [check_shared_lib_support]
 #ld: -shared
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-arm/thumb2-bl-undefweak1.d b/ld/testsuite/ld-arm/thumb2-bl-undefweak1.d
index 806f66c651..87e0b8f89e 100644
--- a/ld/testsuite/ld-arm/thumb2-bl-undefweak1.d
+++ b/ld/testsuite/ld-arm/thumb2-bl-undefweak1.d
@@ -1,5 +1,6 @@
 #source: thumb2-bl-undefweak1.s
 #as:
+#target: [check_shared_lib_support]
 #ld: -shared
 #objdump: -dr
 #...

-- 
Alan Modra
Australia Development Lab, IBM
Nathan Chancellor Nov. 7, 2019, 7:37 a.m. | #5
On Tue, Nov 05, 2019 at 08:33:18PM +1030, Alan Modra wrote:
> On Tue, Nov 05, 2019@09:47:52AM +0100, Christophe Lyon wrote:

> > > So, this patch removes GENERATE_SHLIB_SCRIPT and GENERATE_PIE_SCRIPT

> > > in most emulparams files where EMBEDDED is set, restoring the shared

> > > lib and pie support in emulparams files that unset EMBEDDED after

> > > including a file where the support is removed.

> >

> > On my side, after your committed this patch, I've noticed many regressions on

> > aarch64*-elf and arm-none-eabi:

> > https://ci.linaro.org/job/tcwg-compare-results/9217/artifact/artifacts/logs/0-report.html

> > 

> > Aren't these targets part of the set you regularly test? Or don't they

> > regress for you?

> 

> Um, I see I only test aarch64-linux and aarch64_be-linux-gnu_ilp32 for

> aarch64 so the aarch64-elf changes weren't tested@all.  I test

> arm-linuxeabi, arm-nacl, arm-netbsdelf, arm-nto, arm-pe,

> arm-symbianelf, arm-vxworks, arm-wince-pe, and armeb-linuxeabi but

> that doesn't hit any of the arm-elf targets either.  :-(

> 

> Testsuite regressions aside, is the patch wrong for aarch64-elf and

> arm-elf targets?  That's the real question here.  Or should

> aarch64-elf and perhaps arm-elf *not* set EMBEDDED and instead

> provide the usual shared lib and PIE support?

> 

> -- 

> Alan Modra

> Australia Development Lab, IBM


For what it's worth, this breaks building the Linux kernel for me:

aarch64-linux-ld: -shared not supported
../arch/arm64/kernel/vdso/Makefile:60: recipe for target 'arch/arm64/kernel/vdso/vdso.so.dbg' failed
make[3]: *** [arch/arm64/kernel/vdso/vdso.so.dbg] Error 1
arch/arm64/Makefile:159: recipe for target 'vdso_prepare' failed
make[2]: *** [vdso_prepare] Error 2
/home/nathan/cbl/linux-next/Makefile:326: recipe for target '__build_one_by_one' failed
make[1]: *** [__build_one_by_one] Error 2
Makefile:179: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

Reverting the change to ld/emulparams/aarch64elf.sh fixes it (somewhat
obvious), which probably means that the patch is wrong for the *-elf
targets (unless *-linux* should be setting those flags themselves...).
Not really familiar with the structure of these files, just a general
observation from the couple minutes I spent glancing over them.

Cheers,
Nathan
Alan Modra Nov. 7, 2019, 7:43 a.m. | #6
On Thu, Nov 07, 2019 at 12:37:00AM -0700, Nathan Chancellor wrote:
> For what it's worth, this breaks building the Linux kernel for me:

> 

> aarch64-linux-ld: -shared not supported


An aarch64-linux ld will use emulparams/aarch64linux.sh, which does
have shared support.  If you're trying to use binutils configured for
aarch64-elf on Linux, well, good luck with that.

-- 
Alan Modra
Australia Development Lab, IBM
Nathan Chancellor Nov. 7, 2019, 5:25 p.m. | #7
On Thu, Nov 07, 2019 at 06:13:30PM +1030, Alan Modra wrote:
> On Thu, Nov 07, 2019 at 12:37:00AM -0700, Nathan Chancellor wrote:

> > For what it's worth, this breaks building the Linux kernel for me:

> > 

> > aarch64-linux-ld: -shared not supported

> 

> An aarch64-linux ld will use emulparams/aarch64linux.sh, which does

> have shared support.  If you're trying to use binutils configured for

> aarch64-elf on Linux, well, good luck with that.

> 

> -- 

> Alan Modra

> Australia Development Lab, IBM


As it turns out, this error is related to the arm64 Linux kernel using
the ELF emulation mode by default, falling back to the Linux one if it
is not supported. See the following commits:

https://git.kernel.org/linus/38fc4248677552ce35efc09902fdcb06b61d7ef9
https://git.kernel.org/linus/96f95a17c1cfe65a002e525114d96616e91a8f2d
https://git.kernel.org/linus/c931d34ea0853d41349e93f871bd3f17f1c03a6b

I can probably send the below diff to fix this, not sure if that is how
you would recommend proceeding or if the change to the elf targets in ld
should be reverted.

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 2c0238ce0551..5594043e0f05 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -76,16 +76,13 @@ ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
 KBUILD_CPPFLAGS        += -mbig-endian
 CHECKFLAGS     += -D__AARCH64EB__
 AS             += -EB
-# Prefer the baremetal ELF build target, but not all toolchains include
-# it so fall back to the standard linux version if needed.
-KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb)
+KBUILD_LDFLAGS += -EB -maarch64linuxb
 UTS_MACHINE    := aarch64_be
 else
 KBUILD_CPPFLAGS        += -mlittle-endian
 CHECKFLAGS     += -D__AARCH64EL__
 AS             += -EL
-# Same as above, prefer ELF but fall back to linux target if needed.
-KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux)
+KBUILD_LDFLAGS += -EL -maarch64linux
 UTS_MACHINE    := aarch64
 endif
Alan Modra Nov. 7, 2019, 11:48 p.m. | #8
On Thu, Nov 07, 2019 at 10:25:14AM -0700, Nathan Chancellor wrote:
> On Thu, Nov 07, 2019 at 06:13:30PM +1030, Alan Modra wrote:

> > On Thu, Nov 07, 2019 at 12:37:00AM -0700, Nathan Chancellor wrote:

> > > For what it's worth, this breaks building the Linux kernel for me:

> > > 

> > > aarch64-linux-ld: -shared not supported

> > 

> > An aarch64-linux ld will use emulparams/aarch64linux.sh, which does

> > have shared support.  If you're trying to use binutils configured for

> > aarch64-elf on Linux, well, good luck with that.

> 

> As it turns out, this error is related to the arm64 Linux kernel using

> the ELF emulation mode by default, falling back to the Linux one if it

> is not supported. See the following commits:

> 

> https://git.kernel.org/linus/38fc4248677552ce35efc09902fdcb06b61d7ef9

> https://git.kernel.org/linus/96f95a17c1cfe65a002e525114d96616e91a8f2d

> https://git.kernel.org/linus/c931d34ea0853d41349e93f871bd3f17f1c03a6b


Ah, now your report is starting to make more sense.  The Linux kernel
makes use of -shared to build the kernel vdso and when building a
relocatable kernel.  In both cases the ELF file header and program
headers are not needed to load those images.

However, in any other shared library the headers must be present for
the binary to be loaded by ld.so.  That's what I meant with my comment
"good luck with that".  So attempting to build an aarch64-linux shared
library using -maarch64elf or -maarch64elfb generally will result in a
non-functional binary.  I think the linker should at least warn about
that.

I wonder if the following would work for the aarch64 kernel build?
You might also need -Ttext-segment=0 along with -shared in the kernel
Makefiles since otherwise you'd get a vsdo and relocatable kernel
linked at something other than a zero base address.

diff --git a/ld/lexsup.c b/ld/lexsup.c
index d7766c3c55..f28245b0ca 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1187,33 +1187,25 @@ parse_args (unsigned argc, char **argv)
 	  link_info.prohibit_multiple_definition_absolute = TRUE;
 	  break;
 	case OPTION_SHARED:
-	  if (config.has_shared)
-	    {
-	      if (bfd_link_relocatable (&link_info))
-		einfo (_("%F%P: -r and %s may not be used together\n"),
-		       "-shared");
-
-	      link_info.type = type_dll;
-	      /* When creating a shared library, the default
-		 behaviour is to ignore any unresolved references.  */
-	      if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
-		link_info.unresolved_syms_in_objects = RM_IGNORE;
-	      if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
-		link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
-	    }
-	  else
-	    einfo (_("%F%P: -shared not supported\n"));
+	  if (!config.has_shared)
+	    einfo (_("%P: warning: -shared not supported\n"));
+	  if (bfd_link_relocatable (&link_info))
+	    einfo (_("%F%P: -r and %s may not be used together\n"),
+		   "-shared");
+	  link_info.type = type_dll;
+	  /* When creating a shared library, the default
+	     behaviour is to ignore any unresolved references.  */
+	  if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
+	    link_info.unresolved_syms_in_objects = RM_IGNORE;
+	  if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
+	    link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
 	  break;
 	case OPTION_PIE:
-	  if (config.has_shared)
-	    {
-	      if (bfd_link_relocatable (&link_info))
-		einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
-
-	      link_info.type = type_pie;
-	    }
-	  else
-	    einfo (_("%F%P: -pie not supported\n"));
+	  if (!config.has_shared)
+	    einfo (_("%P: warning: -pie not supported\n"));
+	  if (bfd_link_relocatable (&link_info))
+	    einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
+	  link_info.type = type_pie;
 	  break;
 	case 'h':		/* Used on Solaris.  */
 	case OPTION_SONAME:

-- 
Alan Modra
Australia Development Lab, IBM
Nathan Chancellor Nov. 8, 2019, 5:18 a.m. | #9
CC'ing the arm64 Linux kernel maintainers + Ard and mailing list since I
am sure their input is more valuable than mine :) hopefully you all
don't mind, small discription of the issue below to key you in.

On Fri, Nov 08, 2019 at 10:18:43AM +1030, Alan Modra wrote:
> On Thu, Nov 07, 2019 at 10:25:14AM -0700, Nathan Chancellor wrote:

> > On Thu, Nov 07, 2019 at 06:13:30PM +1030, Alan Modra wrote:

> > > On Thu, Nov 07, 2019 at 12:37:00AM -0700, Nathan Chancellor wrote:

> > > > For what it's worth, this breaks building the Linux kernel for me:

> > > > 

> > > > aarch64-linux-ld: -shared not supported


This error occurs when building an arm64 defconfig kernel with master
binutils due to this commit in binutils interacting with the ELF
emulation added in the kernel commits linked below.

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=f2aaebdb97977ee7a5c83c02af871e758e7d594b

> > > An aarch64-linux ld will use emulparams/aarch64linux.sh, which does

> > > have shared support.  If you're trying to use binutils configured for

> > > aarch64-elf on Linux, well, good luck with that.

> > 

> > As it turns out, this error is related to the arm64 Linux kernel using

> > the ELF emulation mode by default, falling back to the Linux one if it

> > is not supported. See the following commits:

> > 

> > https://git.kernel.org/linus/38fc4248677552ce35efc09902fdcb06b61d7ef9

> > https://git.kernel.org/linus/96f95a17c1cfe65a002e525114d96616e91a8f2d

> > https://git.kernel.org/linus/c931d34ea0853d41349e93f871bd3f17f1c03a6b

> 

> Ah, now your report is starting to make more sense.  The Linux kernel

> makes use of -shared to build the kernel vdso and when building a

> relocatable kernel.  In both cases the ELF file header and program

> headers are not needed to load those images.

> 

> However, in any other shared library the headers must be present for

> the binary to be loaded by ld.so.  That's what I meant with my comment

> "good luck with that".  So attempting to build an aarch64-linux shared

> library using -maarch64elf or -maarch64elfb generally will result in a

> non-functional binary.  I think the linker should at least warn about

> that.


I suppose it has been working fine for the past year; otherwise someone
would have noticed something, right? How would the binary be
non-functional?

> I wonder if the following would work for the aarch64 kernel build?

> You might also need -Ttext-segment=0 along with -shared in the kernel

> Makefiles since otherwise you'd get a vsdo and relocatable kernel

> linked at something other than a zero base address.


<snip patch>

I applied that patch on top of binutils commit
f2aaebdb97 ("GENERATE_SHLIB_SCRIPT vs. EMBEDDED.") and it fixed that
error but revealed another one. I am using Segher Boessenkool's build
script available here, in case it is a configuration issue:

http://git.infradead.org/users/segher/buildall.git/blob/refs/heads/master:/build-binutils

aarch64-linux-ld: warning: -shared not supported
aarch64-linux-ld: unrecognized option '--hash-style=sysv'
aarch64-linux-ld: use the --help option for usage information
../arch/arm64/kernel/vdso/Makefile:60: recipe for target 'arch/arm64/kernel/vdso/vdso.so.dbg' failed
make[3]: *** [arch/arm64/kernel/vdso/vdso.so.dbg] Error 1
arch/arm64/Makefile:159: recipe for target 'vdso_prepare' failed
make[2]: *** [vdso_prepare] Error 2
/home/nathan/src/linux/Makefile:326: recipe for target '__build_one_by_one' failed
make[1]: *** [__build_one_by_one] Error 2
Makefile:179: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

Happy to continue to test other solutions.

Cheers,
Nathan
Alan Modra Nov. 8, 2019, 10:34 a.m. | #10
I'm reverting the patch.  My reasons for making it in the first place
were bogus.  The ELF file header and program headers are of course
still present in a file created by targets that set EMBEDDED, and the
fact that EMBEDDED stops them being included in the memory image only
affects some uses of those headers.  I still don't recommend creating
shared libraries for Linux using -maarch64elf but the resulting shared
library isn't as silly as what I thought.

-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/ld/emulparams/aarch64elf.sh b/ld/emulparams/aarch64elf.sh
index 8f68e517b4..5c70b55686 100644
--- a/ld/emulparams/aarch64elf.sh
+++ b/ld/emulparams/aarch64elf.sh
@@ -12,9 +12,6 @@  NO_REL_RELOCS=yes
 TEMPLATE_NAME=elf
 EXTRA_EM_FILE=aarch64elf
 
-GENERATE_SHLIB_SCRIPT=yes
-GENERATE_PIE_SCRIPT=yes
-
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 
 ENTRY=_start
diff --git a/ld/emulparams/aarch64elf32.sh b/ld/emulparams/aarch64elf32.sh
index 5a08d9e29f..a94025a139 100644
--- a/ld/emulparams/aarch64elf32.sh
+++ b/ld/emulparams/aarch64elf32.sh
@@ -12,9 +12,6 @@  NO_REL_RELOCS=yes
 TEMPLATE_NAME=elf
 EXTRA_EM_FILE=aarch64elf
 
-GENERATE_SHLIB_SCRIPT=yes
-GENERATE_PIE_SCRIPT=yes
-
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 
 ENTRY=_start
diff --git a/ld/emulparams/arcelf.sh b/ld/emulparams/arcelf.sh
index 625ec39779..b6d8f9fdf7 100644
--- a/ld/emulparams/arcelf.sh
+++ b/ld/emulparams/arcelf.sh
@@ -19,5 +19,3 @@  SDATA_START_SYMBOLS='__SDATA_BEGIN__ = . + 0x100;'
 JLI_START_TABLE='__JLI_TABLE__ = .;'
 OTHER_SECTIONS="/DISCARD/ : { *(.__arc_profile_*) }"
 EMBEDDED=yes
-
-GENERATE_SHLIB_SCRIPT=yes
diff --git a/ld/emulparams/armelf.sh b/ld/emulparams/armelf.sh
index 0e3147c1f2..8977fd6fea 100644
--- a/ld/emulparams/armelf.sh
+++ b/ld/emulparams/armelf.sh
@@ -32,9 +32,6 @@  OTHER_READONLY_SECTIONS="
 
 DATA_START_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__data_start = .${CREATE_SHLIB+)};"
 
-GENERATE_SHLIB_SCRIPT=yes
-GENERATE_PIE_SCRIPT=yes
-
 ARCH=arm
 MACHINE=
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
diff --git a/ld/emulparams/armelf_fbsd.sh b/ld/emulparams/armelf_fbsd.sh
index be88c2f2e0..4428b91a34 100644
--- a/ld/emulparams/armelf_fbsd.sh
+++ b/ld/emulparams/armelf_fbsd.sh
@@ -5,7 +5,7 @@  TEXT_START_ADDR=0x00010000
 
 TARGET2_TYPE=got-rel
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
+GENERATE_SHLIB_SCRIPT=yes
 GENERATE_PIE_SCRIPT=yes
-
 unset STACK_ADDR
 unset EMBEDDED
diff --git a/ld/emulparams/armelf_nbsd.sh b/ld/emulparams/armelf_nbsd.sh
index 37e1a4afdd..45954597ee 100644
--- a/ld/emulparams/armelf_nbsd.sh
+++ b/ld/emulparams/armelf_nbsd.sh
@@ -3,5 +3,7 @@  MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 TEXT_START_ADDR=0x00008000
 TARGET2_TYPE=got-rel
 
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 unset STACK_ADDR
 unset EMBEDDED
diff --git a/ld/emulparams/armelf_vxworks.sh b/ld/emulparams/armelf_vxworks.sh
index 5f57535fee..e344209905 100644
--- a/ld/emulparams/armelf_vxworks.sh
+++ b/ld/emulparams/armelf_vxworks.sh
@@ -4,3 +4,4 @@  BIG_OUTPUT_FORMAT="elf32-bigarm-vxworks"
 LITTLE_OUTPUT_FORMAT="$OUTPUT_FORMAT"
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 source_sh ${srcdir}/emulparams/vxworks.sh
+GENERATE_SHLIB_SCRIPT=yes
diff --git a/ld/emulparams/armsymbian.sh b/ld/emulparams/armsymbian.sh
index 1959685f9b..183750a564 100644
--- a/ld/emulparams/armsymbian.sh
+++ b/ld/emulparams/armsymbian.sh
@@ -8,6 +8,8 @@  TARGET1_IS_REL=1
 TARGET2_TYPE=abs
 # On BPABI systems, program headers should not be mapped.
 EMBEDDED=yes
+# Nonetheless, shared libraries are also supported
+GENERATE_SHLIB_SCRIPT=yes
 
 # As for armelf.sh, but add the SymbianOS-specific
 # .ARM.exidx$${Base,Limit} symbols.
diff --git a/ld/emulparams/elf32bfin.sh b/ld/emulparams/elf32bfin.sh
index 8d298b467c..6e08035b6f 100644
--- a/ld/emulparams/elf32bfin.sh
+++ b/ld/emulparams/elf32bfin.sh
@@ -6,7 +6,6 @@  TARGET_PAGE_SIZE=0x1000
 ARCH=bfin
 MACHINE=
 TEMPLATE_NAME=elf
-GENERATE_SHLIB_SCRIPT=yes
 EMBEDDED=yes
 USER_LABEL_PREFIX=_
 EXTRA_EM_FILE=bfin
diff --git a/ld/emulparams/elf32microblaze.sh b/ld/emulparams/elf32microblaze.sh
index f867018eb3..698adb7cf8 100644
--- a/ld/emulparams/elf32microblaze.sh
+++ b/ld/emulparams/elf32microblaze.sh
@@ -21,6 +21,3 @@  NOP=0x80000000
 #OTHER_RELOCATING_SECTIONS='PROVIDE (_stack = _end + 0x1000);'
 
 TEMPLATE_NAME=elf
-#GENERATE_SHLIB_SCRIPT=yes
-
-
diff --git a/ld/emulparams/score3_elf.sh b/ld/emulparams/score3_elf.sh
index 7be7883363..78401876e5 100644
--- a/ld/emulparams/score3_elf.sh
+++ b/ld/emulparams/score3_elf.sh
@@ -26,4 +26,3 @@  ARCH=score3
 MACHINE=
 ENTRY=_start
 EMBEDDED=yes
-GENERATE_SHLIB_SCRIPT=yes
diff --git a/ld/emulparams/shelf.sh b/ld/emulparams/shelf.sh
index 63c2ff19dc..96c18c0750 100644
--- a/ld/emulparams/shelf.sh
+++ b/ld/emulparams/shelf.sh
@@ -9,7 +9,6 @@  MAXPAGESIZE=128
 ARCH=sh
 MACHINE=
 TEMPLATE_NAME=elf
-GENERATE_SHLIB_SCRIPT=yes
 EMBEDDED=yes
 # These are for compatibility with the COFF toolchain.
 ENTRY=start
diff --git a/ld/emulparams/shelf_nbsd.sh b/ld/emulparams/shelf_nbsd.sh
index 391399660d..57db803d00 100644
--- a/ld/emulparams/shelf_nbsd.sh
+++ b/ld/emulparams/shelf_nbsd.sh
@@ -11,5 +11,7 @@  DATA_START_SYMBOLS='PROVIDE (__data_start = .);';
 
 ENTRY=_start
 
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 unset EMBEDDED
 unset STACK_ADDR
diff --git a/ld/emulparams/shelf_uclinux.sh b/ld/emulparams/shelf_uclinux.sh
index a22c35a9a8..41044f028c 100644
--- a/ld/emulparams/shelf_uclinux.sh
+++ b/ld/emulparams/shelf_uclinux.sh
@@ -2,3 +2,4 @@  source_sh ${srcdir}/emulparams/shelf.sh
 
 # We do not want a .stack section
 unset STACK_ADDR
+GENERATE_SHLIB_SCRIPT=yes