This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add function and function pointer tests


On Fri, Nov 21, 2014 at 07:59:33AM -0800, H.J. Lu wrote:
> On Thu, Nov 20, 2014 at 01:30:48PM -0800, H.J. Lu wrote:
> > On Thu, Nov 20, 2014 at 12:50:38PM -0800, H.J. Lu wrote:
> > > Hi,
> > > 
> > > I checked in this patch to adds tests for function and function pointer.
> > > 
> > > H.J.
> > > ---
> > > diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
> > > index 63f145e..5c5fe88 100644
> > > --- a/ld/testsuite/ChangeLog
> > > +++ b/ld/testsuite/ChangeLog
> > > @@ -1,5 +1,21 @@
> > >  2014-11-20  H.J. Lu  <hongjiu.lu@intel.com>
> > >  
> > > +	* ld-x86-64/plt-lib.c: New file.
> > > +	* ld-x86-64/plt-main.out: Likewise.
> > > +	* ld-x86-64/plt-main1.c: Likewise.
> > > +	* ld-x86-64/plt-main1.rd: Likewise.
> > > +	* ld-x86-64/plt-main2.c: Likewise.
> > > +	* ld-x86-64/plt-main2.rd: Likewise.
> > > +	* ld-x86-64/plt-main3.c: Likewise.
> > > +	* ld-x86-64/plt-main3.rd: Likewise.
> > > +	* ld-x86-64/plt-main4.c: Likewise.
> > > +	* ld-x86-64/plt-main4.rd: Likewise.
> > > +	* ld-x86-64/plt-main5.c: Likewise.
> > > +
> > > +	* ld-x86-64/x86-64.exp: Run plt-main tests.
> > > +
> > 
> > I checked in this for x32.
> > 
> > H.J.
> > ---
> > diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
> > index 5c5fe88..f959d55 100644
> > --- a/ld/testsuite/ChangeLog
> > +++ b/ld/testsuite/ChangeLog
> > @@ -1,5 +1,12 @@
> >  2014-11-20  H.J. Lu  <hongjiu.lu@intel.com>
> >  
> > +	* ld-x86-64/plt-main1.rd: Updated for x32.
> > +	* ld-x86-64/plt-main2.rd: Likewise.
> > +	* ld-x86-64/plt-main3.rd: Likewise.
> > +	* ld-x86-64/plt-main4.rd: Likewise.
> > +
> > +2014-11-20  H.J. Lu  <hongjiu.lu@intel.com>
> > +
> 
> I checked in this patch to add PIE test.
> 
> H.J.
> ---
> diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
> index 0068a85..9a264b6 100644
> --- a/ld/testsuite/ChangeLog
> +++ b/ld/testsuite/ChangeLog
> @@ -1,3 +1,7 @@
> +2014-11-21  H.J. Lu  <hongjiu.lu@intel.com>
> +
> +	* ld-x86-64/x86-64.exp: Run plt-main test with -pie.
> +
>  2014-11-21  Terry Guo  <terry.guo@arm.com>
>  

I checked in the similar tests for i386.

H.J.
---
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 9a264b6..be12722 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,5 +1,21 @@
 2014-11-21  H.J. Lu  <hongjiu.lu@intel.com>
 
+	* ld-i386/plt-lib.c: New file.
+	* ld-i386/plt-main.out: Likewise.
+	* ld-i386/plt-main1.c: Likewise.
+	* ld-i386/plt-main1.rd: Likewise.
+	* ld-i386/plt-main2.c: Likewise.
+	* ld-i386/plt-main2.rd: Likewise.
+	* ld-i386/plt-main3.c: Likewise.
+	* ld-i386/plt-main3.rd: Likewise.
+	* ld-i386/plt-main4.c: Likewise.
+	* ld-i386/plt-main4.rd: Likewise.
+	* ld-i386/plt-main5.c: Likewise.
+
+	* ld-i386/i386.exp: Run plt-main tests.
+
+2014-11-21  H.J. Lu  <hongjiu.lu@intel.com>
+
 	* ld-x86-64/x86-64.exp: Run plt-main test with -pie.
 
 2014-11-21  Terry Guo  <terry.guo@arm.com>
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 30be98a..4c870b8 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -263,3 +263,73 @@ run_dump_test "pr12627"
 run_dump_test "pr13302"
 run_dump_test "pr14215"
 run_dump_test "pr17057"
