diff options
author | Gary Benson <gbenson@redhat.com> | 2020-11-02 14:19:29 +0000 |
---|---|---|
committer | Gary Benson <gbenson@redhat.com> | 2020-11-02 14:19:29 +0000 |
commit | 6539a36d0e1a949f66ee2d58bb16c8db133c96a5 (patch) | |
tree | 3e4a8174d3156bf3d6443caf5261c861ba77aff3 /gdb | |
parent | 7ea44a51faeb81644eeb14f06db15cfb4a65d59e (diff) | |
download | gdb-6539a36d0e1a949f66ee2d58bb16c8db133c96a5.zip gdb-6539a36d0e1a949f66ee2d58bb16c8db133c96a5.tar.gz gdb-6539a36d0e1a949f66ee2d58bb16c8db133c96a5.tar.bz2 |
Detect and report incompatible gdb_compile options
In commits 221db974e653659edb280787af1b3efdd1615083 and
68d654afdfcff840ebb3ae432ed72dca0521d670, these patches:
2020-06-24 Pedro Alves <palves@redhat.com>
* lib/gdb.exp (gdb_compile): Pass "-x c++" explicitly when
compiling C++ programs.
2020-09-25 Gary Benson <gbenson@redhat.com>
* lib/gdb.exp (gdb_compile): Pass "-x c++" earlier, and only
for .c files.
attempted to fix problems with testcases that compile .c files
using the C++ compiler. These patches cause gdb_compile to add
"-x c++" to the compiler options when using Clang. This fix does
not work for gdb.base/print-file-var.exp, however, which attempts
to compile a .c input file to an executable linked with shared
libraries: the resulting command caused the compiler to attempt
to parse the .so files as C++. This commit causes gdb_compile
to reject this combination of options.
gdb/testsuite/ChangeLog:
* lib/gdb.exp (gdb_compile): Inhibit passing "-x c++"
for .c files compiled as C++ with Clang if any shared
libraries are specified.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 17 |
2 files changed, 20 insertions, 3 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index be14e5a..330a5eb 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2020-11-02 Gary Benson <gbenson@redhat.com> + * lib/gdb.exp (gdb_compile): Inhibit passing "-x c++" + for .c files compiled as C++ with Clang if any shared + libraries are specified. + +2020-11-02 Gary Benson <gbenson@redhat.com> + * lib/attributes.h: New header. * gdb.base/backtrace.c: Include the above. Replace __attribute__(noclone)) with ATTRIBUTE_NOCLONE. diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 003bd30..6c98ae0 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -3960,9 +3960,20 @@ proc gdb_compile {source dest type options} { # explicitly force C++ language. if { [lsearch -exact $options getting_compiler_info] == -1 && [lsearch -exact $options c++] != -1 - && [string match *.c $source] != 0 - && [test_compiler_info "clang-*"] } { - lappend new_options early_flags=-x\ c++ + && [string match *.c $source] != 0 } { + + # gdb_compile cannot handle this combination of options, the + # result is a command like "clang -x c++ foo.c bar.so -o baz" + # which tells Clang to treat bar.so as C++. The solution is + # to call gdb_compile twice--once to compile, once to link-- + # either directly, or via build_executable_from_specs. + if { [lsearch $options shlib=*] != -1 } { + error "incompatible gdb_compile options" + } + + if {[test_compiler_info "clang-*"]} { + lappend new_options early_flags=-x\ c++ + } } # Place (and look for) Fortran `.mod` files in the output |