summaryrefslogtreecommitdiff
path: root/ld/testsuite
diff options
context:
space:
mode:
authorClément Chigot <clement.chigot@atos.net>2021-11-18 16:12:14 +0100
committerClément Chigot <clement.chigot@atos.net>2021-12-06 12:45:12 +0100
commit74044dc84074abca775c63462ecccc10a7900987 (patch)
tree4186489405f647bba6d48a56ce85d74faf89b4ba /ld/testsuite
parent2427f3b09eb23e7949878cdc0b366fb605df568f (diff)
ld: improve shared tests for AIX
It's now possible to refer symbols in the main program from the shared library. However, it still impossible to have the same overriden features between shared objects and mains than ELF, without using the runtime linking feature which isn't yet fully available. ld/ChangeLog: * testsuite/ld-shared/shared.exp: Improve XCOFF support * testsuite/ld-shared/main.c: Likewise. * testsuite/ld-shared/sh1.c: Likewise. * testsuite/ld-shared/xcoff.dat: Likewise.
Diffstat (limited to 'ld/testsuite')
-rw-r--r--ld/testsuite/ld-shared/main.c10
-rw-r--r--ld/testsuite/ld-shared/sh1.c10
-rw-r--r--ld/testsuite/ld-shared/shared.exp71
-rw-r--r--ld/testsuite/ld-shared/xcoff.dat4
4 files changed, 37 insertions, 58 deletions
diff --git a/ld/testsuite/ld-shared/main.c b/ld/testsuite/ld-shared/main.c
index 0817d2730a..b5200f2a09 100644
--- a/ld/testsuite/ld-shared/main.c
+++ b/ld/testsuite/ld-shared/main.c
@@ -41,25 +41,27 @@ main ()
printf ("mainvar == %d\n", mainvar);
printf ("overriddenvar == %d\n", overriddenvar);
printf ("shlibvar1 == %d\n", shlibvar1);
-#ifndef XCOFF_TEST
+#ifndef SYMBOLIC_TEST
printf ("shlib_mainvar () == %d\n", shlib_mainvar ());
+#ifndef XCOFF_TEST
printf ("shlib_overriddenvar () == %d\n", shlib_overriddenvar ());
#endif
+#endif
printf ("shlib_shlibvar1 () == %d\n", shlib_shlibvar1 ());
printf ("shlib_shlibvar2 () == %d\n", shlib_shlibvar2 ());
printf ("shlib_shlibcall () == %d\n", shlib_shlibcall ());
+#ifndef SYMBOLIC_TEST
#ifndef XCOFF_TEST
printf ("shlib_shlibcall2 () == %d\n", shlib_shlibcall2 ());
+#endif
printf ("shlib_maincall () == %d\n", shlib_maincall ());
#endif
printf ("main_called () == %d\n", main_called ());
#ifndef SYMBOLIC_TEST
printf ("shlib_checkfunptr1 (shlib_shlibvar1) == %d\n",
shlib_checkfunptr1 (shlib_shlibvar1));
-#ifndef XCOFF_TEST
printf ("shlib_checkfunptr2 (main_called) == %d\n",
shlib_checkfunptr2 (main_called));
-#endif
{
int (*p) ();
@@ -71,7 +73,6 @@ main ()
printf ("!=");
printf (" shlib_shlibvar1\n");
}
-#ifndef XCOFF_TEST
{
int (*p) ();
@@ -84,7 +85,6 @@ main ()
printf (" main_called\n");
}
#endif
-#endif
printf ("shlib_check () == %d\n", shlib_check ());
return 0;
}
diff --git a/ld/testsuite/ld-shared/sh1.c b/ld/testsuite/ld-shared/sh1.c
index c8e523249a..9acb29e22d 100644
--- a/ld/testsuite/ld-shared/sh1.c
+++ b/ld/testsuite/ld-shared/sh1.c
@@ -2,9 +2,7 @@
of a shared library. */
/* This variable is supplied by the main program. */
-#ifndef XCOFF_TEST
extern int mainvar;
-#endif
/* This variable is defined in the shared library, and overridden by
the main program. */
@@ -21,13 +19,11 @@ extern int shlibvar2;
/* These functions return the values of the above variables as seen in
the shared library. */
-#ifndef XCOFF_TEST
int
shlib_mainvar ()
{
return mainvar;
}
-#endif
#ifndef XCOFF_TEST
int
@@ -75,7 +71,6 @@ shlib_shlibcall2 ()
/* This function calls a function defined by the main program. */
-#ifndef XCOFF_TEST
extern int main_called ();
int
@@ -83,7 +78,6 @@ shlib_maincall ()
{
return main_called ();
}
-#endif
/* This function is passed a function pointer to shlib_mainvar. It
confirms that the pointer compares equally. */
@@ -98,14 +92,12 @@ shlib_checkfunptr1 (p)
/* This function is passed a function pointer to main_called. It
confirms that the pointer compares equally. */
-#ifndef XCOFF_TEST
int
shlib_checkfunptr2 (p)
int (*p) ();
{
return p == main_called;
}
-#endif
/* This function returns a pointer to shlib_mainvar. */
@@ -117,13 +109,11 @@ int
/* This function returns a pointer to main_called. */
-#ifndef XCOFF_TEST
int
(*shlib_getfunptr2 ()) ()
{
return main_called;
}
-#endif
/* This function makes sure that constant data and local functions
work. */
diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
index 40f417eb69..12879fafed 100644
--- a/ld/testsuite/ld-shared/shared.exp
+++ b/ld/testsuite/ld-shared/shared.exp
@@ -53,8 +53,7 @@ if { ![istarget hppa*64*-*-hpux*] \
&& ![istarget sparc*-*-linux*] \
&& ![istarget arm*-*-linux*] \
&& ![istarget alpha*-*-linux*] \
- && ![istarget rs6000*-*-aix*] \
- && ![istarget powerpc*-*-aix*] \
+ && ![is_xcoff_format] \
&& ![istarget s390*-*-linux*] \
&& ![istarget aarch64*-*-linux*] \
&& ![istarget x86_64-*-linux*] } {
@@ -69,33 +68,22 @@ set shared_needs_pic "no"
set old_CFLAGS "$CFLAGS_FOR_TARGET"
append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
-if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
-
- # AIX shared libraries do not seem to support useful features,
- # like overriding the shared library function or letting the
- # shared library refer to objects defined in the main program. We
- # avoid testing those features.
+if { [is_xcoff_format] } {
+ # Not all the useful features are available with AIX shared
+ # libraries by default.
+ # We can manage to simulate some of them with export/import
+ # files but the overriding of shared library functions or
+ # variables by the main program doesn't seem possible.
+ # We avoid testing those features.
set SHCFLAG "-DXCOFF_TEST"
- # The AIX 3.2.5 loader appears to randomly fail when loading
- # shared libraries from NSF mounted partitions, so we avoid any
- # potential problems by using a local directory.
- catch {exec /bin/sh -c "echo $$"} pid
- set tmpdir /usr/tmp/ld.$pid
- catch "exec mkdir $tmpdir" exec_status
-
- # On AIX, we need to explicitly export the symbols the shared
- # library is going to provide, and need.
- set file [open $tmpdir/xcoff.exp w]
- puts $file shlibvar1
- puts $file shlibvar2
- puts $file shlib_shlibvar1
- puts $file shlib_shlibvar2
- puts $file shlib_shlibcall
- puts $file shlib_shlibcalled
- puts $file shlib_checkfunptr1
- puts $file shlib_getfunptr1
- puts $file shlib_check
+ # In order to avoid listing every symbols in an export file,
+ # the export will be done with -bexpall flag.
+ # However for imports, we must create the import file.
+ set file [open $tmpdir/xcoff-shared.imp w]
+ puts $file "#! ."
+ puts $file mainvar
+ puts $file main_called
close $file
}
@@ -132,10 +120,10 @@ proc shared_test { progname testname main sh1 sh2 dat args } {
if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
# Build the shared library.
- # On AIX, we need to use an export file.
set shared -shared
- if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
- append shared " -Wl,-bE:$tmpdir/xcoff.exp"
+ if { [is_xcoff_format] } {
+ # On AIX, setup imports and exports.
+ append shared " -Wl,-bexpall -Wl,-bI:$tmpdir/xcoff-shared.imp"
}
if { [is_elf_format] && [check_shared_lib_support] } {
append shared " -Wl,-z,notext"
@@ -150,10 +138,12 @@ proc shared_test { progname testname main sh1 sh2 dat args } {
# On AIX, we must include /lib in -rpath, as otherwise the loader
# can not find -lc.
set rpath $tmpdir
- if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
+ set exportflag ""
+ if { [is_xcoff_format] } {
set rpath /lib:$tmpdir
+ set exportflag " -Wl,-bexpall"
}
- if ![ld_link $CC_FOR_TARGET $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
+ if ![ld_link $CC_FOR_TARGET $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so $exportflag"] {
fail "$testname"
return
}
@@ -226,7 +216,7 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.
if { ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
|| ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
unsupported "shared (non PIC)"
- } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
+ } else { if { [is_xcoff_format] } {
shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
} else {
# Solaris defaults to -z text.
@@ -288,12 +278,12 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.
|| ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
unsupported "shared"
} else {
- if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
+ if { [is_xcoff_format] } {
shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
} else {
shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
- ld_compile "$CC_FOR_TARGET -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
- ld_compile "$CC_FOR_TARGET -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
+ ld_compile "$CC_FOR_TARGET -DSYMBOLIC_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
+ ld_compile "$CC_FOR_TARGET -DSYMBOLIC_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
@@ -307,7 +297,7 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi
unsupported "shared (PIC main)"
} else {
if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
- if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
+ if { [is_xcoff_format] } {
shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
} else {
# Solaris defaults to -z text.
@@ -337,7 +327,7 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi
}
if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
- if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
+ if { [is_xcoff_format] } {
shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
} else {
shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared
@@ -348,8 +338,3 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi
}
set CFLAGS_FOR_TARGET "$old_CFLAGS"
-
-if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
- # Remove the temporary directory.
- catch "exec rm -rf $tmpdir" exec_status
-}
diff --git a/ld/testsuite/ld-shared/xcoff.dat b/ld/testsuite/ld-shared/xcoff.dat
index a409d96a1e..249e5daf47 100644
--- a/ld/testsuite/ld-shared/xcoff.dat
+++ b/ld/testsuite/ld-shared/xcoff.dat
@@ -1,10 +1,14 @@
mainvar == 1
overriddenvar == 2
shlibvar1 == 3
+shlib_mainvar () == 1
shlib_shlibvar1 () == 3
shlib_shlibvar2 () == 4
shlib_shlibcall () == 5
+shlib_maincall () == 6
main_called () == 6
shlib_checkfunptr1 (shlib_shlibvar1) == 1
+shlib_checkfunptr2 (main_called) == 1
shlib_getfunptr1 () == shlib_shlibvar1
+shlib_getfunptr2 () == main_called
shlib_check () == 1