public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix gdb.base/align-*.exp and Clang + LTO and AIX GCC
@ 2023-04-06 15:57 Pedro Alves
0 siblings, 0 replies; only message in thread
From: Pedro Alves @ 2023-04-06 15:57 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b4f767131f75179df4f47fc40e177f2607fb1003
commit b4f767131f75179df4f47fc40e177f2607fb1003
Author: Pedro Alves <pedro@palves.net>
Date: Wed Mar 29 13:21:20 2023 +0100
Fix gdb.base/align-*.exp and Clang + LTO and AIX GCC
Clang with LTO (clang -flto) garbage collects unused global variables,
Thus, gdb.base/align-c.exp and gdb.base/align-c++.exp fail with
hundreds of FAILs like so:
$ make check \
TESTS="gdb.*/align-*.exp" \
RUNTESTFLAGS="CC_FOR_TARGET='clang -flto' CXX_FOR_TARGET='clang++ -flto'"
...
FAIL: gdb.base/align-c.exp: get integer valueof "a_char"
FAIL: gdb.base/align-c.exp: print _Alignof(char)
FAIL: gdb.base/align-c.exp: get integer valueof "a_char_x_char"
FAIL: gdb.base/align-c.exp: print _Alignof(struct align_pair_char_x_char)
FAIL: gdb.base/align-c.exp: get integer valueof "a_char_x_unsigned_char"
...
AIX GCC has the same issue, and there the easier way of adding
__attribute__((used)) to globals does not help.
So add explicit uses of all globals to the generated code.
For the C++ test, that reveals that the static variable members of the
generated structs are not defined anywhere, leading to undefined
references. Fixed by emitting initialization for all static members.
Lastly, I noticed that CXX_FOR_TARGET was being ignored -- that's
because the align-c++.exp testcase is compiling with the C compiler
driver. Fixed by passing "c++" as option to prepare_for_testing.
Change-Id: I874b717afde7b6fb1e45e526912b518a20a12716
Diff:
---
gdb/testsuite/gdb.base/align.exp.tcl | 49 ++++++++++++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.base/align.exp.tcl b/gdb/testsuite/gdb.base/align.exp.tcl
index 6a75a14d887..550afe1c47d 100644
--- a/gdb/testsuite/gdb.base/align.exp.tcl
+++ b/gdb/testsuite/gdb.base/align.exp.tcl
@@ -94,12 +94,15 @@ proc prepare_test_source_file { lang } {
puts $outfile "DEF_WITH_1_STATIC ($utype, $uinner);"
set joined "static_${utype}_x_${uinner}"
puts $outfile "struct align_pair_$joined item_${joined};"
+ puts $outfile "$utype align_pair_${joined}::one = 0;"
puts $outfile "unsigned a_${joined}"
puts $outfile " = ${align_func} (struct align_pair_${joined});"
puts $outfile "DEF_WITH_2_STATIC ($utype, $uinner);"
set joined "static_${utype}_x_static_${uinner}"
puts $outfile "struct align_pair_$joined item_${joined};"
+ puts $outfile "$utype align_pair_${joined}::one = 0;"
+ puts $outfile "$uinner align_pair_${joined}::two = 0;"
puts $outfile "unsigned a_${joined}"
puts $outfile " = ${align_func} (struct align_pair_${joined});"
}
@@ -107,12 +110,53 @@ proc prepare_test_source_file { lang } {
}
# Epilogue.
- puts $outfile {
+ puts $outfile "
int main() {
- return 0;
+ "
+
+ # Clang with LTO garbage collects unused global variables, even at
+ # -O0. Likewise AIX GCC. Add uses to all global variables to
+ # prevent it.
+
+ if { $lang == "c" } {
+ puts $outfile "a_void++;"
+ }
+
+ # First, add uses for single items.
+ foreach type $typelist {
+ set utype [join [split $type] _]
+ puts $outfile "item_$utype++;"
+ if { $lang == "c" } {
+ puts $outfile "a_$utype++;"
+ }
+ }
+
+ # Now add uses for all pairs.
+ foreach type $typelist {
+ set utype [join [split $type] _]
+ foreach inner $typelist {
+ set uinner [join [split $inner] _]
+ set joined "${utype}_x_${uinner}"
+ puts $outfile "item_${joined}.one++;"
+ puts $outfile "a_${joined}++;"
+
+ if { $lang == "c++" } {
+ set joined "static_${utype}_x_${uinner}"
+ puts $outfile "item_${joined}.one++;"
+ puts $outfile "a_${joined}++;"
+
+ set joined "static_${utype}_x_static_${uinner}"
+ puts $outfile "item_${joined}.one++;"
+ puts $outfile "a_${joined}++;"
+ }
}
}
+ puts $outfile "
+ return 0;
+ }
+ "
+
close $outfile
return $filename
@@ -127,6 +171,7 @@ proc run_alignment_test { lang } {
set flags {debug}
if { "$lang" == "c++" } {
+ lappend flags "c++"
lappend flags "additional_flags=-std=c++11"
}
standard_testfile $filename
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-06 15:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 15:57 [binutils-gdb] Fix gdb.base/align-*.exp and Clang + LTO and AIX GCC Pedro Alves
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).