]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Compile compile-ifunc.c with -Wno-attribute-alias
authorTom de Vries <tdevries@suse.de>
Wed, 6 May 2020 03:27:48 +0000 (05:27 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 6 May 2020 03:27:48 +0000 (05:27 +0200)
Consider the following test-case:
...
$ cat 1.c
typedef int (*final_t) (int arg);
int final (int arg)
  { return arg + 1; }
final_t gnu_ifunc (void)
  { return final; }
int gnu_ifunc_alias (int) __attribute__ ((ifunc ("gnu_ifunc")));
int main (void)
  { return gnu_ifunc_alias (10); }
...
with result:
...
$ gcc 1.c
$ ./a.out; echo $?
11
...

The test-case uses the ifunc attribute, but there's another solution using
%gnu_indirect_function.  Consider 2.c and 3.c:
...
$ cat 2.c
typedef int (*final_t) (int arg);
int final (int arg)
  { return arg + 1; }
asm (".type gnu_ifunc, %gnu_indirect_function");
final_t gnu_ifunc (void)
  { return final; }
$ cat 3.c
extern int gnu_ifunc (int);
int main (void)
  { return gnu_ifunc (10); }
...

However, it can be inconvenient to have seperate files for the incompatible
decls of gnu_ifunc, so we can use this in a single file like this:
...
$ cat 4.c
typedef int (*final_t) (int arg);
int final (int arg)
  { return arg + 1; }
asm (".type gnu_ifunc, %gnu_indirect_function");
final_t gnu_ifunc (void)
  { return final; }
extern int gnu_ifunc_alias (int arg) __attribute__ ((alias ("gnu_ifunc")));
int main (void)
  { return gnu_ifunc_alias (10); }
...

This alias trick works ok at -O0, but not at -O2:
...
$ gcc 4.c
$ ./a.out; echo $?
11
$ gcc 4.c
$ ./a.out; echo $?
176
...
and produces a warning with gcc-8 and later:
...
$ gcc-8 4.c
4.c:7:12: warning: 'gnu_ifunc_alias' alias between functions of incompatible \
  types 'int(int)' and 'int (*(void))(int)' [-Wattribute-alias]
 extern int gnu_ifunc_alias (int arg) __attribute__ ((alias ("gnu_ifunc")));
            ^~~~~~~~~~~~~~~
4.c:5:9: note: aliased declaration here
 final_t gnu_ifunc (void)
         ^~~~~~~~~
...
The warning is correct, but the mismatch is intentional.

The last variant (%gnu_indirect_function + alias) is used in
gdb.compile/compile-ifunc.c, so we run into the warning with recent gcc.

Fix the warning by compiling with -Wno-attribute-alias.

Tested the test-case on x86_64-linux with gcc-10, and observed I no longer see
the warning:
...
Running src/gdb/testsuite/gdb.compile/compile-ifunc.exp ...

                === gdb Summary ===

nr of untested testcases         1
...

gdb/testsuite/ChangeLog:

2020-05-06  Tom de Vries  <tdevries@suse.de>

* gdb.compile/compile-ifunc.exp: Use -Wno-attribute-alias.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.compile/compile-ifunc.exp

index 409f44ca9d0d527086de4bf886475a59c4d829e7..7b88b3a469c482ee8ce1578cd31635871eae10c8 100644 (file)
@@ -1,3 +1,7 @@
+2020-05-06  Tom de Vries  <tdevries@suse.de>
+
+       * gdb.compile/compile-ifunc.exp: Use -Wno-attribute-alias.
+
 2020-05-04  Tom de Vries  <tdevries@suse.de>
 
        * gdb.base/async.exp: Check whether instruction addresses are a
index ff81e2f87aa6b7ef13bdfffe9760abaff153e990..9239c5adf1ef0abd86cb82b496ec063790d7917d 100644 (file)
@@ -19,9 +19,16 @@ if {[skip_ifunc_tests]} {
 
 standard_testfile
 
+get_compiler_info
+set flags ""
+if [test_compiler_info gcc*] {
+    set flags additional_flags=-Wno-attribute-alias
+}
+
 with_test_prefix "nodebug" {
 
-    if { [prepare_for_testing "failed to prepare" "$testfile-nodebug" $srcfile {}] } {
+    if { [prepare_for_testing "failed to prepare" "$testfile-nodebug" \
+             $srcfile $flags] } {
        return -1
     }
 
@@ -51,7 +58,8 @@ with_test_prefix "nodebug" {
 
 with_test_prefix "debug" {
 
-    if { [prepare_for_testing "failed to prepare" "$testfile-debug" $srcfile] } {
+    if { [prepare_for_testing "failed to prepare" "$testfile-debug" \
+             $srcfile "debug $flags"] } {
        return -1
     }