public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom de Vries <vries@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] [gdb/testsuite] Fix nopie test-cases with target board unix/-fPIE/-pie
Date: Fri, 14 Oct 2022 11:10:10 +0000 (GMT)	[thread overview]
Message-ID: <20221014111011.17C4738582A0@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=68f7bda9b1c32920ce4a2fe65129525bc0b05bf7

commit 68f7bda9b1c32920ce4a2fe65129525bc0b05bf7
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Oct 14 13:09:50 2022 +0200

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

Diff:
---
 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

                 reply	other threads:[~2022-10-14 11:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221014111011.17C4738582A0@sourceware.org \
    --to=vries@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).