diff options
author | Pedro Alves <pedro@palves.net> | 2023-03-29 13:21:20 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2023-04-06 16:52:34 +0100 |
commit | b4f767131f75179df4f47fc40e177f2607fb1003 (patch) | |
tree | 3a4b18f9c65636de44f113cab692666df1487d75 /gdb | |
parent | a52aeef9237096bbde1c3092a4860d12c3778ffb (diff) | |
download | gdb-b4f767131f75179df4f47fc40e177f2607fb1003.zip gdb-b4f767131f75179df4f47fc40e177f2607fb1003.tar.gz gdb-b4f767131f75179df4f47fc40e177f2607fb1003.tar.bz2 |
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
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/testsuite/gdb.base/align.exp.tcl | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/gdb/testsuite/gdb.base/align.exp.tcl b/gdb/testsuite/gdb.base/align.exp.tcl index 6a75a14..550afe1 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 |