+
+# Must be Linux native with the C compiler
+if { [isnative]
+     && [istarget "i?86-*-linux*"]
+     && [which $CC] != 0 } {
+    run_cc_link_tests [list \
+	[list \
+	    "Build plt-lib.so" \
+	    "-shared" \
+	    "-fPIC" \
+	    { plt-lib.c } \
+	    {} \
+	    "libplt-lib.so" \
+	] \
+	[list \
+	    "Build libplt-main1.a" \
+	    "" \
+	    "-fPIC" \
+	    { plt-main1.c } \
+	    {{readelf {-Wr} plt-main1.rd}} \
+	    "libplt-main1.a" \
+	] \
+	[list \
+	    "Build libplt-main2.a" \
+	    "" \
+	    "-fPIC" \
+	    { plt-main2.c } \
+	    {{readelf {-Wr} plt-main2.rd}} \
+	    "libplt-main2.a" \
+	] \
+	[list \
+	    "Build libplt-main3.a" \
+	    "" \
+	    "-fPIC" \
+	    { plt-main3.c } \
+	    {{readelf {-Wr} plt-main3.rd}} \
+	    "libplt-main3.a" \
+	] \
+	[list \
+	    "Build libplt-main4.a" \
+	    "" \
+	    "-fPIC" \
+	    { plt-main4.c } \
+	    {{readelf {-Wr} plt-main4.rd}} \
+	    "libplt-main4.a" \
+	] \
+    ]
+
+    run_ld_link_exec_tests [] [list \
+	[list \
+	    "Run plt-main" \
+	    "tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
+	     tmpdir/plt-main4.o tmpdir/libplt-lib.so" \
+	    "" \
+	    { plt-main5.c } \
+	    "plt-main" \
+	    "plt-main.out" \
+	] \
+	[list \
+	    "Run plt-main with PIE" \
+	    "tmpdir/plt-main1.o tmpdir/plt-main2.o tmpdir/plt-main3.o \
+	     tmpdir/plt-main4.o tmpdir/libplt-lib.so -pie" \
+	    "" \
+	    { plt-main5.c } \
+	    "plt-main-pie" \
+	    "plt-main.out" \
+	    "-fPIC" \
+	] \
+    ]
+}
diff --git a/ld/testsuite/ld-i386/plt-lib.c b/ld/testsuite/ld-i386/plt-lib.c
new file mode 100644
index 0000000..5e64ccd
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-lib.c
@@ -0,0 +1,11 @@
+int
+foo (void)
+{
+  return 1;
+}
+
+int
+bar (void)
+{
+  return -1;
+}
diff --git a/ld/testsuite/ld-i386/plt-main.out b/ld/testsuite/ld-i386/plt-main.out
new file mode 100644
index 0000000..d86bac9
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main.out
@@ -0,0 +1 @@
+OK
diff --git a/ld/testsuite/ld-i386/plt-main1.c b/ld/testsuite/ld-i386/plt-main1.c
new file mode 100644
index 0000000..90bb966
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main1.c
@@ -0,0 +1,8 @@
+extern int bar(void);
+typedef int (*func_p) (void);
+
+func_p
+get_bar (void)
+{
+  return bar;
+}
diff --git a/ld/testsuite/ld-i386/plt-main1.rd b/ld/testsuite/ld-i386/plt-main1.rd
new file mode 100644
index 0000000..d27589e
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main1.rd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f ]+R_386_GOT32 +0+ +bar
+#pass
diff --git a/ld/testsuite/ld-i386/plt-main2.c b/ld/testsuite/ld-i386/plt-main2.c
new file mode 100644
index 0000000..d76694e
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main2.c
@@ -0,0 +1,3 @@
+extern int foo(void);
+typedef int (*func_p) (void);
+func_p foo_ptr = foo;
diff --git a/ld/testsuite/ld-i386/plt-main2.rd b/ld/testsuite/ld-i386/plt-main2.rd
new file mode 100644
index 0000000..e815015
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main2.rd
@@ -0,0 +1,3 @@
+#...
+[0-9a-f ]+R_386_32 +0+ +foo
+#pass
diff --git a/ld/testsuite/ld-i386/plt-main3.c b/ld/testsuite/ld-i386/plt-main3.c
new file mode 100644
index 0000000..026e05f
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main3.c
@@ -0,0 +1,15 @@
+extern int bar(void);
+typedef int (*func_p) (void);
+extern func_p get_bar (void);
+
+void
+check_bar (void)
+{
+  func_p bar_ptr = get_bar ();
+  if (bar_ptr != bar)
+    __builtin_abort ();
+  if (bar_ptr() != -1)
+    __builtin_abort ();
+  if (bar() != -1)
+    __builtin_abort ();
+}
diff --git a/ld/testsuite/ld-i386/plt-main3.rd b/ld/testsuite/ld-i386/plt-main3.rd
new file mode 100644
index 0000000..7b78818
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main3.rd
@@ -0,0 +1,5 @@
+#...
+[0-9a-f ]+R_386_GOT32 +0+ +bar
+#...
+[0-9a-f ]+R_386_PLT32 +0+ +bar
+#pass
diff --git a/ld/testsuite/ld-i386/plt-main4.c b/ld/testsuite/ld-i386/plt-main4.c
new file mode 100644
index 0000000..992ba5f
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main4.c
@@ -0,0 +1,14 @@
+extern int foo(void);
+typedef int (*func_p) (void);
+extern func_p foo_ptr;
+
+void
+check_foo (void)
+{
+  if (foo_ptr != foo)
+    __builtin_abort ();
+  if (foo_ptr() != 1)
+    __builtin_abort ();
+  if (foo() != 1)
+    __builtin_abort ();
+}
diff --git a/ld/testsuite/ld-i386/plt-main4.rd b/ld/testsuite/ld-i386/plt-main4.rd
new file mode 100644
index 0000000..882a3ad
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main4.rd
@@ -0,0 +1,5 @@
+#...
+[0-9a-f ]+R_386_GOT32 +0+ +foo
+#...
+[0-9a-f ]+R_386_PLT32 +0+ +foo
+#pass
diff --git a/ld/testsuite/ld-i386/plt-main5.c b/ld/testsuite/ld-i386/plt-main5.c
new file mode 100644
index 0000000..97351a8
--- /dev/null
+++ b/ld/testsuite/ld-i386/plt-main5.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+extern void check_foo (void);
+extern void check_bar (void);
+
+int
+main (void)
+{
+  check_foo ();
+  check_bar ();
+
+  printf ("OK\n");
+
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]