aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@linaro.org>2017-04-19 08:51:04 +0000
committerChristophe Lyon <christophe.lyon@linaro.org>2017-05-03 07:59:43 +0000
commit43dae5fd274ed5a115cc448b150f84ebe58c895f (patch)
tree70b3939d47b5c4d2ac3ee4ea8a428b399ab90667
parent35b9bb679bde1ed34517d4abdd04c4335acd6013 (diff)
bug-2562: New test.
Change-Id: Ib40250db1ccba839f36bc8953e13665f6cdb56d8
-rw-r--r--bug-2562/Makefile1
-rwxr-xr-xbug-2562/build.sh20
-rw-r--r--bug-2562/some_module.c47
3 files changed, 68 insertions, 0 deletions
diff --git a/bug-2562/Makefile b/bug-2562/Makefile
new file mode 100644
index 0000000..23f8a8f
--- /dev/null
+++ b/bug-2562/Makefile
@@ -0,0 +1 @@
+include ../common.mk
diff --git a/bug-2562/build.sh b/bug-2562/build.sh
new file mode 100755
index 0000000..a5c3757
--- /dev/null
+++ b/bug-2562/build.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+set -e
+
+case ${TARGET} in
+ arm*)
+ CFLAGS="-marm -fpie"
+ ;;
+ *)
+ echo "$(basename $(pwd)): SKIP" > result.txt
+ exit 0
+ ;;
+esac
+
+echo "$(basename $(pwd)): FAIL" > result.txt
+set -x
+${CC} $CFLAGS -S some_module.c -o some_module.s
+grep '.word some_weak_func' some_module.s | grep GOT
+
+set +x
+echo "$(basename $(pwd)): PASS" > result.txt
diff --git a/bug-2562/some_module.c b/bug-2562/some_module.c
new file mode 100644
index 0000000..628359c
--- /dev/null
+++ b/bug-2562/some_module.c
@@ -0,0 +1,47 @@
+
+int printf(const char *__restrict __format, ...);
+
+int res_direct_call;
+int res_pointer_call;
+
+int (*__weak_func_ptr )(void);
+
+int __attribute__((weak)) some_weak_func(void)
+{
+ return 10;
+}
+
+void call_weak_directly(void)
+{
+ res_direct_call = some_weak_func();
+}
+
+void save_weak_func_pointer(void)
+{
+ __weak_func_ptr = some_weak_func;
+}
+
+void call_weak_by_pointer(void)
+{
+ res_pointer_call = __weak_func_ptr();
+}
+
+void test_weak_funcion_call(void)
+{
+ printf("Entering test_weak_funcion_call\n");
+
+ save_weak_func_pointer();
+
+ printf("This line is to avoid optimization in further call_weak_by_pointer\n");
+
+ call_weak_by_pointer();
+ printf(" res_pointer_call = %d\n", res_pointer_call);
+
+ call_weak_directly();
+ printf(" res_direct_call = %d\n", res_direct_call);
+
+ if (res_direct_call == res_pointer_call)
+ printf("All Ok\n");
+ else
+ printf("ERROR: Results from direct call and from call via pointer differs\n");
+}