aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
Diffstat (limited to 'ld')
-rw-r--r--ld/testsuite/ChangeLog8
-rw-r--r--ld/testsuite/ld-ifunc/ifunc.exp27
-rw-r--r--ld/testsuite/ld-ifunc/pr18808.out1
-rw-r--r--ld/testsuite/ld-ifunc/pr18808a.c9
-rw-r--r--ld/testsuite/ld-ifunc/pr18808b.c24
-rw-r--r--ld/testsuite/lib/ld-lib.exp45
6 files changed, 114 insertions, 0 deletions
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index ea873d9..f719db7 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2015-08-11 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/18808
+ * ld-ifunc/ifunc.exp: Add a test for PR ld/18808.
+ * ld-ifunc/pr18808.out: New file.
+ * ld-ifunc/pr18808a.c: Likewise.
+ * ld-ifunc/pr18808b.c: Likewise.
+---
2015-08-07 H.J. Lu <hongjiu.lu@intel.com>
PR ld/18720
diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp
index e08261b..498cb2d 100644
--- a/ld/testsuite/ld-ifunc/ifunc.exp
+++ b/ld/testsuite/ld-ifunc/ifunc.exp
@@ -457,3 +457,30 @@ run_ld_link_exec_tests [] [list \
"-fpic" \
] \
]
+
+# Run-time tests which require working ifunc attribute support.
+if { ![check_ifunc_attribute_available] } {
+ return
+}
+
+run_cc_link_tests [list \
+ [list \
+ "Build libpr18808.so" \
+ "-shared" \
+ "-fPIC -O2 -g" \
+ { pr18808b.c } \
+ {} \
+ "libpr18808.so" \
+ ] \
+]
+
+run_ld_link_exec_tests [] [list \
+ [list \
+ "Run pr18808" \
+ "tmpdir/libpr18808.so" \
+ "" \
+ { pr18808a.c } \
+ "pr18808" \
+ "pr18808.out" \
+ ] \
+]
diff --git a/ld/testsuite/ld-ifunc/pr18808.out b/ld/testsuite/ld-ifunc/pr18808.out
new file mode 100644
index 0000000..d86bac9
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/pr18808.out
@@ -0,0 +1 @@
+OK
diff --git a/ld/testsuite/ld-ifunc/pr18808a.c b/ld/testsuite/ld-ifunc/pr18808a.c
new file mode 100644
index 0000000..35228ae
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/pr18808a.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+void bar(void);
+int main(void)
+{
+ bar();
+ printf("OK\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-ifunc/pr18808b.c b/ld/testsuite/ld-ifunc/pr18808b.c
new file mode 100644
index 0000000..6f0db5a
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/pr18808b.c
@@ -0,0 +1,24 @@
+int foo (int x) __attribute__ ((ifunc ("resolve_foo")));
+extern void abort (void);
+
+static int foo_impl(int x)
+{
+ return x;
+}
+
+int bar()
+{
+ int (*f)(int) = foo;
+
+ if (foo (5) != 5)
+ abort ();
+
+ if (f(42) != 42)
+ abort ();
+}
+
+
+void *resolve_foo (void)
+{
+ return (void *) foo_impl;
+}
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 6904499..364c6fa 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1960,6 +1960,51 @@ proc check_ifunc_available { } {
return $ifunc_available_saved
}
+# Returns true if ifunc attribute works.
+
+proc check_ifunc_attribute_available { } {
+ global ifunc_attribute_available_saved
+ global CC
+
+ if {![info exists ifunc_attribute_available_saved]} {
+ if { [which $CC] == 0 } {
+ set ifunc_attribute_available_saved 0
+ return 0
+ }
+ # Check if gcc supports -flto -fuse-linker-plugin
+ set flags ""
+ if [board_info [target_info name] exists cflags] {
+ append flags " [board_info [target_info name] cflags]"
+ }
+ if [board_info [target_info name] exists ldflags] {
+ append flags " [board_info [target_info name] ldflags]"
+ }
+
+ set basename "tmpdir/ifunc[pid]"
+ set src ${basename}.c
+ set output ${basename}.out
+ set f [open $src "w"]
+ puts $f "extern int library_func2 (void) __attribute__ ((ifunc (\"foo\")));"
+ puts $f "int main (void)"
+ puts $f "{"
+ puts $f " if (library_func2 () != 2) __builtin_abort ();"
+ puts $f " return 0; "
+ puts $f "}"
+ puts $f "static int library_func1 (void) {return 2; }"
+ puts $f "void *foo (void) { return library_func1; }"
+ close $f
+ remote_download host $src
+ set ifunc_attribute_available_saved [run_host_cmd_yesno "$CC" "$flags $src -o $output"]
+ if { $ifunc_attribute_available_saved == 1 } {
+ set ifunc_attribute_available_saved [run_host_cmd_yesno "$output" ""]
+ }
+ remote_file host delete $src
+ remote_file host delete $output
+ file delete $src
+ }
+ return $ifunc_attribute_available_saved
+}
+
# Provide virtual target "cfi" for targets supporting CFI.
rename "istarget" "istarget_ld"