public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/testsuite] Compile compile-ifunc.c with -Wno-attribute-alias
@ 2020-05-01 14:26 Tom de Vries
  2020-05-06  3:32 ` [committed][gdb/testsuite] " Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2020-05-01 14:26 UTC (permalink / raw)
  To: gdb-patches

Hi,

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
...

Any comments?

Thanks,
- Tom

[gdb/testsuite] Compile compile-ifunc.c with -Wno-attribute-alias

gdb/testsuite/ChangeLog:

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

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

---
 gdb/testsuite/gdb.compile/compile-ifunc.exp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.compile/compile-ifunc.exp b/gdb/testsuite/gdb.compile/compile-ifunc.exp
index ff81e2f87aa..4b482b8245c 100644
--- a/gdb/testsuite/gdb.compile/compile-ifunc.exp
+++ b/gdb/testsuite/gdb.compile/compile-ifunc.exp
@@ -19,9 +19,12 @@ if {[skip_ifunc_tests]} {
 
 standard_testfile
 
+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 +54,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
     }
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [committed][gdb/testsuite] Compile compile-ifunc.c with -Wno-attribute-alias
  2020-05-01 14:26 [PATCH][gdb/testsuite] Compile compile-ifunc.c with -Wno-attribute-alias Tom de Vries
@ 2020-05-06  3:32 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2020-05-06  3:32 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 336 bytes --]

On 01-05-2020 16:26, Tom de Vries wrote:
> Fix the warning by compiling with -Wno-attribute-alias.

I ran into this with clang:
...
warning: unknown warning option '-Wno-attribute-alias'; did you mean^M
      '-Wno-attributes'? [-Wunknown-warning-option]^M
...

So, I've limited the fix to when gcc is used.

Committed.

Thanks,
- Tom


[-- Attachment #2: 0001-gdb-testsuite-Compile-compile-ifunc.c-with-Wno-attribute-alias.patch --]
[-- Type: text/x-patch, Size: 3485 bytes --]

[gdb/testsuite] Compile compile-ifunc.c with -Wno-attribute-alias

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-01  Tom de Vries  <tdevries@suse.de>

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

---
 gdb/testsuite/gdb.compile/compile-ifunc.exp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.compile/compile-ifunc.exp b/gdb/testsuite/gdb.compile/compile-ifunc.exp
index ff81e2f87aa..9239c5adf1e 100644
--- a/gdb/testsuite/gdb.compile/compile-ifunc.exp
+++ b/gdb/testsuite/gdb.compile/compile-ifunc.exp
@@ -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
     }
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-06  3:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-01 14:26 [PATCH][gdb/testsuite] Compile compile-ifunc.c with -Wno-attribute-alias Tom de Vries
2020-05-06  3:32 ` [committed][gdb/testsuite] " Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).