diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2010-10-30 23:02:32 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2010-10-30 23:02:32 +0000 |
commit | b3cded65e92ba4d9b5e5a33fb95c4d551bda9c1b (patch) | |
tree | 69d40fbef2c0c4ee32fe97b7a28b510f2e3c2dbc /ld/testsuite/ld-elf | |
parent | 7a815afd9b5121ee0f65dc1e1de1c0de6de97679 (diff) |
Import the binutils master branch from the sourceware CVS repository,vendor/binutils/binutils-master-20070703-075419vendor/binutils
exactly as it was on Tue, 3 Jul 2007 07:54:19 +0000.
Corresponds to git commit 397a64b350470350c8e0adb2af84439ea0f89272,
which was the last commit before switching to GPLv3.
Notes
Notes:
svn path=/vendor/binutils/dist/; revision=214571
svn path=/vendor/binutils/binutils-master-20070703-075419/; revision=214573; tag=vendor/binutils/binutils-master-20070703-075419
Diffstat (limited to 'ld/testsuite/ld-elf')
144 files changed, 2420 insertions, 55 deletions
diff --git a/ld/testsuite/ld-elf/begin.c b/ld/testsuite/ld-elf/begin.c new file mode 100644 index 000000000000..ccc47d4f8708 --- /dev/null +++ b/ld/testsuite/ld-elf/begin.c @@ -0,0 +1,5 @@ +extern void foo (void); + +static void (*const init_array []) (void) + __attribute__ ((used, section (".init_array"), aligned (sizeof (void *)))) + = { foo }; diff --git a/ld/testsuite/ld-elf/beginwarn.c b/ld/testsuite/ld-elf/beginwarn.c new file mode 100644 index 000000000000..ebe28191b56f --- /dev/null +++ b/ld/testsuite/ld-elf/beginwarn.c @@ -0,0 +1,9 @@ +static const char _evoke_link_warning_foo [] + __attribute__ ((used, section (".gnu.warning.foo"))) + = "function foo is deprecated"; + +extern void foo (void); + +static void (*const init_array []) (void) + __attribute__ ((used, section (".init_array"), aligned (sizeof (void *)))) + = { foo }; diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp new file mode 100644 index 000000000000..7ced42ca125b --- /dev/null +++ b/ld/testsuite/ld-elf/binutils.exp @@ -0,0 +1,124 @@ +# Expect script for binutils tests +# Copyright 2006 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. +# +# Written by H.J. Lu (hongjiu.lu@intel.com) +# + +# Make sure that binutils can correctly handle ld output in ELF. + +# Run on Linux only. +if { ![istarget *-*-linux*] } { + return +} + +if { [istarget *-*-linux*aout*] + || [istarget *-*-linux*oldld*] } { + return +} + +proc binutils_test { prog_name ld_options test } { + global as + global ld + global READELF + global objcopy + global strip + global srcdir + global subdir + global link_output + + eval set prog \$$prog_name + set test_name "$prog_name $ld_options ($test)" + + if { ![ld_assemble $as $srcdir/$subdir/$test.s tmpdir/$test.o ] } { + unresolved "$test_name" + return + } + + if { ![ld_simple_link $ld tmpdir/$test "$ld_options tmpdir/$test.o"] } { + if { [string match "*not supported*" $link_output] + || [string match "*unrecognized option*" $link_output] } { + unsupported "$ld_options is not supported by this target" + } else { + unresolved "$test_name" + } + return + } + + send_log "$READELF -l --wide tmpdir/$test > tmpdir/$test.exp\n" + catch "exec $READELF -l --wide tmpdir/$test > tmpdir/$test.exp" got + if ![string match "" $got] then { + send_log "$got\n" + unresolved "$test_name" + return + } + + send_log "$prog tmpdir/$test\n" + catch "exec $prog tmpdir/$test" got + if ![string match "" $got] then { + send_log "$got\n" + fail "$test_name" + return + } + + send_log "$READELF -l --wide tmpdir/$test > tmpdir/$test.out\n" + catch "exec $READELF -l --wide tmpdir/$test > tmpdir/$test.out" got + if ![string match "" $got] then { + send_log "$got\n" + unresolved "$test_name" + return + } + + if { [catch {exec cmp tmpdir/$test.exp tmpdir/$test.out}] } then { + send_log "tmpdir/$test.exp tmpdir/$test.out differ.\n" + fail "$test_name" + return + } + + pass "$test_name" +} + +binutils_test strip "-z max-page-size=0x200000" maxpage1 +binutils_test strip "-z max-page-size=0x200000 -z common-page-size=0x100000" maxpage1 +binutils_test strip "-z max-page-size=0x100000" maxpage1 +binutils_test strip "-z max-page-size=0x100000 -z common-page-size=0x1000" maxpage1 + +binutils_test strip "" maxpage1 +binutils_test strip "-shared" maxpage1 +binutils_test objcopy "" maxpage1 +binutils_test objcopy "-shared" maxpage1 + +binutils_test strip "-z relro" maxpage1 +binutils_test strip "-z relro -shared" maxpage1 +binutils_test objcopy "-z relro" maxpage1 +binutils_test objcopy "-z relro -shared" maxpage1 + +binutils_test objcopy "" tbss1 +binutils_test objcopy "-shared" tbss1 +binutils_test objcopy "-z max-page-size=0x100000" tbss1 +binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tbss1 +binutils_test objcopy "" tdata1 +binutils_test objcopy "-shared" tdata1 +binutils_test objcopy "-z max-page-size=0x100000" tdata1 +binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tdata1 +binutils_test objcopy "" tbss2 +binutils_test objcopy "-shared" tbss2 +binutils_test objcopy "-z max-page-size=0x100000" tbss2 +binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tbss2 +binutils_test objcopy "-z max-page-size=0x100000" tdata2 +binutils_test objcopy "" tdata2 +binutils_test objcopy "-shared" tdata2 +binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tdata2 diff --git a/ld/testsuite/ld-elf/commonpage1.d b/ld/testsuite/ld-elf/commonpage1.d new file mode 100644 index 000000000000..76dc0565b342 --- /dev/null +++ b/ld/testsuite/ld-elf/commonpage1.d @@ -0,0 +1,9 @@ +#source: maxpage1.s +#ld: -z max-page-size=0x200000 -z common-page-size=0x100000 +#readelf: -l --wide +#target: *-*-linux* + +#... + LOAD+.*0x200000 + LOAD+.*0x200000 +#pass diff --git a/ld/testsuite/ld-elf/data1.c b/ld/testsuite/ld-elf/data1.c new file mode 100644 index 000000000000..c205f822bccd --- /dev/null +++ b/ld/testsuite/ld-elf/data1.c @@ -0,0 +1,6 @@ +#include "data1.h" + +char a1[1] __attribute__ ((aligned (ALIGNMENT1))) = { 10 }; +char a2[2] __attribute__ ((aligned (ALIGNMENT2))); +char a3[3] __attribute__ ((aligned (ALIGNMENT3))); +char a4[4] __attribute__ ((aligned (ALIGNMENT4))); diff --git a/ld/testsuite/ld-elf/data1.h b/ld/testsuite/ld-elf/data1.h new file mode 100644 index 000000000000..529ee4b24205 --- /dev/null +++ b/ld/testsuite/ld-elf/data1.h @@ -0,0 +1,9 @@ +#define ALIGNMENT1 0x800 +#define ALIGNMENT2 0x400 +#define ALIGNMENT3 0x200 +#define ALIGNMENT4 0x100 + +extern char a1[1]; +extern char a2[2]; +extern char a3[3]; +extern char a4[4]; diff --git a/ld/testsuite/ld-elf/del.cc b/ld/testsuite/ld-elf/del.cc new file mode 100644 index 000000000000..4e2cc60d74a9 --- /dev/null +++ b/ld/testsuite/ld-elf/del.cc @@ -0,0 +1,29 @@ +#include <new> + +extern "C" void free (void *); + +void +operator delete (void *ptr, const std::nothrow_t&) throw () +{ + if (ptr) + free (ptr); +} + +void +operator delete (void *ptr) throw () +{ + if (ptr) + free (ptr); +} + +void +operator delete[] (void *ptr) throw () +{ + ::operator delete (ptr); +} + +void +operator delete[] (void *ptr, const std::nothrow_t&) throw () +{ + ::operator delete (ptr); +} diff --git a/ld/testsuite/ld-elf/dl1.c b/ld/testsuite/ld-elf/dl1.c new file mode 100644 index 000000000000..09426f32fb7b --- /dev/null +++ b/ld/testsuite/ld-elf/dl1.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +extern int bar; + +void +foo (void) +{ + if (bar == -20) + printf ("OK\n"); +} diff --git a/ld/testsuite/ld-elf/dl1.list b/ld/testsuite/ld-elf/dl1.list new file mode 100644 index 000000000000..9ffada041895 --- /dev/null +++ b/ld/testsuite/ld-elf/dl1.list @@ -0,0 +1,6 @@ +{ + extern "C" + { + bar; + }; +}; diff --git a/ld/testsuite/ld-elf/dl1.out b/ld/testsuite/ld-elf/dl1.out new file mode 100644 index 000000000000..d86bac9de59a --- /dev/null +++ b/ld/testsuite/ld-elf/dl1.out @@ -0,0 +1 @@ +OK diff --git a/ld/testsuite/ld-elf/dl1main.c b/ld/testsuite/ld-elf/dl1main.c new file mode 100644 index 000000000000..f224e12394dd --- /dev/null +++ b/ld/testsuite/ld-elf/dl1main.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <dlfcn.h> + +int bar = -20; + +int +main (void) +{ + int ret = 0; + void *handle; + void (*fcn) (void); + + handle = dlopen("./tmpdir/libdl1.so", RTLD_GLOBAL|RTLD_LAZY); + if (!handle) + { + printf("dlopen ./tmpdir/libdl1.so: %s\n", dlerror ()); + return 1; + } + + fcn = (void (*)(void)) dlsym(handle, "foo"); + if (!fcn) + { + printf("dlsym foo: %s\n", dlerror ()); + ret += 1; + } + else + { + (*fcn) (); + } + + dlclose (handle); + return ret; +} diff --git a/ld/testsuite/ld-elf/dl2.c b/ld/testsuite/ld-elf/dl2.c new file mode 100644 index 000000000000..b5cd9275dab4 --- /dev/null +++ b/ld/testsuite/ld-elf/dl2.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +int foo; + +extern void xxx (void); + +void +bar (int x) +{ + if (foo == 1) + printf ("OK1\n"); + else if (foo == 0) + printf ("OK2\n"); + foo = -1; + xxx (); +} diff --git a/ld/testsuite/ld-elf/dl2.list b/ld/testsuite/ld-elf/dl2.list new file mode 100644 index 000000000000..e985dcfca24c --- /dev/null +++ b/ld/testsuite/ld-elf/dl2.list @@ -0,0 +1,3 @@ +{ + foo; +}; diff --git a/ld/testsuite/ld-elf/dl2a.list b/ld/testsuite/ld-elf/dl2a.list new file mode 100644 index 000000000000..989646e63f1a --- /dev/null +++ b/ld/testsuite/ld-elf/dl2a.list @@ -0,0 +1,3 @@ +{ + "foo"; +}; diff --git a/ld/testsuite/ld-elf/dl2a.out b/ld/testsuite/ld-elf/dl2a.out new file mode 100644 index 000000000000..f3d5b9ffcc0e --- /dev/null +++ b/ld/testsuite/ld-elf/dl2a.out @@ -0,0 +1,3 @@ +OK1 +DSO +OK1 diff --git a/ld/testsuite/ld-elf/dl2b.out b/ld/testsuite/ld-elf/dl2b.out new file mode 100644 index 000000000000..f30cead5244b --- /dev/null +++ b/ld/testsuite/ld-elf/dl2b.out @@ -0,0 +1,3 @@ +OK1 +MAIN +OK1 diff --git a/ld/testsuite/ld-elf/dl2main.c b/ld/testsuite/ld-elf/dl2main.c new file mode 100644 index 000000000000..ddf677fd3bcf --- /dev/null +++ b/ld/testsuite/ld-elf/dl2main.c @@ -0,0 +1,22 @@ +#include <stdio.h> + +extern int foo; +extern void bar (void); + +void +xxx (void) +{ + printf ("MAIN\n"); +} + +int +main (void) +{ + foo = 1; + bar (); + if (foo == -1) + printf ("OK1\n"); + else if (foo == 1) + printf ("OK2\n"); + return 0; +} diff --git a/ld/testsuite/ld-elf/dl2xxx.c b/ld/testsuite/ld-elf/dl2xxx.c new file mode 100644 index 000000000000..cf3a1d0c66c8 --- /dev/null +++ b/ld/testsuite/ld-elf/dl2xxx.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +void +xxx (void) +{ + printf ("DSO\n"); +} diff --git a/ld/testsuite/ld-elf/dl2xxx.list b/ld/testsuite/ld-elf/dl2xxx.list new file mode 100644 index 000000000000..9388cda7f52e --- /dev/null +++ b/ld/testsuite/ld-elf/dl2xxx.list @@ -0,0 +1,3 @@ +{ + xxx; +}; diff --git a/ld/testsuite/ld-elf/dl3.cc b/ld/testsuite/ld-elf/dl3.cc new file mode 100644 index 000000000000..558e49f74c2c --- /dev/null +++ b/ld/testsuite/ld-elf/dl3.cc @@ -0,0 +1,7 @@ +#include "dl3header.h" + +void +f (void) +{ + throw (A (42)); +} diff --git a/ld/testsuite/ld-elf/dl3.list b/ld/testsuite/ld-elf/dl3.list new file mode 100644 index 000000000000..0b347ea2dabd --- /dev/null +++ b/ld/testsuite/ld-elf/dl3.list @@ -0,0 +1,6 @@ +{ + extern "C++" + { + typeinfo*; + }; +}; diff --git a/ld/testsuite/ld-elf/dl3a.out b/ld/testsuite/ld-elf/dl3a.out new file mode 100644 index 000000000000..d86bac9de59a --- /dev/null +++ b/ld/testsuite/ld-elf/dl3a.out @@ -0,0 +1 @@ +OK diff --git a/ld/testsuite/ld-elf/dl3b.out b/ld/testsuite/ld-elf/dl3b.out new file mode 100644 index 000000000000..8a1504410770 --- /dev/null +++ b/ld/testsuite/ld-elf/dl3b.out @@ -0,0 +1 @@ +BAD2 diff --git a/ld/testsuite/ld-elf/dl3header.h b/ld/testsuite/ld-elf/dl3header.h new file mode 100644 index 000000000000..66f7d4621f24 --- /dev/null +++ b/ld/testsuite/ld-elf/dl3header.h @@ -0,0 +1,5 @@ +struct A +{ + int i; + A (int i): i(i) {} +}; diff --git a/ld/testsuite/ld-elf/dl3main.cc b/ld/testsuite/ld-elf/dl3main.cc new file mode 100644 index 000000000000..977f9bb02774 --- /dev/null +++ b/ld/testsuite/ld-elf/dl3main.cc @@ -0,0 +1,25 @@ +#include <stdio.h> +#include "dl3header.h" + +extern void f (void); + +int +main (void) +{ + try + { + f(); + } + catch (A a) + { + if (a.i == 42) + printf ("OK\n"); + else + printf ("BAD1\n"); + } + catch (...) + { + printf ("BAD2\n"); + } + return 0; +} diff --git a/ld/testsuite/ld-elf/dl4.c b/ld/testsuite/ld-elf/dl4.c new file mode 100644 index 000000000000..bf6f070cb759 --- /dev/null +++ b/ld/testsuite/ld-elf/dl4.c @@ -0,0 +1,24 @@ +#include <stdio.h> + +int foo1; +int foo2; + +extern void xxx1 (void); +extern void xxx2 (void); + +void +bar (int x) +{ + if (foo1 == 1) + printf ("bar OK1\n"); + else if (foo1 == 0) + printf ("bar OK2\n"); + if (foo2 == 1) + printf ("bar OK3\n"); + else if (foo2 == 0) + printf ("bar OK4\n"); + foo1 = -1; + foo2 = -1; + xxx1 (); + xxx2 (); +} diff --git a/ld/testsuite/ld-elf/dl4.list b/ld/testsuite/ld-elf/dl4.list new file mode 100644 index 000000000000..e932e2352e32 --- /dev/null +++ b/ld/testsuite/ld-elf/dl4.list @@ -0,0 +1,4 @@ +{ + foo1; + foo2; +}; diff --git a/ld/testsuite/ld-elf/dl4a.out b/ld/testsuite/ld-elf/dl4a.out new file mode 100644 index 000000000000..871c5be830ac --- /dev/null +++ b/ld/testsuite/ld-elf/dl4a.out @@ -0,0 +1,6 @@ +bar OK1 +bar OK3 +DSO1 +DSO2 +OK1 +OK3 diff --git a/ld/testsuite/ld-elf/dl4b.out b/ld/testsuite/ld-elf/dl4b.out new file mode 100644 index 000000000000..b838f5b4b7f2 --- /dev/null +++ b/ld/testsuite/ld-elf/dl4b.out @@ -0,0 +1,6 @@ +bar OK1 +bar OK3 +MAIN1 +MAIN2 +OK1 +OK3 diff --git a/ld/testsuite/ld-elf/dl4main.c b/ld/testsuite/ld-elf/dl4main.c new file mode 100644 index 000000000000..173450da1a89 --- /dev/null +++ b/ld/testsuite/ld-elf/dl4main.c @@ -0,0 +1,34 @@ +#include <stdio.h> + +extern int foo1; +extern int foo2; +extern void bar (void); + +void +xxx1 (void) +{ + printf ("MAIN1\n"); +} + +void +xxx2 (void) +{ + printf ("MAIN2\n"); +} + +int +main (void) +{ + foo1 = 1; + foo2 = 1; + bar (); + if (foo1 == -1) + printf ("OK1\n"); + else if (foo1 == 1) + printf ("OK2\n"); + if (foo2 == -1) + printf ("OK3\n"); + else if (foo2 == 1) + printf ("OK4\n"); + return 0; +} diff --git a/ld/testsuite/ld-elf/dl4xxx.c b/ld/testsuite/ld-elf/dl4xxx.c new file mode 100644 index 000000000000..8180eb141292 --- /dev/null +++ b/ld/testsuite/ld-elf/dl4xxx.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +void +xxx1 (void) +{ + printf ("DSO1\n"); +} + +void +xxx2 (void) +{ + printf ("DSO2\n"); +} diff --git a/ld/testsuite/ld-elf/dl4xxx.list b/ld/testsuite/ld-elf/dl4xxx.list new file mode 100644 index 000000000000..f39ce14d01af --- /dev/null +++ b/ld/testsuite/ld-elf/dl4xxx.list @@ -0,0 +1,4 @@ +{ + xxx1; + xxx2; +}; diff --git a/ld/testsuite/ld-elf/dl5.cc b/ld/testsuite/ld-elf/dl5.cc new file mode 100644 index 000000000000..cc404553f93b --- /dev/null +++ b/ld/testsuite/ld-elf/dl5.cc @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <stdlib.h> +#include <new> + +int pass = 0; + +void * +operator new (size_t sz, const std::nothrow_t&) throw () +{ + void *p; + pass++; + p = malloc(sz); + return p; +} + +void * +operator new (size_t sz) throw (std::bad_alloc) +{ + void *p; + pass++; + p = malloc(sz); + return p; +} + +void +operator delete (void *ptr) throw () +{ + pass++; + if (ptr) + free (ptr); +} + +class A +{ +public: + A() {} + ~A() { } + int a; + int b; +}; + + +int +main (void) +{ + A *bb = new A[10]; + delete [] bb; + bb = new (std::nothrow) A [10]; + delete [] bb; + + if (pass == 4) + { + printf ("PASS\n"); + return 0; + } + else + { + printf ("FAIL\n"); + return 1; + } +} diff --git a/ld/testsuite/ld-elf/dl5.out b/ld/testsuite/ld-elf/dl5.out new file mode 100644 index 000000000000..7ef22e9a431a --- /dev/null +++ b/ld/testsuite/ld-elf/dl5.out @@ -0,0 +1 @@ +PASS diff --git a/ld/testsuite/ld-elf/dl6.c b/ld/testsuite/ld-elf/dl6.c new file mode 100644 index 000000000000..f655ca6ef335 --- /dev/null +++ b/ld/testsuite/ld-elf/dl6.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +int bar = 10; + +void +foo (void) +{ + if (bar == 10) + printf ("bar is in DSO.\n"); + else if (bar == -20) + printf ("bar is in main.\n"); + else + printf ("FAIL\n"); +} diff --git a/ld/testsuite/ld-elf/dl6a.out b/ld/testsuite/ld-elf/dl6a.out new file mode 100644 index 000000000000..186e8488e29c --- /dev/null +++ b/ld/testsuite/ld-elf/dl6a.out @@ -0,0 +1 @@ +bar is in main. diff --git a/ld/testsuite/ld-elf/dl6amain.c b/ld/testsuite/ld-elf/dl6amain.c new file mode 100644 index 000000000000..9824224661a7 --- /dev/null +++ b/ld/testsuite/ld-elf/dl6amain.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <dlfcn.h> + +int bar = -20; + +int +main (void) +{ + int ret = 0; + void *handle; + void (*fcn) (void); + + handle = dlopen("./tmpdir/libdl6a.so", RTLD_GLOBAL|RTLD_LAZY); + if (!handle) + { + printf("dlopen ./tmpdir/libdl6a.so: %s\n", dlerror ()); + return 1; + } + + fcn = (void (*)(void)) dlsym(handle, "foo"); + if (!fcn) + { + printf("dlsym foo: %s\n", dlerror ()); + ret += 1; + } + else + { + (*fcn) (); + } + + dlclose (handle); + return ret; +} diff --git a/ld/testsuite/ld-elf/dl6b.out b/ld/testsuite/ld-elf/dl6b.out new file mode 100644 index 000000000000..8cc87f50d137 --- /dev/null +++ b/ld/testsuite/ld-elf/dl6b.out @@ -0,0 +1 @@ +bar is in DSO. diff --git a/ld/testsuite/ld-elf/dl6bmain.c b/ld/testsuite/ld-elf/dl6bmain.c new file mode 100644 index 000000000000..df9dbcc3fee8 --- /dev/null +++ b/ld/testsuite/ld-elf/dl6bmain.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <dlfcn.h> + +int bar = -20; + +int +main (void) +{ + int ret = 0; + void *handle; + void (*fcn) (void); + + handle = dlopen("./tmpdir/libdl6b.so", RTLD_GLOBAL|RTLD_LAZY); + if (!handle) + { + printf("dlopen ./tmpdir/libdl6b.so: %s\n", dlerror ()); + return 1; + } + + fcn = (void (*)(void)) dlsym(handle, "foo"); + if (!fcn) + { + printf("dlsym foo: %s\n", dlerror ()); + ret += 1; + } + else + { + (*fcn) (); + } + + dlclose (handle); + return ret; +} diff --git a/ld/testsuite/ld-elf/dl6cmain.c b/ld/testsuite/ld-elf/dl6cmain.c new file mode 100644 index 000000000000..f6c285cdf621 --- /dev/null +++ b/ld/testsuite/ld-elf/dl6cmain.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <dlfcn.h> + +int bar = -20; + +int +main (void) +{ + int ret = 0; + void *handle; + void (*fcn) (void); + + handle = dlopen("./tmpdir/libdl6c.so", RTLD_GLOBAL|RTLD_LAZY); + if (!handle) + { + printf("dlopen ./tmpdir/libdl6c.so: %s\n", dlerror ()); + return 1; + } + + fcn = (void (*)(void)) dlsym(handle, "foo"); + if (!fcn) + { + printf("dlsym foo: %s\n", dlerror ()); + ret += 1; + } + else + { + (*fcn) (); + } + + dlclose (handle); + return ret; +} diff --git a/ld/testsuite/ld-elf/dl6dmain.c b/ld/testsuite/ld-elf/dl6dmain.c new file mode 100644 index 000000000000..2e57eb751e9d --- /dev/null +++ b/ld/testsuite/ld-elf/dl6dmain.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <dlfcn.h> + +int bar = -20; + +int +main (void) +{ + int ret = 0; + void *handle; + void (*fcn) (void); + + handle = dlopen("./tmpdir/libdl6d.so", RTLD_GLOBAL|RTLD_LAZY); + if (!handle) + { + printf("dlopen ./tmpdir/libdl6d.so: %s\n", dlerror ()); + return 1; + } + + fcn = (void (*)(void)) dlsym(handle, "foo"); + if (!fcn) + { + printf("dlsym foo: %s\n", dlerror ()); + ret += 1; + } + else + { + (*fcn) (); + } + + dlclose (handle); + return ret; +} diff --git a/ld/testsuite/ld-elf/dummy.c b/ld/testsuite/ld-elf/dummy.c new file mode 100644 index 000000000000..5c0328739c60 --- /dev/null +++ b/ld/testsuite/ld-elf/dummy.c @@ -0,0 +1 @@ +/* An empty file. */ diff --git a/ld/testsuite/ld-elf/dwarf.exp b/ld/testsuite/ld-elf/dwarf.exp new file mode 100644 index 000000000000..b10e3d256c79 --- /dev/null +++ b/ld/testsuite/ld-elf/dwarf.exp @@ -0,0 +1,111 @@ +# Expect script for various DWARF tests. +# Copyright 2006 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# Written by H.J. Lu (hongjiu.lu@intel.com) +# + +# Exclude non-ELF targets. + +if ![is_elf_format] { + return +} + +# The following tests require running the executable generated by ld. +if ![isnative] { + return +} + +# Check if compiler works +if { [which $CC] == 0 } { + return +} + +# Skip if -feliminate-dwarf2-dups isn't supported. +if ![ld_compile "$CC -g -feliminate-dwarf2-dups" $srcdir/$subdir/dummy.c tmpdir/dummy.o] { + return +} + +set build_tests { + {"Build libdwarf1.so" + "-s -shared" "-fPIC -g -feliminate-dwarf2-dups" + {dwarf1.c} {} "libdwarf1.so"} +} + +set run_tests { + {"Run with libdwarf1.so first" + "tmpdir/libdwarf1.so" "" + {dwarf1main.c} "dwarf1a" "dwarf1.out" + "-g -feliminate-dwarf2-dups"} + {"Run with libdwarf1.so last" + "tmpdir/dwarf1main.o tmpdir/libdwarf1.so" "" + {dummy.c} "dwarf1b" "dwarf1.out" + "-g -feliminate-dwarf2-dups"} +} + +run_cc_link_tests $build_tests +run_ld_link_exec_tests [] $run_tests + +proc strip_test {} { + global ld + global strip + global NM + + set test "libdwarf1c.so" + set test_name "Strip -s $test" + set prog $strip + + if ![ld_simple_link $ld tmpdir/$test "-shared tmpdir/dwarf1.o"] { + unresolved "$test_name" + return + } + + send_log "$NM -D tmpdir/$test > tmpdir/$test.exp\n" + catch "exec $NM -D tmpdir/$test > tmpdir/$test.exp" got + if ![string match "" $got] then { + send_log "$got\n" + unresolved "$test_name" + return + } + + send_log "$prog -s tmpdir/$test\n" + catch "exec $prog -s tmpdir/$test" got + if ![string match "" $got] then { + send_log "$got\n" + fail "$test_name" + return + } + + send_log "$NM -D tmpdir/$test > tmpdir/$test.out\n" + catch "exec $NM -D tmpdir/$test > tmpdir/$test.out" got + if ![string match "" $got] then { + send_log "$got\n" + unresolved "$test_name" + return + } + + if { [catch {exec cmp tmpdir/$test.exp tmpdir/$test.out}] } then { + send_log "tmpdir/$test.exp tmpdir/$test.out differ.\n" + fail "$test_name" + return + } + + pass "$test_name" +} + +strip_test diff --git a/ld/testsuite/ld-elf/dwarf1.c b/ld/testsuite/ld-elf/dwarf1.c new file mode 100644 index 000000000000..2895d4c8a770 --- /dev/null +++ b/ld/testsuite/ld-elf/dwarf1.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include "dwarf1.h" + +struct foo_s foo; + +void +doprintf (void) +{ + printf ("OK\n"); +} diff --git a/ld/testsuite/ld-elf/dwarf1.h b/ld/testsuite/ld-elf/dwarf1.h new file mode 100644 index 000000000000..3cd7918c070a --- /dev/null +++ b/ld/testsuite/ld-elf/dwarf1.h @@ -0,0 +1,6 @@ +struct foo_s +{ + int foo; +}; + +extern void doprintf (void); diff --git a/ld/testsuite/ld-elf/dwarf1.out b/ld/testsuite/ld-elf/dwarf1.out new file mode 100644 index 000000000000..d86bac9de59a --- /dev/null +++ b/ld/testsuite/ld-elf/dwarf1.out @@ -0,0 +1 @@ +OK diff --git a/ld/testsuite/ld-elf/dwarf1main.c b/ld/testsuite/ld-elf/dwarf1main.c new file mode 100644 index 000000000000..90451981d380 --- /dev/null +++ b/ld/testsuite/ld-elf/dwarf1main.c @@ -0,0 +1,10 @@ +#include "dwarf1.h" + +struct foo_s foo; + +int +main (void) +{ + doprintf (); + return 0; +} diff --git a/ld/testsuite/ld-elf/dynbss1.c b/ld/testsuite/ld-elf/dynbss1.c new file mode 100644 index 000000000000..eb5f0673998e --- /dev/null +++ b/ld/testsuite/ld-elf/dynbss1.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> +#include "data1.h" + +int +main (void) +{ + if ((((long) (&a1)) & (ALIGNMENT1 - 1))) + abort (); + if ((((long) (&a2)) & (ALIGNMENT2 - 1))) + abort (); + if ((((long) (&a2)) & (ALIGNMENT3 - 1))) + abort (); + if ((((long) (&a3)) & (ALIGNMENT4 - 1))) + abort (); + + printf ("PASS\n"); + + return(0) ; +} diff --git a/ld/testsuite/ld-elf/eh-frame-hdr.d b/ld/testsuite/ld-elf/eh-frame-hdr.d new file mode 100644 index 000000000000..b465e5de2d57 --- /dev/null +++ b/ld/testsuite/ld-elf/eh-frame-hdr.d @@ -0,0 +1,17 @@ +#source: eh-frame-hdr.s +#ld: -e _start --eh-frame-hdr +#objdump: -hw +#target: alpha*-*-* +#target: arm*-*-* +#target: i?86-*-* +#target: m68k-*-* +#target: mips*-*-* +#target: powerpc*-*-* +#target: s390*-*-* +#target: sh*-*-* +#xfail: sh*l*-*-* +#target: sparc*-*-* +#target: x86_64-*-* +#... + [0-9] .eh_frame_hdr 0*[12][048c] .* +#pass diff --git a/ld/testsuite/ld-elf/eh-frame-hdr.s b/ld/testsuite/ld-elf/eh-frame-hdr.s new file mode 100644 index 000000000000..e5d33189eb38 --- /dev/null +++ b/ld/testsuite/ld-elf/eh-frame-hdr.s @@ -0,0 +1,6 @@ + .text + .global _start +_start: + .cfi_startproc + .skip 16 + .cfi_endproc diff --git a/ld/testsuite/ld-elf/eh1.d b/ld/testsuite/ld-elf/eh1.d index 897955b2b6f7..d7a5b15d3251 100644 --- a/ld/testsuite/ld-elf/eh1.d +++ b/ld/testsuite/ld-elf/eh1.d @@ -22,11 +22,11 @@ The section .eh_frame contains: DW_CFA_nop DW_CFA_nop -00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0 - DW_CFA_advance_loc: 0 to 004000b0 +00000018 0000001c 0000001c FDE cie=00000000 pc=00400078..00400078 + DW_CFA_advance_loc: 0 to 00400078 DW_CFA_def_cfa_offset: 16 DW_CFA_offset: r6 at cfa-16 - DW_CFA_advance_loc: 0 to 004000b0 + DW_CFA_advance_loc: 0 to 00400078 DW_CFA_def_cfa_reg: r6 00000038 ZERO terminator diff --git a/ld/testsuite/ld-elf/eh2.d b/ld/testsuite/ld-elf/eh2.d index 6f4f2c58ed59..c1ef3994fb82 100644 --- a/ld/testsuite/ld-elf/eh2.d +++ b/ld/testsuite/ld-elf/eh2.d @@ -22,11 +22,11 @@ The section .eh_frame contains: DW_CFA_nop DW_CFA_nop -00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0 - DW_CFA_advance_loc: 0 to 004000b0 +00000018 0000001c 0000001c FDE cie=00000000 pc=00400078..00400078 + DW_CFA_advance_loc: 0 to 00400078 DW_CFA_def_cfa_offset: 16 DW_CFA_offset: r6 at cfa-16 - DW_CFA_advance_loc: 0 to 004000b0 + DW_CFA_advance_loc: 0 to 00400078 DW_CFA_def_cfa_reg: r6 00000038 ZERO terminator diff --git a/ld/testsuite/ld-elf/eh3.d b/ld/testsuite/ld-elf/eh3.d index 492c87784b92..f1d2a523759f 100644 --- a/ld/testsuite/ld-elf/eh3.d +++ b/ld/testsuite/ld-elf/eh3.d @@ -22,11 +22,11 @@ The section .eh_frame contains: DW_CFA_nop DW_CFA_nop -00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0 - DW_CFA_advance_loc: 0 to 004000b0 +00000018 0000001c 0000001c FDE cie=00000000 pc=00400078..00400078 + DW_CFA_advance_loc: 0 to 00400078 DW_CFA_def_cfa_offset: 16 DW_CFA_offset: r6 at cfa-16 - DW_CFA_advance_loc: 0 to 004000b0 + DW_CFA_advance_loc: 0 to 00400078 DW_CFA_def_cfa_reg: r6 00000038 ZERO terminator diff --git a/ld/testsuite/ld-elf/eh4.d b/ld/testsuite/ld-elf/eh4.d new file mode 100644 index 000000000000..5fdd722bd387 --- /dev/null +++ b/ld/testsuite/ld-elf/eh4.d @@ -0,0 +1,32 @@ +#source: eh4.s +#source: eh4a.s +#ld: -shared +#readelf: -wf +#target: x86_64-*-* + +The section .eh_frame contains: + +00000000 00000014 00000000 CIE + Version: 1 + Augmentation: "zR" + Code alignment factor: 1 + Data alignment factor: -8 + Return address column: 16 + Augmentation data: 1b + + DW_CFA_def_cfa: r7 ofs 8 + DW_CFA_offset: r16 at cfa-8 + DW_CFA_nop + DW_CFA_nop + +00000018 00000014 0000001c FDE cie=00000000 pc=00000400..00000413 + DW_CFA_set_loc: 00000404 + DW_CFA_def_cfa_offset: 80 + +00000030 00000014 00000034 FDE cie=00000000 pc=00000413..00000426 + DW_CFA_set_loc: 00000417 + DW_CFA_def_cfa_offset: 80 + +00000048 ZERO terminator +#pass + diff --git a/ld/testsuite/ld-elf/eh4.s b/ld/testsuite/ld-elf/eh4.s new file mode 100644 index 000000000000..2714ad64dc84 --- /dev/null +++ b/ld/testsuite/ld-elf/eh4.s @@ -0,0 +1,92 @@ + .text + .align 512 + .globl foo + .type foo, @function +foo: +.LFB1: + subq $72, %rsp +.LCFI1: + xorl %eax, %eax + movq %rsp, %rdi + call bar@PLT + addq $72, %rsp + ret +.LFE1: + .size foo, .-foo + .globl bar + .type bar, @function +bar: +.LFB2: + subq $72, %rsp +.LCFI2: + xorl %eax, %eax + movq %rsp, %rdi + call bar@PLT + addq $72, %rsp + ret +.LFE2: + .size bar, .-bar + .section .eh_frame,"a",@progbits +.Lframe1: + .long .LECIE1-.LSCIE1 # Length of Common Information Entry +.LSCIE1: + .long 0x0 # CIE Identifier Tag + .byte 0x1 # CIE Version + .ascii "zR\0" # CIE Augmentation + .uleb128 0x1 # CIE Code Alignment Factor + .sleb128 -8 # CIE Data Alignment Factor + .byte 0x10 # CIE RA Column + .uleb128 0x1 # Augmentation size + .byte 0x1b # FDE Encoding (pcrel sdata4) + .byte 0xc # DW_CFA_def_cfa + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 # DW_CFA_offset, column 0x10 + .uleb128 0x1 + .align 8 +.LECIE1: +.LSFDE1: + .long .LEFDE1-.LASFDE1 # FDE Length +.LASFDE1: + .long .LASFDE1-.Lframe1 # FDE CIE offset + .long .LFB1-. # FDE initial location + .long .LFE1-.LFB1 # FDE address range + .uleb128 0x0 # Augmentation size + .byte 0x1 # DW_CFA_set_loc + .long .LCFI1-. + .byte 0xe # DW_CFA_def_cfa_offset + .uleb128 0x50 + .align 8 +.LEFDE1: +.Lframe2: + .long .LECIE2-.LSCIE2 # Length of Common Information Entry +.LSCIE2: + .long 0x0 # CIE Identifier Tag + .byte 0x1 # CIE Version + .ascii "zR\0" # CIE Augmentation + .uleb128 0x1 # CIE Code Alignment Factor + .sleb128 -8 # CIE Data Alignment Factor + .byte 0x10 # CIE RA Column + .uleb128 0x1 # Augmentation size + .byte 0x1b # FDE Encoding (pcrel sdata4) + .byte 0xc # DW_CFA_def_cfa + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 # DW_CFA_offset, column 0x10 + .uleb128 0x1 + .align 8 +.LECIE2: +.LSFDE2: + .long .LEFDE2-.LASFDE2 # FDE Length +.LASFDE2: + .long .LASFDE2-.Lframe2 # FDE CIE offset + .long .LFB2-. # FDE initial location + .long .LFE2-.LFB2 # FDE address range + .uleb128 0x0 # Augmentation size + .byte 0x1 # DW_CFA_set_loc + .long .LCFI2-. + .byte 0xe # DW_CFA_def_cfa_offset + .uleb128 0x50 + .align 8 +.LEFDE2: + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-elf/eh4a.s b/ld/testsuite/ld-elf/eh4a.s new file mode 100644 index 000000000000..c245871ed10d --- /dev/null +++ b/ld/testsuite/ld-elf/eh4a.s @@ -0,0 +1,3 @@ + .section .eh_frame,"a",%progbits + .align 8 + .zero 8 diff --git a/ld/testsuite/ld-elf/eh5.d b/ld/testsuite/ld-elf/eh5.d new file mode 100644 index 000000000000..c12562aa3b32 --- /dev/null +++ b/ld/testsuite/ld-elf/eh5.d @@ -0,0 +1,161 @@ +#source: eh5.s +#source: eh5a.s +#source: eh5b.s +#ld: +#readelf: -wf +#target: x86_64-*-* i?86-*-* + +The section .eh_frame contains: + +00000000 0000001[04] 00000000 CIE + Version: 1 + Augmentation: "zR" + Code alignment factor: 1 + Data alignment factor: .* + Return address column: .* + Augmentation data: 1b + + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop +#... +0000001[48] 00000014 0000001[8c] FDE cie=00000000 pc=.* + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000000(2c|30) 00000014 00000000 CIE + Version: 1 + Augmentation: "zPR" + Code alignment factor: 1 + Data alignment factor: .* + Return address column: .* + Augmentation data: 03 .. .. .. .. 1b + + DW_CFA_nop + +0000004[48] 00000014 0000001c FDE cie=000000(2c|30) pc=.* + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000000(5c|60) 00000014 0000006[04] FDE cie=00000000 pc=.* + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +0000007[48] 0000001[8c] 00000000 CIE + Version: 1 + Augmentation: "zPLR" + Code alignment factor: 1 + Data alignment factor: .* + Return address column: .* + Augmentation data: 03 .. .. .. .. 0c 1b + + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop +#... +0000009[08] 0000001c 0000002[04] FDE cie=0000007[48] pc=.* + Augmentation data: (ef be ad de 00 00 00 00|00 00 00 00 de ad be ef) + + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000000b[08] 0000001[04] 00000000 CIE + Version: 1 + Augmentation: "zR" + Code alignment factor: 1 + Data alignment factor: .* + Return address column: .* + Augmentation data: 1b + + DW_CFA_def_cfa: r0 ofs 16 +#... +000000(c4|d0) 0000001[04] 0000001[8c] FDE cie=000000b[08] pc=.* + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop +#... +000000[de]8 00000014 00000000 CIE + Version: 1 + Augmentation: "zPR" + Code alignment factor: 1 + Data alignment factor: .* + Return address column: .* + Augmentation data: 03 .. .. .. .. 1b + + DW_CFA_nop + +00000(0f|10)0 00000014 0000001c FDE cie=000000[de]8 pc=.* + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000001[01]8 0000001[04] 000000(5c|64) FDE cie=000000b[08] pc=.* + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop +#... +000001(1c|30) 0000001[8c] 00000000 CIE + Version: 1 + Augmentation: "zPLR" + Code alignment factor: 1 + Data alignment factor: .* + Return address column: .* + Augmentation data: 03 .. .. .. .. 0c 1b + + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop +#... +000001(38|50) 0000001c 0000002[04] FDE cie=000001(1c|30) pc=.* + Augmentation data: (ef be ad de 00 00 00 00|00 00 00 00 de ad be ef) + + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000001(58|70) 00000014 000001(5c|74) FDE cie=00000000 pc=.* + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000001(70|88) 00000014 000001(48|5c) FDE cie=000000(2c|30) pc=.* + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000001(88|a0) 00000014 000001(8c|a4) FDE cie=00000000 pc=.* + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +000001(a0|b8) 0000001c 000001(30|44) FDE cie=0000007[48] pc=.* + Augmentation data: (ef be ad de 00 00 00 00|00 00 00 00 de ad be ef) + + DW_CFA_advance_loc: 4 to .* + DW_CFA_def_cfa: r0 ofs 16 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + diff --git a/ld/testsuite/ld-elf/eh5.s b/ld/testsuite/ld-elf/eh5.s new file mode 100644 index 000000000000..6af48c2c1adc --- /dev/null +++ b/ld/testsuite/ld-elf/eh5.s @@ -0,0 +1,29 @@ + .text + .cfi_startproc simple + .long 0 + .cfi_def_cfa 0, 16 + .long 0 + .cfi_endproc + + .cfi_startproc simple + .cfi_personality 3, my_personality_v0 + .long 0 + .cfi_def_cfa 0, 16 + .cfi_endproc + + .cfi_startproc simple + .long 0 + .cfi_def_cfa 0, 16 + .long 0 + .cfi_endproc + + .cfi_startproc simple + .cfi_personality 3, my_personality_v0 + .cfi_lsda 12, 0xdeadbeef + .long 0 + .cfi_def_cfa 0, 16 + .cfi_endproc + + .globl my_personality_v0 +my_personality_v0: + .long 0 diff --git a/ld/testsuite/ld-elf/eh5a.s b/ld/testsuite/ld-elf/eh5a.s new file mode 100644 index 000000000000..a74b2cc84327 --- /dev/null +++ b/ld/testsuite/ld-elf/eh5a.s @@ -0,0 +1,27 @@ + .text + .cfi_startproc simple + .cfi_def_cfa 0, 16 + .long 0 + .cfi_endproc + + .cfi_startproc simple + .cfi_personality 3, my_personality_v1 + .long 0 + .cfi_def_cfa 0, 16 + .cfi_endproc + + .cfi_startproc simple + .cfi_def_cfa 0, 16 + .long 0 + .cfi_endproc + + .cfi_startproc simple + .cfi_personality 3, my_personality_v1 + .cfi_lsda 12, 0xdeadbeef + .long 0 + .cfi_def_cfa 0, 16 + .cfi_endproc + + .globl my_personality_v1 +my_personality_v1: + .long 0 diff --git a/ld/testsuite/ld-elf/eh5b.s b/ld/testsuite/ld-elf/eh5b.s new file mode 100644 index 000000000000..3e5e0108f95d --- /dev/null +++ b/ld/testsuite/ld-elf/eh5b.s @@ -0,0 +1,29 @@ + .text + .cfi_startproc simple + .long 0 + .cfi_def_cfa 0, 16 + .long 0 + .cfi_endproc + + .cfi_startproc simple + .cfi_personality 3, my_personality_v0 + .long 0 + .cfi_def_cfa 0, 16 + .cfi_endproc + + .cfi_startproc simple + .long 0 + .cfi_def_cfa 0, 16 + .long 0 + .cfi_endproc + + .cfi_startproc simple + .cfi_personality 3, my_personality_v0 + .cfi_lsda 12, 0xdeadbeef + .long 0 + .cfi_def_cfa 0, 16 + .cfi_endproc + + .globl _start +_start: + .long 0 diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp index 43c42822bc08..66b5babfb208 100644 --- a/ld/testsuite/ld-elf/elf.exp +++ b/ld/testsuite/ld-elf/elf.exp @@ -1,5 +1,5 @@ # Expect script for various ELF tests. -# Copyright 2002, 2003 Free Software Foundation, Inc. +# Copyright 2002, 2003, 2005, 2007 Free Software Foundation, Inc. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +22,10 @@ if ![is_elf_format] { return } +if { [istarget spu*-*-*] } { + set LDFLAGS "$LDFLAGS --local-store 0:0" +} + set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] foreach t $test_list { # We need to strip the ".d", but can leave the dirname. diff --git a/ld/testsuite/ld-elf/end.c b/ld/testsuite/ld-elf/end.c new file mode 100644 index 000000000000..f7b681adbbd6 --- /dev/null +++ b/ld/testsuite/ld-elf/end.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +void +foo () +{ + printf ("TEST1\n"); +} diff --git a/ld/testsuite/ld-elf/endhidden.c b/ld/testsuite/ld-elf/endhidden.c new file mode 100644 index 000000000000..2cab97af1843 --- /dev/null +++ b/ld/testsuite/ld-elf/endhidden.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +__attribute__ ((visibility ("hidden"))) +void +foo () +{ + printf ("TEST1\n"); +} diff --git a/ld/testsuite/ld-elf/endprotected.c b/ld/testsuite/ld-elf/endprotected.c new file mode 100644 index 000000000000..b6b39ea92ad9 --- /dev/null +++ b/ld/testsuite/ld-elf/endprotected.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +__attribute__ ((visibility ("protected"))) +void +foo () +{ + printf ("TEST1\n"); +} diff --git a/ld/testsuite/ld-elf/expr1.d b/ld/testsuite/ld-elf/expr1.d new file mode 100644 index 000000000000..7bf5d227e5da --- /dev/null +++ b/ld/testsuite/ld-elf/expr1.d @@ -0,0 +1,2 @@ +# ld: -T expr1.t +# error: expr1.t:3: nonconstant expression for load base diff --git a/ld/testsuite/ld-elf/expr1.s b/ld/testsuite/ld-elf/expr1.s new file mode 100644 index 000000000000..998bbc086fa4 --- /dev/null +++ b/ld/testsuite/ld-elf/expr1.s @@ -0,0 +1,4 @@ + .section .bar,"ax","progbits" + .byte 0 + .section .foo,"aw","progbits" + .byte 0 diff --git a/ld/testsuite/ld-elf/expr1.t b/ld/testsuite/ld-elf/expr1.t new file mode 100644 index 000000000000..9670e255bbdd --- /dev/null +++ b/ld/testsuite/ld-elf/expr1.t @@ -0,0 +1,6 @@ +SECTIONS +{ + .bar : AT ((ADDR(.foo) + 4095) & ~(4095)) { *(.bar) } + .foo : { *(.foo) } + /DISCARD/ : { *(.*) } +} diff --git a/ld/testsuite/ld-elf/extract-symbol-1.ld b/ld/testsuite/ld-elf/extract-symbol-1.ld new file mode 100644 index 000000000000..53e95c6d09d5 --- /dev/null +++ b/ld/testsuite/ld-elf/extract-symbol-1.ld @@ -0,0 +1,18 @@ +ENTRY(_entry) +PHDRS +{ + data PT_LOAD AT (0); +} +SECTIONS +{ + . = 0x10000; + .foo : { *(.foo) } :data + + . = 0x20000; + .bar : { *(.bar) } :data + + /DISCARD/ : { *(*) } + + _entry = 0x30000; + linker_symbol = 0x40000; +} diff --git a/ld/testsuite/ld-elf/extract-symbol-1.s b/ld/testsuite/ld-elf/extract-symbol-1.s new file mode 100644 index 000000000000..0971500413f9 --- /dev/null +++ b/ld/testsuite/ld-elf/extract-symbol-1.s @@ -0,0 +1,15 @@ + .globl B + .globl C + + .section .foo,"awx",%progbits + .4byte 1,2,3,4 +B: + .4byte 5,6,7 + + .section .bar,"ax",%nobits + .space 0x123 +C: + .space 0x302 + + .globl D + .equ D,0x12345678 diff --git a/ld/testsuite/ld-elf/extract-symbol-1sec.d b/ld/testsuite/ld-elf/extract-symbol-1sec.d new file mode 100644 index 000000000000..6891abcec262 --- /dev/null +++ b/ld/testsuite/ld-elf/extract-symbol-1sec.d @@ -0,0 +1,13 @@ +#name: --extract-symbol test 1 (sections) +#source: extract-symbol-1.s +#ld: -Textract-symbol-1.ld +#objcopy_linked_file: --extract-symbol +#objdump: --headers +#xfail: "hppa*-*-*" +#... +Sections: + *Idx +Name +Size +VMA +LMA .* + *0 +\.foo +0+ +0+ +0+ .* + *CONTENTS, ALLOC, LOAD, CODE + *1 +\.bar +0+ +0+ +0+ .* + *ALLOC, READONLY, CODE diff --git a/ld/testsuite/ld-elf/extract-symbol-1sym.d b/ld/testsuite/ld-elf/extract-symbol-1sym.d new file mode 100644 index 000000000000..f37293297329 --- /dev/null +++ b/ld/testsuite/ld-elf/extract-symbol-1sym.d @@ -0,0 +1,11 @@ +#name: --extract-symbol test 1 (symbols) +#source: extract-symbol-1.s +#ld: -Textract-symbol-1.ld +#objcopy_linked_file: --extract-symbol +#nm: -n +#xfail: "hppa*-*-*" +0*00010010 T B +0*00020123 T C +0*00030000 A _entry +0*00040000 A linker_symbol +0*12345678 A D diff --git a/ld/testsuite/ld-elf/foo.c b/ld/testsuite/ld-elf/foo.c new file mode 100644 index 000000000000..c84baee2e26a --- /dev/null +++ b/ld/testsuite/ld-elf/foo.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +void +foo (void) +{ + printf ("TEST2\n"); +} + +static void (*const init_array []) (void) + __attribute__ ((used, section (".init_array"), aligned (sizeof (void *)))) + = { foo }; diff --git a/ld/testsuite/ld-elf/foo.map b/ld/testsuite/ld-elf/foo.map new file mode 100644 index 000000000000..6b993de75248 --- /dev/null +++ b/ld/testsuite/ld-elf/foo.map @@ -0,0 +1,4 @@ +FOO { + global: foo; + local: *; +}; diff --git a/ld/testsuite/ld-elf/group.ld b/ld/testsuite/ld-elf/group.ld index d6b27d04946e..58d78dab942a 100644 --- a/ld/testsuite/ld-elf/group.ld +++ b/ld/testsuite/ld-elf/group.ld @@ -1,5 +1,6 @@ SECTIONS { . = 0x1000; - .text : { *(.text) } + .text : { *(.text) *(.rodata.brlt) } + /DISCARD/ : { *(.reginfo) } } diff --git a/ld/testsuite/ld-elf/group3a.d b/ld/testsuite/ld-elf/group3a.d new file mode 100644 index 000000000000..83c516134d32 --- /dev/null +++ b/ld/testsuite/ld-elf/group3a.d @@ -0,0 +1,8 @@ +#source: group3a.s +#source: group3b.s +#ld: -T group.ld +#readelf: -s +Symbol table '.symtab' contains .* entries: +#... + .*: 0[0]*1000 0 OBJECT GLOBAL HIDDEN . foo +#... diff --git a/ld/testsuite/ld-elf/group3a.s b/ld/testsuite/ld-elf/group3a.s new file mode 100644 index 000000000000..5e6a68648cb4 --- /dev/null +++ b/ld/testsuite/ld-elf/group3a.s @@ -0,0 +1,5 @@ + .section .data,"awG",%progbits,foo_group,comdat + .globl foo + .type foo,%object +foo: + .word 0 diff --git a/ld/testsuite/ld-elf/group3b.d b/ld/testsuite/ld-elf/group3b.d new file mode 100644 index 000000000000..82c18e4b4d90 --- /dev/null +++ b/ld/testsuite/ld-elf/group3b.d @@ -0,0 +1,8 @@ +#source: group3b.s +#source: group3a.s +#ld: -T group.ld +#readelf: -s +Symbol table '.symtab' contains .* entries: +#... + .*: 0[0]*1000 0 OBJECT GLOBAL HIDDEN . foo +#... diff --git a/ld/testsuite/ld-elf/group3b.s b/ld/testsuite/ld-elf/group3b.s new file mode 100644 index 000000000000..6c101bc52622 --- /dev/null +++ b/ld/testsuite/ld-elf/group3b.s @@ -0,0 +1,6 @@ + .section .data,"awG",%progbits,foo_group,comdat + .hidden foo + .globl foo + .type foo,%object +foo: + .word 0 diff --git a/ld/testsuite/ld-elf/hash.d b/ld/testsuite/ld-elf/hash.d new file mode 100644 index 000000000000..9c5a8f92096b --- /dev/null +++ b/ld/testsuite/ld-elf/hash.d @@ -0,0 +1,9 @@ +#source: start.s +#readelf: -d +#ld: -shared --hash-style=gnu +#target: *-*-linux* +#notarget: mips*-*-* + +#... +[ ]*0x[0-9a-z]+[ ]+\(GNU_HASH\)[ ]+0x[0-9a-z]+ +#... diff --git a/ld/testsuite/ld-elf/header.d b/ld/testsuite/ld-elf/header.d new file mode 100644 index 000000000000..d4388323ddda --- /dev/null +++ b/ld/testsuite/ld-elf/header.d @@ -0,0 +1,5 @@ +# target: *-*-linux* *-*-vxworks +# ld: -T header.t -z max-page-size=0x100 +# objdump: -hpw + +#... diff --git a/ld/testsuite/ld-elf/header.s b/ld/testsuite/ld-elf/header.s new file mode 100644 index 000000000000..38f22280e8e0 --- /dev/null +++ b/ld/testsuite/ld-elf/header.s @@ -0,0 +1,8 @@ + .text + .globl main +main: + .rept 0x40 - 0x15 + .long 0xfedcba98 + .endr + .data + .long 0x76543210 diff --git a/ld/testsuite/ld-elf/header.t b/ld/testsuite/ld-elf/header.t new file mode 100644 index 000000000000..c378fbe07e01 --- /dev/null +++ b/ld/testsuite/ld-elf/header.t @@ -0,0 +1,8 @@ +ENTRY(main) + +SECTIONS +{ + . = 0x100 + SIZEOF_HEADERS; + .text : { *(.text) } + .data : { *(.data) } +} diff --git a/ld/testsuite/ld-elf/hidden.out b/ld/testsuite/ld-elf/hidden.out new file mode 100644 index 000000000000..7ad7cbe39750 --- /dev/null +++ b/ld/testsuite/ld-elf/hidden.out @@ -0,0 +1,3 @@ +TEST2 +TEST1 +MAIN diff --git a/ld/testsuite/ld-elf/linkonce1.d b/ld/testsuite/ld-elf/linkonce1.d new file mode 100644 index 000000000000..35e1787f1816 --- /dev/null +++ b/ld/testsuite/ld-elf/linkonce1.d @@ -0,0 +1,12 @@ +#source: linkonce1a.s +#source: linkonce1b.s +#ld: -r +#objdump: -r + +.*: file format .* + +RELOCATION RECORDS FOR \[.debug_frame\]: +OFFSET[ ]+TYPE[ ]+VALUE[ ]* +.*(NONE|unused).*\*ABS\* + +#pass diff --git a/ld/testsuite/ld-elf/linkonce1a.s b/ld/testsuite/ld-elf/linkonce1a.s new file mode 100644 index 000000000000..5c2d8c25a3ab --- /dev/null +++ b/ld/testsuite/ld-elf/linkonce1a.s @@ -0,0 +1,3 @@ + .section .gnu.linkonce.d.dummy,"aw" +bar: + .long 0 diff --git a/ld/testsuite/ld-elf/linkonce1b.s b/ld/testsuite/ld-elf/linkonce1b.s new file mode 100644 index 000000000000..fd45cec54080 --- /dev/null +++ b/ld/testsuite/ld-elf/linkonce1b.s @@ -0,0 +1,17 @@ + .globl main + .globl start + .globl _start + .globl __start + .text +main: +start: +_start: +__start: + .long 0 + + .section .gnu.linkonce.d.dummy,"aw" + .long 0 +foo: + .long 0 + .section .debug_frame,"",%progbits + .long foo diff --git a/ld/testsuite/ld-elf/linkonce2.d b/ld/testsuite/ld-elf/linkonce2.d new file mode 100644 index 000000000000..33eb14fff0f3 --- /dev/null +++ b/ld/testsuite/ld-elf/linkonce2.d @@ -0,0 +1,12 @@ +#source: linkonce1a.s +#source: linkonce1b.s +#ld: -emit-relocs +#objdump: -r + +.*: file format .* + +RELOCATION RECORDS FOR \[.debug_frame\]: +OFFSET[ ]+TYPE[ ]+VALUE[ ]* +.*(NONE|unused).*\*ABS\* + +#pass diff --git a/ld/testsuite/ld-elf/loadaddr.s b/ld/testsuite/ld-elf/loadaddr.s new file mode 100644 index 000000000000..0a1416924281 --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr.s @@ -0,0 +1,20 @@ + .text + .globl main + .globl start + .globl _start + .globl __start +main: +start: +_start: +__start: + .byte 0,0,0,0,0,0,0,0 + .byte 0,0,0,0,0,0,0,0 + .section .bar,"ax","progbits" + .byte 0,0,0,0,0,0,0,0 + .byte 0,0,0,0,0,0,0,0 + .section .foo,"aw","progbits" + .byte 0,0,0,0,0,0,0,0 + .byte 0,0,0,0,0,0,0,0 + .data + .byte 0,0,0,0,0,0,0,0 + .byte 0,0,0,0,0,0,0,0 diff --git a/ld/testsuite/ld-elf/loadaddr1.d b/ld/testsuite/ld-elf/loadaddr1.d new file mode 100644 index 000000000000..31ac0ac0f287 --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr1.d @@ -0,0 +1,10 @@ +#source: loadaddr.s +#ld: -T loadaddr1.t -z max-page-size=0x200000 +#readelf: -l --wide +#target: *-*-linux* + +#... + LOAD +0x000000 0xf*80000000 0xf*80000000 0x100050 0x100050 RWE 0x200000 + LOAD +0x200000 0xf*ff600000 0xf*80101000 0x0*10 0x0*10 R E 0x200000 + LOAD +0x302000 0xf*80102000 0xf*80102000 0x0*10 0x0*10 RW 0x200000 +#pass diff --git a/ld/testsuite/ld-elf/loadaddr1.t b/ld/testsuite/ld-elf/loadaddr1.t new file mode 100644 index 000000000000..f28c7cbbcd63 --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr1.t @@ -0,0 +1,13 @@ +SECTIONS +{ + . = -0x7ff00000; + .text : {*(.text .text.*)} + . = ALIGN(64); + .foo : { *(.foo) } + .bar -0xa00000 : AT ((LOADADDR(.foo) + SIZEOF(.foo) + 4095) & ~(4095)) + { *(.bar) } + . = LOADADDR(.bar) + 4096; + . = ALIGN(8192); + .data : AT (ADDR(.data)) { *(.data) } + /DISCARD/ : { *(.*) } +} diff --git a/ld/testsuite/ld-elf/loadaddr2.d b/ld/testsuite/ld-elf/loadaddr2.d new file mode 100644 index 000000000000..2198b6ceb692 --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr2.d @@ -0,0 +1,10 @@ +#source: loadaddr.s +#ld: -T loadaddr2.t -z max-page-size=0x200000 +#readelf: -l --wide +#target: *-*-linux* + +#... + LOAD +0x000000 0xf*80000000 0xf*80000000 0x100050 0x100050 RWE 0x200000 + LOAD +0x110000 0xf*80110000 0xf*80101000 0x0*10 0x0*10 R E 0x200000 + LOAD +0x302000 0xf*80302000 0xf*80302000 0x0*10 0x0*10 RW 0x200000 +#pass diff --git a/ld/testsuite/ld-elf/loadaddr2.t b/ld/testsuite/ld-elf/loadaddr2.t new file mode 100644 index 000000000000..fd897e79d60d --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr2.t @@ -0,0 +1,13 @@ +SECTIONS +{ + . = -0x7ff00000; + .text : {*(.text .text.*)} + . = ALIGN(64); + .foo : { *(.foo) } + .bar -0x7fef0000 : AT ((LOADADDR(.foo) + SIZEOF(.foo) + 4095) & ~(4095)) + { *(.bar) } + . = LOADADDR(.bar) + 0x200000; + . = ALIGN(8192); + .data : AT (ADDR(.data)) { *(.data) } + /DISCARD/ : { *(.*) } +} diff --git a/ld/testsuite/ld-elf/loadaddr3.t b/ld/testsuite/ld-elf/loadaddr3.t new file mode 100644 index 000000000000..789f61eda1e4 --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr3.t @@ -0,0 +1,16 @@ + +MEMORY +{ + rom (rx) : ORIGIN = 0x100, LENGTH = 0x100 + ram (rwx) : ORIGIN = 0x200, LENGTH = 0x100 + +} + +SECTIONS +{ + .text : {*(.text .text.*)} >rom + .data : {data_load = LOADADDR (.data); + data_start = ADDR (.data); + *(.data .data.*)} >ram AT>rom + /DISCARD/ : { *(.*) } +} diff --git a/ld/testsuite/ld-elf/loadaddr3a.d b/ld/testsuite/ld-elf/loadaddr3a.d new file mode 100644 index 000000000000..b2ace667a929 --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr3a.d @@ -0,0 +1,9 @@ +#source: loadaddr.s +#ld: -T loadaddr3.t -z max-page-size=0x200000 +#readelf: -l --wide +#target: *-*-linux* + +#... + LOAD +0x000000 0x0*00000000 0x0*00000000 0x0*0110 0x0*0110 R E 0x.* + LOAD +0x000200 0x0*00000200 0x0*00000110 0x0*0010 0x0*0010 RW 0x.* +#pass diff --git a/ld/testsuite/ld-elf/loadaddr3b.d b/ld/testsuite/ld-elf/loadaddr3b.d new file mode 100644 index 000000000000..af7e6e4e07ea --- /dev/null +++ b/ld/testsuite/ld-elf/loadaddr3b.d @@ -0,0 +1,13 @@ +#source: loadaddr.s +#ld: -T loadaddr3.t -z max-page-size=0x200000 +#objdump: -t +#target: *-*-linux* + +#... +0+0000100 l d .text 0+0000000 .text +0+0000200 l d .data 0+0000000 .data +#... +0+0000110 g \*ABS\* 0+0000000 data_load +#... +0+0000200 g .data 0+0000000 data_start +#pass diff --git a/ld/testsuite/ld-elf/main.c b/ld/testsuite/ld-elf/main.c new file mode 100644 index 000000000000..24f9dcc86515 --- /dev/null +++ b/ld/testsuite/ld-elf/main.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int +main (void) +{ + printf ("MAIN\n"); + return 0; +} diff --git a/ld/testsuite/ld-elf/maxpage1.d b/ld/testsuite/ld-elf/maxpage1.d new file mode 100644 index 000000000000..57acda090a95 --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage1.d @@ -0,0 +1,9 @@ +#source: maxpage1.s +#ld: -z max-page-size=0x200000 +#readelf: -l --wide +#target: *-*-linux* + +#... + LOAD+.*0x200000 + LOAD+.*0x200000 +#pass diff --git a/ld/testsuite/ld-elf/maxpage1.s b/ld/testsuite/ld-elf/maxpage1.s new file mode 100644 index 000000000000..1a7735a8f2f5 --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage1.s @@ -0,0 +1,13 @@ + .globl main + .globl start + .globl _start + .globl __start + .text +main: +start: +_start: +__start: + .long 0 + + .data + .long 0 diff --git a/ld/testsuite/ld-elf/maxpage2.d b/ld/testsuite/ld-elf/maxpage2.d new file mode 100644 index 000000000000..7fe937988460 --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage2.d @@ -0,0 +1,9 @@ +#source: maxpage1.s +#ld: -z max-page-size=0x100000 +#readelf: -l --wide +#target: *-*-linux* + +#... + LOAD+.*0x100000 + LOAD+.*0x100000 +#pass diff --git a/ld/testsuite/ld-elf/maxpage3.t b/ld/testsuite/ld-elf/maxpage3.t new file mode 100644 index 000000000000..556dcd533c8a --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage3.t @@ -0,0 +1,7 @@ +SECTIONS +{ + .text : {*(.text)} + . = ALIGN(CONSTANT (MAXPAGESIZE)); + .data : {*(.data)} + /DISCARD/ : {*(*)} +} diff --git a/ld/testsuite/ld-elf/maxpage3a.d b/ld/testsuite/ld-elf/maxpage3a.d new file mode 100644 index 000000000000..0e46b6bb3e8c --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage3a.d @@ -0,0 +1,11 @@ +#source: maxpage1.s +#ld: -z max-page-size=0x10000000 -T maxpage3.t +#readelf: -lS --wide +#target: *-*-linux* + +#... + \[[ 0-9]+\] \.data[ \t]+PROGBITS[ \t]+0*10000000[ \t]+[ \t0-9a-f]+WA?.* +#... + LOAD+.*0x10000000 + LOAD+.*0x10000000 +#pass diff --git a/ld/testsuite/ld-elf/maxpage3b.d b/ld/testsuite/ld-elf/maxpage3b.d new file mode 100644 index 000000000000..4bee0ec447c6 --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage3b.d @@ -0,0 +1,10 @@ +#source: maxpage1.s +#ld: -T maxpage3.t -z max-page-size=0x10000000 +#readelf: -lS --wide +#target: x86_64-*-linux* + +#... + \[[ 0-9]+\] \.data[ \t]+PROGBITS[ \t]+0*200000[ \t]+[ \t0-9a-f]+WA?.* +#... + LOAD+.*0x10000000 +#pass diff --git a/ld/testsuite/ld-elf/maxpage3c.d b/ld/testsuite/ld-elf/maxpage3c.d new file mode 100644 index 000000000000..cdc3eaffe541 --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage3c.d @@ -0,0 +1,12 @@ +#source: maxpage1.s +#as: --32 +#ld: -m elf_i386 -z max-page-size=0x10000000 -T maxpage3.t +#readelf: -lS --wide +#target: x86_64-*-linux* + +#... + \[[ 0-9]+\] \.data[ \t]+PROGBITS[ \t]+0*10000000[ \t]+[ \t0-9a-f]+WA?.* +#... + LOAD+.*0x10000000 + LOAD+.*0x10000000 +#pass diff --git a/ld/testsuite/ld-elf/merge.d b/ld/testsuite/ld-elf/merge.d index 12b8458630c3..bc5a7b2b4bc6 100644 --- a/ld/testsuite/ld-elf/merge.d +++ b/ld/testsuite/ld-elf/merge.d @@ -2,7 +2,7 @@ #ld: -T merge.ld #objdump: -s #xfail: "arc-*-*" "avr-*-*" "bfin-*-*" "cris*-*-*" "crx-*-*" "d10v-*-*" "d30v-*-*" -#xfail: "dlx-*-*" "fr30-*-*" "frv-*-*" "hppa*-*-*" "h8300-*-*" +#xfail: "dlx-*-*" "fr30-*-*" "frv-*-*" "hppa*-*-*" "h8300-*-*" "score-*-*" #xfail: "i370-*-*" "i860-*-*" "i960-*-*" "ip2k-*-*" "iq2000-*-*" #xfail: "mcore-*-*" "mn102*-*-*" "mips*-*-*" "ms1-*-*" "msp430-*-*" #xfail: "or32-*-*" "pj-*-*" "sparc*-*-*" "vax-*-*" "xstormy16-*-*" "xtensa-*-*" diff --git a/ld/testsuite/ld-elf/multibss1.d b/ld/testsuite/ld-elf/multibss1.d new file mode 100644 index 000000000000..8074fe3347f1 --- /dev/null +++ b/ld/testsuite/ld-elf/multibss1.d @@ -0,0 +1,9 @@ +#source: multibss1.s +#ld: -e 0 +#readelf: -l --wide +#target: *-*-linux* + +#... + +LOAD +0x[^ ]+ +0x[^ ]+ +0x[^ ]+ +0x[^ ]+ +0x500000 .* +# p_offset p_vaddr p_paddr p_filesz +#pass diff --git a/ld/testsuite/ld-elf/multibss1.s b/ld/testsuite/ld-elf/multibss1.s new file mode 100644 index 000000000000..94b84f994621 --- /dev/null +++ b/ld/testsuite/ld-elf/multibss1.s @@ -0,0 +1,11 @@ + .macro makebss + .section .bss_\@,"aw",%nobits + .space 0x10000 + .endm + + .rept 80 + makebss + .endr + + .text + .space 0x10 diff --git a/ld/testsuite/ld-elf/new.cc b/ld/testsuite/ld-elf/new.cc new file mode 100644 index 000000000000..b4c888247e09 --- /dev/null +++ b/ld/testsuite/ld-elf/new.cc @@ -0,0 +1,48 @@ +#include <new> +#include <exception_defines.h> + +using std::bad_alloc; + +extern "C" void *malloc (std::size_t); +extern "C" void abort (void); + +void * +operator new (std::size_t sz, const std::nothrow_t&) throw() +{ + void *p; + + /* malloc (0) is unpredictable; avoid it. */ + if (sz == 0) + sz = 1; + p = (void *) malloc (sz); + return p; +} + +void * +operator new (std::size_t sz) throw (std::bad_alloc) +{ + void *p; + + /* malloc (0) is unpredictable; avoid it. */ + if (sz == 0) + sz = 1; + p = (void *) malloc (sz); + while (p == 0) + { + ::abort(); + } + + return p; +} + +void* +operator new[] (std::size_t sz) throw (std::bad_alloc) +{ + return ::operator new(sz); +} + +void * +operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw() +{ + return ::operator new(sz, nothrow); +} diff --git a/ld/testsuite/ld-elf/nobits-1.d b/ld/testsuite/ld-elf/nobits-1.d new file mode 100644 index 000000000000..9b90b6f76afb --- /dev/null +++ b/ld/testsuite/ld-elf/nobits-1.d @@ -0,0 +1,7 @@ +#ld: -Tnobits-1.t +#readelf: -l --wide + +#... + Section to Segment mapping: + Segment Sections... + 00 .foo .bar diff --git a/ld/testsuite/ld-elf/nobits-1.s b/ld/testsuite/ld-elf/nobits-1.s new file mode 100644 index 000000000000..8fb1365c7100 --- /dev/null +++ b/ld/testsuite/ld-elf/nobits-1.s @@ -0,0 +1,6 @@ + .globl _entry + .section .foo,"awx",%progbits +_entry: + .byte 0 + .section .bar,"ax",%nobits + .byte 0 diff --git a/ld/testsuite/ld-elf/nobits-1.t b/ld/testsuite/ld-elf/nobits-1.t new file mode 100644 index 000000000000..200433058b39 --- /dev/null +++ b/ld/testsuite/ld-elf/nobits-1.t @@ -0,0 +1,13 @@ +ENTRY(_entry) +PHDRS +{ + data PT_LOAD; +} +SECTIONS +{ + . = 0x1000000; + .foo : { *(.foo) } :data + . = 0x2000000; + .bar : { *(.bar) } :data + /DISCARD/ : { *(*) } +} diff --git a/ld/testsuite/ld-elf/noload-1.d b/ld/testsuite/ld-elf/noload-1.d new file mode 100644 index 000000000000..7cae479a0710 --- /dev/null +++ b/ld/testsuite/ld-elf/noload-1.d @@ -0,0 +1,7 @@ +#source: noload-1.s +#ld: -T noload-1.t +#readelf: -S --wide + +#... + \[[ 0-9]+\] TEST[ \t]+NOBITS[ \t0-9a-f]+WA.* +#pass diff --git a/ld/testsuite/ld-elf/noload-1.s b/ld/testsuite/ld-elf/noload-1.s new file mode 100644 index 000000000000..ad0479e0e47e --- /dev/null +++ b/ld/testsuite/ld-elf/noload-1.s @@ -0,0 +1,2 @@ + .section TEST,"aw",%progbits + .byte 0 diff --git a/ld/testsuite/ld-elf/noload-1.t b/ld/testsuite/ld-elf/noload-1.t new file mode 100644 index 000000000000..1efd06c2e11c --- /dev/null +++ b/ld/testsuite/ld-elf/noload-1.t @@ -0,0 +1,8 @@ +SECTIONS +{ + TEST (NOLOAD) : + { + *(TEST) + } + /DISCARD/ : { *(.*) } +} diff --git a/ld/testsuite/ld-elf/noload-2.d b/ld/testsuite/ld-elf/noload-2.d new file mode 100644 index 000000000000..633bf4563830 --- /dev/null +++ b/ld/testsuite/ld-elf/noload-2.d @@ -0,0 +1,8 @@ +#source: noload-1.s +#ld: -T noload-1.t -z max-page-size=0x200000 +#readelf: -Sl --wide +#target: *-*-linux* + +#... + +LOAD +0x200000 +0x0+ +0x0+ +0x0+ +0x0+1 +RW +0x200000 +#pass diff --git a/ld/testsuite/ld-elf/normal.out b/ld/testsuite/ld-elf/normal.out new file mode 100644 index 000000000000..3b721f066560 --- /dev/null +++ b/ld/testsuite/ld-elf/normal.out @@ -0,0 +1,3 @@ +TEST1 +TEST1 +MAIN diff --git a/ld/testsuite/ld-elf/note-1.d b/ld/testsuite/ld-elf/note-1.d new file mode 100644 index 000000000000..a5fc40f2e697 --- /dev/null +++ b/ld/testsuite/ld-elf/note-1.d @@ -0,0 +1,8 @@ +#ld: -Tnote-1.t +#readelf: -l --wide + +#... + Section to Segment mapping: + Segment Sections... + 00 .foo + 01 .note diff --git a/ld/testsuite/ld-elf/note-1.s b/ld/testsuite/ld-elf/note-1.s new file mode 100644 index 000000000000..844188bb5c59 --- /dev/null +++ b/ld/testsuite/ld-elf/note-1.s @@ -0,0 +1,6 @@ + .globl _entry + .section .foo,"awx",%progbits +_entry: + .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .section .note,"",%note + .byte 0 diff --git a/ld/testsuite/ld-elf/note-1.t b/ld/testsuite/ld-elf/note-1.t new file mode 100644 index 000000000000..031fe820ead6 --- /dev/null +++ b/ld/testsuite/ld-elf/note-1.t @@ -0,0 +1,14 @@ +ENTRY(_entry) +PHDRS +{ + data PT_LOAD; + note PT_NOTE; +} +SECTIONS +{ + . = 0x1000000; + .foo : { *(.foo) } :data + . = 0x2000000; + .note : { *(.note) } :note + /DISCARD/ : { *(*) } +} diff --git a/ld/testsuite/ld-elf/orphan.d b/ld/testsuite/ld-elf/orphan.d index 04d935c11e5c..54d10df4cdaa 100644 --- a/ld/testsuite/ld-elf/orphan.d +++ b/ld/testsuite/ld-elf/orphan.d @@ -4,6 +4,7 @@ #... \[[ 0-9]+\] \.(text|notbad)[ \t]+PROGBITS[ \t0-9a-f]+AX?.* +#... \[[ 0-9]+\] \.(text|notbad)[ \t]+PROGBITS[ \t0-9a-f]+AX?.* \[[ 0-9]+\] \.data[ \t]+PROGBITS[ \t0-9a-f]+WA.* #... diff --git a/ld/testsuite/ld-elf/orphan2.d b/ld/testsuite/ld-elf/orphan2.d index 867a4a9261c8..a82e72177534 100644 --- a/ld/testsuite/ld-elf/orphan2.d +++ b/ld/testsuite/ld-elf/orphan2.d @@ -4,5 +4,6 @@ #... \[[ 0-9]+\] \.text[ \t]+PROGBITS[ \t0-9a-f]+AX?.* +#... \[[ 0-9]+\] \.modinfo[ \t]+PROGBITS[ \t0-9a-f]+A.* #pass diff --git a/ld/testsuite/ld-elf/overlay.d b/ld/testsuite/ld-elf/overlay.d new file mode 100644 index 000000000000..00d25d5e2046 --- /dev/null +++ b/ld/testsuite/ld-elf/overlay.d @@ -0,0 +1,12 @@ +# ld: -T overlay.t -u __load_start_text1 -u __load_start_text2 -u __load_stop_text1 -u __load_stop_text2 +#readelf: -s + +#... +[ ]+[0-9]+:[ ]+0*4000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+ABS __load_start_text1 +#... +[ ]+[0-9]+:[ ]+0*4010[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+ABS __load_start_text2 +#... +[ ]+[0-9]+:[ ]+0*4030[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+ABS __load_stop_text2 +#... +[ ]+[0-9]+:[ ]+0*4010[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+ABS __load_stop_text1 +#pass diff --git a/ld/testsuite/ld-elf/overlay.s b/ld/testsuite/ld-elf/overlay.s new file mode 100644 index 000000000000..f153044e31b6 --- /dev/null +++ b/ld/testsuite/ld-elf/overlay.s @@ -0,0 +1,6 @@ + .section .text1,"ax",%progbits + .space 0x10 + .section .text2,"ax",%progbits + .space 0x20 + .text + .space 0x30 diff --git a/ld/testsuite/ld-elf/overlay.t b/ld/testsuite/ld-elf/overlay.t new file mode 100644 index 000000000000..bdb33c815cac --- /dev/null +++ b/ld/testsuite/ld-elf/overlay.t @@ -0,0 +1,10 @@ +SECTIONS +{ + .text : { *(.text) } + OVERLAY 0x1000 : AT (0x4000) + { + .text1 {*(.text1)} + .text2 {*(.text2)} + } + /DISCARD/ : { *(.*) } +} diff --git a/ld/testsuite/ld-elf/pass.out b/ld/testsuite/ld-elf/pass.out new file mode 100644 index 000000000000..7ef22e9a431a --- /dev/null +++ b/ld/testsuite/ld-elf/pass.out @@ -0,0 +1 @@ +PASS diff --git a/ld/testsuite/ld-elf/sec64k.exp b/ld/testsuite/ld-elf/sec64k.exp index bd66c1c5701d..cbf6e4667a12 100644 --- a/ld/testsuite/ld-elf/sec64k.exp +++ b/ld/testsuite/ld-elf/sec64k.exp @@ -1,5 +1,5 @@ # Expect script for tests for >64k sections -# Copyright 2002, 2003 Free Software Foundation, Inc. +# Copyright 2002, 2003, 2006 Free Software Foundation, Inc. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -50,12 +50,16 @@ for { set i 0 } { $i < $max_sec / $secs_per_file } { incr i } { } if { $i == 0 } { + puts $ofd " .global start" + puts $ofd "start:" puts $ofd " .global _start" - puts $ofd " .global __start" puts $ofd "_start:" + puts $ofd " .global __start" puts $ofd "__start:" + puts $ofd " .global main" + puts $ofd "main:" puts $ofd " .global foo_0" - puts $ofd "foo_0: .long 0" + puts $ofd "foo_0: .dc.a 0" } # Make sure the used section is not covered by common linker scripts. @@ -65,9 +69,9 @@ for { set i 0 } { $i < $max_sec / $secs_per_file } { incr i } { puts $ofd " .section .foo.\\secn,\"ax\"" puts $ofd " .global foo_\\secn" puts $ofd "foo_\\secn:" - puts $ofd " .long foo_\\secp" + puts $ofd " .dc.a foo_\\secp" puts $ofd "bar_\\secn:" - puts $ofd " .long bar_\\secn" + puts $ofd " .dc.a bar_\\secn" puts $ofd " .endm" puts $ofd " secn = [expr $i * $secs_per_file]" puts $ofd " .rept $secs_per_file" @@ -87,35 +91,41 @@ if [catch { set ofd [open "tmpdir/$test1.d" w] } x] { # The ld-r linked file will contain relocation-sections too, so make it # half the size in order to try and keep the test-time down. -foreach sfile [lrange $sfiles 0 [expr [llength $sfiles] / 2]] { - puts $ofd "#source: $sfile" + +# The m32r target generates both REL and RELA relocs (for historical +# reasons) so the expected number of sections will be much more than +# 68000, which throws this particular test right off. +if {![istarget "m32r-*-*"]} then { + foreach sfile [lrange $sfiles 0 [expr [llength $sfiles] / 2]] { + puts $ofd "#source: $sfile" + } + puts $ofd "#ld: -r" + puts $ofd "#readelf: -W -Ss" + puts $ofd "There are 680.. section headers.*:" + puts $ofd "#..." + puts $ofd " \\\[ 0\\\] .* 682\[0-9\]\[0-9\]\[ \]+0\[ \]+0" + puts $ofd "#..." + puts $ofd " \\\[ \[0-9\]\\\] \.foo\.1\[ \]+PROGBITS\[ \]+.*" + puts $ofd "#..." + puts $ofd " \\\[65279\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*" + puts $ofd " \\\[65536\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*" + puts $ofd "#..." + puts $ofd " 340..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... " + puts $ofd "#..." + puts $ofd " 340..: 0+(2|4|8)\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[23\] bar_1$" + puts $ofd "#..." + puts $ofd ".* bar_34000$" + puts $ofd "#..." + # Global symbols are not in "alphanumeric" order, so we just check + # that the first and the last are present in any order (assuming no + # duplicates). + puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)$" + puts $ofd "#..." + puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)$" + puts $ofd "#pass" + close $ofd + run_dump_test "tmpdir/$test1" } -puts $ofd "#ld: -r" -puts $ofd "#readelf: -W -Ss" -puts $ofd "There are 680.. section headers.*:" -puts $ofd "#..." -puts $ofd " \\\[ 0\\\] .* 682\[0-9\]\[0-9\]\[ \]+0\[ \]+0" -puts $ofd "#..." -puts $ofd " \\\[ \[0-9\]\\\] \.foo\.1\[ \]+PROGBITS\[ \]+.*" -puts $ofd "#..." -puts $ofd " \\\[65279\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*" -puts $ofd " \\\[65536\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*" -puts $ofd "#..." -puts $ofd " 680..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... " -puts $ofd "#..." -puts $ofd " 680..: 0+4\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[23\] bar_1" -puts $ofd "#..." -puts $ofd ".* bar_34000" -puts $ofd "#..." -# Global symbols are not in "alphanumeric" order, so we just check -# that the first and the last are present in any order (assuming no -# duplicates). -puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)" -puts $ofd "#..." -puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)" -puts $ofd "#pass" -close $ofd -run_dump_test "tmpdir/$test1" if [catch { set ofd [open "tmpdir/$test2.d" w] } x] { perror "$x" @@ -123,7 +133,11 @@ if [catch { set ofd [open "tmpdir/$test2.d" w] } x] { return } foreach sfile $sfiles { puts $ofd "#source: $sfile" } -puts $ofd "#ld:" +if { [istarget spu*-*-*] } { + puts $ofd "#ld: --local-store 0:0" +} else { + puts $ofd "#ld:" +} puts $ofd "#readelf: -W -Ss" puts $ofd "There are 660.. section headers.*:" puts $ofd "#..." @@ -132,18 +146,18 @@ puts $ofd "#..." puts $ofd " \\\[65279\\\] \\.foo\\.\[0-9\]+ .*" puts $ofd " \\\[65536\\\] \\.foo\\.\[0-9\]+ .*" puts $ofd "#..." -puts $ofd " 660..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+662.. " +puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+662.. " puts $ofd "#..." -puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[0-9\] bar_1" +puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[0-9\] bar_1$" puts $ofd "#..." -puts $ofd ".* bar_66000" +puts $ofd ".* bar_66000$" puts $ofd "#..." # Global symbols are not in "alphanumeric" order, so we just check # that the first and the last are present in any order (assuming no # duplicates). -puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)" +puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)$" puts $ofd "#..." -puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)" +puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)$" puts $ofd "#pass" close $ofd run_dump_test "tmpdir/$test2" diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp new file mode 100644 index 000000000000..c8e0a18c4f5c --- /dev/null +++ b/ld/testsuite/ld-elf/shared.exp @@ -0,0 +1,283 @@ +# Expect script for various ELF tests. +# Copyright 2006 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. +# + +# Exclude non-ELF targets. + +if ![is_elf_format] { + return +} + +# The following tests require running the executable generated by ld. +if ![isnative] { + return +} + +# Check if compiler works +if { [which $CC] == 0 } { + return +} + +set build_tests { + {"Build libfoo.so" + "-shared" "-fPIC" + {foo.c} {} "libfoo.so"} + {"Build versioned libfoo.so" + "-shared -Wl,--version-script=foo.map" "-fPIC" + {foo.c} {} "libfoov.so"} + {"Build libbar.so" + "-shared" "-fPIC" + {begin.c end.c} {} "libbar.so"} + {"Build warn libbar.so" + "-shared" "-fPIC" + {beginwarn.c end.c} {} "libbarw.so"} + {"Build hidden libbar.so" + "-shared" "-fPIC" + {begin.c endhidden.c} {} "libbarh.so"} + {"Build protected libbar.so" + "-shared" "-fPIC" + {begin.c endprotected.c} {} "libbarp.so"} + {"Build libbar.so with libfoo.so" + "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" + {end.c} {} "libbarfoo.so"} + {"Build libar.so with versioned libfoo.so" + "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" + {end.c} {} "libbarfoov.so"} + {"Build hidden libbar.so with libfoo.so" + "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" + {endhidden.c} {} "libbarhfoo.so"} + {"Build hidden libar.so with versioned libfoo.so" + "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" + {endhidden.c} {} "libbarhfoov.so"} + {"Build protected libbar.so with libfoo.so" + "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" + {endprotected.c} {} "libbarpfoo.so"} + {"Build protected libbar.so with versioned libfoo.so" + "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" + {endprotected.c} {} "libbarpfoov.so"} + {"Build libdl1.so" + "-shared" "-fPIC" + {dl1.c} {} "libdl1.so"} + {"Build libdl2a.so with --dynamic-list=dl2.list" + "-shared -Wl,--dynamic-list=dl2.list" "-fPIC" + {dl2.c dl2xxx.c} {} "libdl2a.so"} + {"Build libdl2a.so with --dynamic-list=dl2a.list" + "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC" + {dl2.c dl2xxx.c} {} "libdl2a.so"} + {"Build libdl2a.so with --dynamic-list-data" + "-shared -Wl,--dynamic-list-data" "-fPIC" + {dl2.c dl2xxx.c} {} "libdl2a.so"} + {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list" + "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC" + {dl2.c dl2xxx.c} {} "libdl2b.so"} + {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list" + "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC" + {dl2.c dl2xxx.c} {} "libdl2c.so"} + {"Build libdl4a.so with --dynamic-list=dl4.list" + "-shared -Wl,--dynamic-list=dl4.list" "-fPIC" + {dl4.c dl4xxx.c} {} "libdl4a.so"} + {"Build libdl4b.so with --dynamic-list-data" + "-shared -Wl,--dynamic-list-data" "-fPIC" + {dl4.c dl4xxx.c} {} "libdl4b.so"} + {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list" + "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC" + {dl4.c dl4xxx.c} {} "libdl4c.so"} + {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list" + "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC" + {dl4.c dl4xxx.c} {} "libdl4d.so"} + {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new" + "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC" + {dl4.c dl4xxx.c} {} "libdl4e.so"} + {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions" + "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC" + {dl4.c dl4xxx.c} {} "libdl4f.so"} + {"Build libdl6a.so" + "-shared" "-fPIC" + {dl6.c} {} "libdl6a.so"} + {"Build libdl6b.so with -Bsymbolic --dynamic-list-data" + "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC" + {dl6.c} {} "libdl6b.so"} + {"Build libdl6c.so with -Bsymbolic" + "-shared -Wl,-Bsymbolic" "-fPIC" + {dl6.c} {} "libdl6c.so"} + {"Build libdl6d.so with --dynamic-list-data -Bsymbolic" + "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC" + {dl6.c} {} "libdl6d.so"} + {"Build libdata1.so" + "-shared" "-fPIC" + {data1.c} {} "libdata1.so"} +} + +set run_tests { + {"Run normal with libfoo.so" + "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" + {main.c} "normal" "normal.out"} + {"Run protected with libfoo.so" + "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" + {main.c} "protected" "normal.out"} + {"Run hidden with libfoo.so" + "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" + {main.c} "hidden" "hidden.out"} + {"Run normal with versioned libfoo.so" + "tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" + {main.c} "normalv" "normal.out"} + {"Run warn with versioned libfoo.so" + "tmpdir/beginwarn.o tmpdir/libfoov.so" "" + {main.c} "warn" "warn.out" + "" "" "^.*\\\): warning: function foo is deprecated$"} + {"Run protected with versioned libfoo.so" + "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" + {main.c} "protected" "normal.out"} + {"Run hidden with versioned libfoo.so" + "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" + {main.c} "hiddenv" "hidden.out"} + {"Run normal libbar.so with libfoo.so" + "tmpdir/libbarfoo.so tmpdir/libfoo.so" "" + {main.c} "normal" "normal.out"} + {"Run protected libbar.so with libfoo.so" + "tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" + {main.c} "protected" "normal.out"} + {"Run hidden libbar.so with libfoo.so" + "tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" + {main.c} "hidden" "hidden.out"} + {"Run normal libbar.so with versioned libfoo.so" + "tmpdir/libbarfoov.so tmpdir/libfoov.so" "" + {main.c} "normal" "normal.out"} + {"Run protected libbar.so with versioned libfoo.so" + "tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" + {main.c} "protected" "normal.out"} + {"Run hidden libbar.so with versioned libfoo.so" + "tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" + {main.c} "hidden" "hidden.out"} + {"Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" + "--dynamic-list=dl1.list -ldl" "" + {dl1main.c} "dl1a" "dl1.out"} + {"Run dl1b with --dynamic-list-data and dlopen on libdl1.so" + "--dynamic-list-data -ldl" "" + {dl1main.c} "dl1b" "dl1.out"} + {"Run with libdl2a.so" + "tmpdir/libdl2a.so" "" + {dl2main.c} "dl2a" "dl2a.out"} + {"Run with libdl2b.so" + "tmpdir/libdl2b.so" "" + {dl2main.c} "dl2b" "dl2b.out"} + {"Run with libdl2c.so" + "tmpdir/libdl2c.so" "" + {dl2main.c} "dl2c" "dl2b.out"} + {"Run with libdl4a.so" + "tmpdir/libdl4a.so" "" + {dl4main.c} "dl4a" "dl4a.out"} + {"Run with libdl4b.so" + "tmpdir/libdl4b.so" "" + {dl4main.c} "dl4b" "dl4a.out"} + {"Run with libdl4c.so" + "tmpdir/libdl4c.so" "" + {dl4main.c} "dl4c" "dl4b.out"} + {"Run with libdl4d.so" + "tmpdir/libdl4d.so" "" + {dl4main.c} "dl4d" "dl4b.out"} + {"Run with libdl4e.so" + "tmpdir/libdl4e.so" "" + {dl4main.c} "dl4e" "dl4a.out"} + {"Run with libdl4f.so" + "tmpdir/libdl4f.so" "" + {dl4main.c} "dl4f" "dl4a.out"} + {"Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" + "--dynamic-list-data -ldl" "" + {dl6amain.c} "dl6a1" "dl6a.out"} + {"Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" + "-Bsymbolic-functions -ldl" "" + {dl6amain.c} "dl6a2" "dl6b.out"} + {"Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" + "-Bsymbolic -ldl" "" + {dl6amain.c} "dl6a3" "dl6b.out"} + {"Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" + "-Bsymbolic --dynamic-list-data -ldl" "" + {dl6amain.c} "dl6a4" "dl6a.out"} + {"Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" + "-Bsymbolic-functions --dynamic-list-cpp-new -ldl" "" + {dl6amain.c} "dl6a5" "dl6b.out"} + {"Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" + "--dynamic-list-cpp-new -Bsymbolic-functions -ldl" "" + {dl6amain.c} "dl6a6" "dl6b.out"} + {"Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" + "--dynamic-list-data -Bsymbolic -ldl" "" + {dl6amain.c} "dl6a7" "dl6a.out"} + {"Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" + "--dynamic-list-data -ldl" "" + {dl6bmain.c} "dl6b1" "dl6a.out"} + {"Run dl6b2 with dlopen on libdl6b.so" + "-ldl" "" + {dl6bmain.c} "dl6b2" "dl6b.out"} + {"Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" + "--dynamic-list-data -ldl" "" + {dl6cmain.c} "dl6c1" "dl6b.out"} + {"Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" + "--dynamic-list-data -ldl" "" + {dl6dmain.c} "dl6d1" "dl6b.out"} + {"Run with libdata1.so" + "tmpdir/libdata1.so" "" + {dynbss1.c} "dynbss1" "pass.out"} +} + +run_cc_link_tests $build_tests +# NetBSD ELF systems do not currently support the .*_array sections. +run_ld_link_exec_tests [list "*-*-netbsdelf*"] $run_tests + +# Check if compiler works +if { [which $CXX] == 0 } { + return +} + +set build_cxx_tests { + {"Build libdl3a.so with --dynamic-list=dl3.list" + "-shared -Wl,--dynamic-list=dl3.list" "-fPIC" + {dl3.cc} {} "libdl3a.so" "c++"} + {"Build libdl3b.so with -Bsymbolic" + "-shared -Wl,-Bsymbolic" "-fPIC" + {dl3.cc} {} "libdl3b.so" "c++"} + {"Build libdl3a.so with --dynamic-list-cpp-typeinfo" + "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC" + {dl3.cc} {} "libdl3c.so" "c++"} + {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new" + "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC" + {del.cc new.cc} {} "libnew1a.so" "c++"} + {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new" + "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC" + {del.cc new.cc} {} "libnew1b.so" "c++"} +} + +set run_cxx_tests { + {"Run with libdl3a.so" + "tmpdir/libdl3a.so" "" + {dl3main.cc} "dl3a" "dl3a.out" "" "c++"} + {"Run with libdl3b.so" + "tmpdir/libdl3b.so" "" + {dl3main.cc} "dl3b" "dl3b.out" "" "c++"} + {"Run with libdl3c.so" + "tmpdir/libdl3c.so" "" + {dl3main.cc} "dl3c" "dl3a.out" "" "c++"} + {"Run with libnew1a.so" + "tmpdir/libnew1a.so" "" + {dl5.cc} "dl5a" "dl5.out" "" "c++"} + {"Run with libnew1b.so" + "tmpdir/libnew1b.so" "" + {dl5.cc} "dl5b" "dl5.out" "" "c++"} +} + +run_cc_link_tests $build_cxx_tests +run_ld_link_exec_tests [] $run_cxx_tests diff --git a/ld/testsuite/ld-elf/stab.d b/ld/testsuite/ld-elf/stab.d new file mode 100644 index 000000000000..667623817d48 --- /dev/null +++ b/ld/testsuite/ld-elf/stab.d @@ -0,0 +1,11 @@ +#source: start.s +#as: -gstabs +#readelf: -S --wide +#ld: +#notarget: ia64-*-* + +#... + \[[0-9 ][0-9]\] \.stab +PROGBITS +0+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ +[1-9]+ +0.* +#... + \[[0-9 ][0-9]\] \.stabstr +STRTAB +0+ [0-9a-f]+ [0-9a-f]+ 00 +0 +0.* +#... diff --git a/ld/testsuite/ld-elf/start.s b/ld/testsuite/ld-elf/start.s index 9cbf231a3abd..d8655bef05cc 100644 --- a/ld/testsuite/ld-elf/start.s +++ b/ld/testsuite/ld-elf/start.s @@ -1,10 +1,10 @@ .text + .global start /* Used by SH targets. */ +start: .global _start _start: .global __start __start: - .global start /* Used by SH targets. */ -start: .global main /* Used by HPPA targets. */ main: - .long 0 + .dc.a 0 diff --git a/ld/testsuite/ld-elf/symbol1ref.s b/ld/testsuite/ld-elf/symbol1ref.s index 582e6ba12b79..15725cb1da9f 100644 --- a/ld/testsuite/ld-elf/symbol1ref.s +++ b/ld/testsuite/ld-elf/symbol1ref.s @@ -1,3 +1,3 @@ .text - .long symbol1 + .dc.a symbol1 diff --git a/ld/testsuite/ld-elf/symbol2ref.s b/ld/testsuite/ld-elf/symbol2ref.s new file mode 100644 index 000000000000..d2710f9c9a80 --- /dev/null +++ b/ld/testsuite/ld-elf/symbol2ref.s @@ -0,0 +1,3 @@ + .text + .dc.a Foo + diff --git a/ld/testsuite/ld-elf/symbol2w.s b/ld/testsuite/ld-elf/symbol2w.s new file mode 100644 index 000000000000..794a753c616e --- /dev/null +++ b/ld/testsuite/ld-elf/symbol2w.s @@ -0,0 +1,6 @@ + .section .gnu.warning,"a",%progbits + .global Foo + .type Foo, %object + .size Foo, 20 +Foo: + .string "function 'Foo' used" diff --git a/ld/testsuite/ld-elf/tbss1.s b/ld/testsuite/ld-elf/tbss1.s new file mode 100644 index 000000000000..4f1631f2dc67 --- /dev/null +++ b/ld/testsuite/ld-elf/tbss1.s @@ -0,0 +1,24 @@ + .globl main + .globl start + .globl _start + .globl __start + .text +main: +start: +_start: +__start: + .byte 0 + .globl bss + .section .bss,"aw",%nobits + .p2align 12 + .type bss,%object + .size bss,4096 +bss: + .zero 4096 + .globl tbss + .section .tbss,"awT",%nobits + .p2align 12 + .type tbss,%object + .size tbss,4096 +tbss: + .zero 4096 diff --git a/ld/testsuite/ld-elf/tbss2.s b/ld/testsuite/ld-elf/tbss2.s new file mode 100644 index 000000000000..b9809258e26c --- /dev/null +++ b/ld/testsuite/ld-elf/tbss2.s @@ -0,0 +1,16 @@ + .globl main + .globl start + .globl _start + .globl __start + .text +main: +start: +_start: +__start: + .byte 0 + .globl tbss + .section .tbss,"awT",%nobits + .type tbss,%object + .size tbss,1 +tbss: + .zero 1 diff --git a/ld/testsuite/ld-elf/tdata1.s b/ld/testsuite/ld-elf/tdata1.s new file mode 100644 index 000000000000..6ea57b661f16 --- /dev/null +++ b/ld/testsuite/ld-elf/tdata1.s @@ -0,0 +1,24 @@ + .globl main + .globl start + .globl _start + .globl __start + .text +main: +start: +_start: +__start: + .byte 0 + .globl data + .section .data,"aw",%progbits + .p2align 4 + .type data,%object + .size data,4096 +data: + .zero 4096 + .globl tdata + .section .tdata,"awT",%progbits + .p2align 4 + .type tdata,%object + .size tdata,4096 +tdata: + .zero 4096 diff --git a/ld/testsuite/ld-elf/tdata2.s b/ld/testsuite/ld-elf/tdata2.s new file mode 100644 index 000000000000..1da459f96192 --- /dev/null +++ b/ld/testsuite/ld-elf/tdata2.s @@ -0,0 +1,16 @@ + .globl main + .globl start + .globl _start + .globl __start + .text +main: +start: +_start: +__start: + .byte 0 + .globl tdata + .section .tdata,"awT",%progbits + .type tdata,%object + .size tdata,1 +tdata: + .byte 0 diff --git a/ld/testsuite/ld-elf/tls_common.exp b/ld/testsuite/ld-elf/tls_common.exp new file mode 100644 index 000000000000..512689f167be --- /dev/null +++ b/ld/testsuite/ld-elf/tls_common.exp @@ -0,0 +1,70 @@ +# Expect script for .tls_common tests +# Copyright 2006 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. +# +# Written by Jakub Jelinek (jakub@redhat.com) +# + +# Make sure that binutils can correctly handle ld output in ELF. + +# Run on Linux only. +if { ![istarget *-*-linux*] } { + return +} + +if { [istarget *-*-linux*aout*] + || [istarget *-*-linux*oldld*] } { + return +} + +global as +global ld +global READELF +global srcdir +global subdir +global link_output + +if { ![ld_assemble $as $srcdir/$subdir/tls_common.s tmpdir/tls_common.o ] } { + unresolved "tls_common" + return +} + +if { ![ld_simple_link $ld tmpdir/tls_common1.o "-r tmpdir/tls_common.o"] } { + fail "tls_common" + return +} + +if { ![ld_simple_link $ld tmpdir/tls_common "tmpdir/tls_common1.o"] } { + if { [string match "*not supported*" $link_output] + || [string match "*unrecognized option*" $link_output] } { + unsupported "$ld_options is not supported by this target" + } elseif { [string match "*Warning*alignment*of common symbol*" $link_output] } { + fail "tls_common" + } else { + unresolved "tls_common" + } + return +} + +send_log "$READELF -l --wide tmpdir/tls_common\n" +catch "exec $READELF -l --wide tmpdir/tls_common" readelf_output +if ![regexp ".*TLS.*0x0+ 0x0+4 R .*" $readelf_output] then { + send_log "$readelf_output\n" + fail "tls_common" + return +} + +pass "tls_common" diff --git a/ld/testsuite/ld-elf/tls_common.s b/ld/testsuite/ld-elf/tls_common.s new file mode 100644 index 000000000000..502d8f3103a7 --- /dev/null +++ b/ld/testsuite/ld-elf/tls_common.s @@ -0,0 +1,11 @@ + .globl main + .globl start + .globl _start + .globl __start + .text +main: +start: +_start: +__start: + .byte 0 + .tls_common foo,4,4 diff --git a/ld/testsuite/ld-elf/warn.out b/ld/testsuite/ld-elf/warn.out new file mode 100644 index 000000000000..ba836ce87915 --- /dev/null +++ b/ld/testsuite/ld-elf/warn.out @@ -0,0 +1,3 @@ +TEST2 +TEST2 +MAIN diff --git a/ld/testsuite/ld-elf/warn2.d b/ld/testsuite/ld-elf/warn2.d new file mode 100644 index 000000000000..97d4f590d3f8 --- /dev/null +++ b/ld/testsuite/ld-elf/warn2.d @@ -0,0 +1,15 @@ +#source: start.s +#source: symbol2ref.s +#source: symbol2w.s +#ld: -T group.ld +#warning: ^[^\\n]*\.[obj]+: warning: function 'Foo' used$ +#readelf: -s +#notarget: "sparc64-*-solaris2*" "sparcv9-*-solaris2*" +#xfail: "arc-*-*" "d30v-*-*" "dlx-*-*" "i960-*-*" "or32-*-*" "pj-*-*" + +# Check that warnings are generated for the symbols in .gnu.warning +# construct and that the symbol still appears as expected. + +#... +[ ]+[0-9]+:[ ]+[0-9a-f]+[ ]+20[ ]+OBJECT[ ]+GLOBAL DEFAULT[ ]+[1-2] Foo +#pass diff --git a/ld/testsuite/ld-elf/wrap.exp b/ld/testsuite/ld-elf/wrap.exp new file mode 100644 index 000000000000..5fd57ea7d621 --- /dev/null +++ b/ld/testsuite/ld-elf/wrap.exp @@ -0,0 +1,54 @@ +# Expect script for wrap ELF tests. +# Copyright 2006 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. +# + +# Exclude non-ELF targets. + +if ![is_elf_format] { + return +} + +# The following tests require running the executable generated by ld. +if ![isnative] { + return +} + +# Check if compiler works +if { [which $CC] == 0 } { + return +} + +set build_tests { + {"Build libwrap1a.so" + "-shared" "-fPIC" + {wrap1a.c} {} "libwrap1a.so"} + {"Build libwrap1b.so" + "-shared tmpdir/libwrap1a.so" "-fPIC" + {wrap1b.c} {} "libwrap1b.so"} +} + +set run_tests { + {"Run with libwrap1a.so and libwrap1b.so" + "--wrap par tmpdir/libwrap1a.so tmpdir/libwrap1b.so" "" + {wrap1.c} "wrap1" "wrap1.out"} + {"Run with libwrap1b.so and libwrap1a.so" + "--wrap par tmpdir/libwrap1b.so tmpdir/libwrap1a.so" "" + {wrap1.c} "wrap1" "wrap1.out"} +} + +run_cc_link_tests $build_tests +run_ld_link_exec_tests [] $run_tests diff --git a/ld/testsuite/ld-elf/wrap1.c b/ld/testsuite/ld-elf/wrap1.c new file mode 100644 index 000000000000..1ff250e2dba9 --- /dev/null +++ b/ld/testsuite/ld-elf/wrap1.c @@ -0,0 +1,8 @@ +extern void par (void); + +int +main (void) +{ + par (); + return 0; +} diff --git a/ld/testsuite/ld-elf/wrap1.out b/ld/testsuite/ld-elf/wrap1.out new file mode 100644 index 000000000000..7c1938f43b61 --- /dev/null +++ b/ld/testsuite/ld-elf/wrap1.out @@ -0,0 +1,3 @@ +__wrap_par +__real_par +par diff --git a/ld/testsuite/ld-elf/wrap1a.c b/ld/testsuite/ld-elf/wrap1a.c new file mode 100644 index 000000000000..75c94e00a448 --- /dev/null +++ b/ld/testsuite/ld-elf/wrap1a.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +void par (void) +{ + printf ("par\n"); +} diff --git a/ld/testsuite/ld-elf/wrap1b.c b/ld/testsuite/ld-elf/wrap1b.c new file mode 100644 index 000000000000..abd39aa97158 --- /dev/null +++ b/ld/testsuite/ld-elf/wrap1b.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +extern void par (void); + +void __real_par (void) +{ + printf ("__real_par \n"); + par (); +} + +void +__wrap_par (void) +{ + printf ("__wrap_par \n"); + __real_par (); +} |