From 68f7bda9b1c32920ce4a2fe65129525bc0b05bf7 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Fri, 14 Oct 2022 13:09:50 +0200 Subject: [PATCH] [gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie Compilers default to either PIE or no-PIE executables. In order to test PIE executables with a compiler that produces non-PIE by default, we can use target board unix/-fPIE/-pie, which set the multilib_flags of the target board to "-fPIE -pie". Likewise, we can use target board unix/-fno-PIE/-no-pie with a compiler that produces PIE by default. The target board unix/-fno-PIE/-no-pie has a potential problem when compiling shared libs, because the multilib_flags will override the attempts of gdb_compile_shlib to compile with -fPIC. This is taken care of by running the body of gdb_compile_shlib wrapped in with_PIE_multilib_flags_filtered. The target board unix/-fPIE/-pie has a problem with nopie compilations. The current approach is to do the compilation hoping for the best, and if we find out that the resulting executable is PIE despite specifying nopie, we error out with the standard error message "nopie failed to prevent PIE executable". That however does not work for hard-coded assembly nopie test-cases, which will just noisily refuse to compile: ... ld: amd64-disp-step0.o: relocation R_X86_64_32S against `.text' can not be \ used when making a PIE object; recompile with -fPIE^M ... Fix this in gdb_compile by filtering out the PIE settings in the target board multilib_flags when pie or nopie is specified. Tested on x86_64-linux. --- gdb/testsuite/lib/gdb.exp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 7de8bb60c19..1167aa73e2c 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4783,7 +4783,10 @@ proc gdb_compile {source dest type options} { } } - set result [target_compile $source $dest $type $options] + cond_wrap [expr $pie != -1 || $nopie != -1] \ + with_PIE_multilib_flags_filtered { + set result [target_compile $source $dest $type $options] + } # Prune uninteresting compiler (and linker) output. regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result -- 2.30.2