ld: Compile some tests with -mdirect-extern-access

When GCC enables -mno-direct-extern-access by default, some tests fail
without -mdirect-extern-access.  Define DIRECT_EXTERN_ACCESS_CFLAGS
to compile these tests with -mdirect-extern-access.  Also pass
"-z noindirect-extern-access" to linker to support the C library
compiled with -mno-direct-extern-access.

	PR ld/33267
	* testsuite/config/default.exp (DIRECT_EXTERN_ACCESS_CFLAGS): New.
	* testsuite/ld-elf/linux-x86.exp: Compile some tests with
	$DIRECT_EXTERN_ACCESS_CFLAGS.
	* testsuite/ld-elfvers/vers.exp (need_direct_extern_access): New
	for i?86.
	Compile tests with $need_direct_extern_access.
	* testsuite/ld-i386/i386.exp: Compile some tests with
	$DIRECT_EXTERN_ACCESS_CFLAGS.
	* testsuite/ld-ifunc/ifunc.exp (need_direct_extern_access): New
	for i?86.
	Compile tests with $need_direct_extern_access.
	* testsuite/ld-shared/shared.exp (need_direct_extern_access): New
	for i?86.
	Compile tests with $need_direct_extern_access.
	* testsuite/ld-srec/srec.exp (CFLAGS_FOR_TARGET_TEST): Add
	$DIRECT_EXTERN_ACCESS_CFLAGS.
	(CXXFLAGS_FOR_TARGET_TEST): Likewise.
	* testsuite/ld-vsb/vsb.exp (need_direct_extern_access): New
	for i?86.
	Compile tests with $need_direct_extern_access.
	* testsuite/ld-x86-64/x86-64.exp: Compile some tests with
	$DIRECT_EXTERN_ACCESS_CFLAGS and link some tests with
	"-Wl,-z,noindirect-extern-access".

Co-Authored-By: Sam James <sam@gentoo.org>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Sam James <sam@gentoo.org>
9 files changed