From patchwork Wed Oct 30 17:35:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35479 Received: (qmail 13637 invoked by alias); 30 Oct 2019 17:35:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 12313 invoked by uid 89); 30 Oct 2019 17:35:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=gdbada, UD:ada, UD:gdb.ada, Independent X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Oct 2019 17:35:44 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 805D220277; Wed, 30 Oct 2019 13:35:42 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id BD74B20407; Wed, 30 Oct 2019 13:35:38 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id B1C5920AF6; Wed, 30 Oct 2019 13:35:38 -0400 (EDT) X-Gerrit-PatchSet: 3 Date: Wed, 30 Oct 2019 13:35:38 -0400 From: "Tom de Vries (Code Review)" To: Joel Brobecker , Tom Tromey , gdb-patches@sourceware.org Cc: Luis Machado , Simon Marchi Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v3] [gdb/testsuite] Compile ada with -lgnarl_pic and -lgnat_pic if required X-Gerrit-Change-Id: I3e1e40bd46236b45e2d7808c1cd744a075d4a148 X-Gerrit-Change-Number: 32 X-Gerrit-ChangeURL: X-Gerrit-Commit: 5a5172eaab1f54c91a8dbf46679c67dcc6b63337 In-Reply-To: References: Reply-To: tdevries@suse.de, simon.marchi@polymtl.ca, tromey@sourceware.org, luis.machado@linaro.org, brobecker@adacore.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-75-g9005159e5d Message-Id: <20191030173538.B1C5920AF6@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/32 ...................................................................... [gdb/testsuite] Compile ada with -lgnarl_pic and -lgnat_pic if required On openSUSE Leap 15.1, when running the gdb.ada testsuite with target board unix/-fPIE/-pie, I get: ... nr of unexpected failures 158 ... The problem is that although due to commit abcf2cc85a3 "[gdb/testsuite] Fix ada tests with -fPIE/-pie" we try to compile say, hello.adb like so: ... $ gnatmake -fPIE -largs -pie -margs hello.adb ... this is not sufficient, because gnatlink is try to link in libgnat.a, which is not Position Independent Code. This issue has been filed as gcc PR ada/87936 - "gnatlink fails with -pie". Work around this issue by compiling with _pic versions of lgnarl and lgnat: ... $ gnatmake -fPIE -largs -pie -lgnarl_pic -lgnat_pic -margs hello.adb ... if that is required to make hello.adb compile. Using this patch, I get instead: ... FAIL: gdb.ada/exec_changed.exp: start second nr of unexpected failures 1 ... which has been filed as gdb PR24890. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2019-10-10 Tom de Vries PR testsuite/24888 * lib/ada.exp (gdb_simple_compile_ada): New proc. (calculating_ada_needs_libs_pic_suffix): New global, initialized to 0. (gdb_ada_needs_libs_pic_suffix): New caching proc. (target_compile_ada_from_dir): Append -largs -lgnarl_pic -lgnat_pic -margs to multilib_flags if required. (gdb_compile_ada_1): Factor out of ... (gdb_compile_ada): ... here. Change-Id: I3e1e40bd46236b45e2d7808c1cd744a075d4a148 --- M gdb/testsuite/lib/ada.exp 1 file changed, 105 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 45c4180..7bb1e9f 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -13,6 +13,96 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +# Compile the ada code in $code to a file based on $name, using the flags +# $compile_flags as well as debug, nowarning and quiet. +# Return 1 if code can be compiled +# Leave the file name of the resulting object in the upvar object. +# Similar to gdb_simple_compile, but using gdb_compile_ada_1 instead of +# gdb_compile. + +proc gdb_simple_compile_ada {name code {type object} {compile_flags {}} {object obj}} { + upvar $object obj + + switch -regexp -- $type { + "executable" { + set postfix "x" + } + "object" { + set postfix "o" + } + "preprocess" { + set postfix "i" + } + "assembly" { + set postfix "s" + } + } + set src [standard_temp_file $name.adb] + set obj [standard_temp_file $name-[pid].$postfix] + set compile_flags [concat $compile_flags {debug nowarnings quiet}] + + gdb_produce_source $src $code + + verbose "$name: compiling testfile $src" 2 + set lines [gdb_compile_ada_1 $src $obj $type $compile_flags] + + if ![string match "" $lines] then { + verbose "$name: compilation failed, returning 0" 2 + return 0 + } + return 1 +} + +# Global variable used in gdb_ada_needs_libs_pic_suffix to detect recursion. +# Initialize to 0. + +set calculating_ada_needs_libs_pic_suffix 0 + +# Caching true/false for whether we need to use -lgnarl_pic -lgnat_pic in +# target_compile_ada_from_dir. + +gdb_caching_proc gdb_ada_needs_libs_pic_suffix { + global calculating_ada_needs_libs_pic_suffix + if { $calculating_ada_needs_libs_pic_suffix } { + return 0 + } + set ada_hello { + with Ada.Text_IO; + + procedure Hello is + begin + Ada.Text_IO.Put_Line("Hello, world!"); + end Hello; + } + + set calculating_ada_needs_libs_pic_suffix 1 + set res \ + [gdb_simple_compile_ada hello $ada_hello executable] + if { $res == 1 } { + set calculating_ada_needs_libs_pic_suffix 0 + # Compilation works without the flags, we don't need them. + return 0 + } + set flags {} + lappend flags "additional_flags=-largs" + lappend flags "additional_flags=-lgnarl_pic" + lappend flags "additional_flags=-lgnat_pic" + lappend flags "additional_flags=-margs" + set res \ + [gdb_simple_compile_ada hello $ada_hello executable $flags] + if { $res == 1 } { + set calculating_ada_needs_libs_pic_suffix 0 + # Compilation works with the flags, we need them. + return 1 + } + + set calculating_ada_needs_libs_pic_suffix 0 + # Compilation doesn't work, even with the flags. Assume we don't need + # them, since they don't seem to help. + return 0 +} + # Call target_compile with SOURCE DEST TYPE and OPTIONS as argument, # after having temporarily changed the current working directory to # BUILDDIR. @@ -29,6 +119,10 @@ # Pretend gnatmake supports -pie/-no-pie, route it to # linker. append multilib_flag " -largs $op -margs" + if { $op == "-pie" && [gdb_ada_needs_libs_pic_suffix]} { + # Work around PR gcc/87936 by using libgnat_pic + append multilib_flag " -largs -lgnarl_pic -lgnat_pic -margs" + } } else { append multilib_flag " $op" } @@ -52,9 +146,9 @@ return -options $options $result } -# Compile some Ada code. +# Compile some Ada code. Return "" if the compile was successful. -proc gdb_compile_ada {source dest type options} { +proc gdb_compile_ada_1 {source dest type options} { set srcdir [file dirname $source] set gprdir [file dirname $srcdir] @@ -78,6 +172,15 @@ # We therefore simply check whether the dest file has been created # or not. Unless not present, the build has succeeded. if [file exists $dest] { set result "" } + return $result +} + +# Compile some Ada code. Generate "PASS: foo.exp: compilation SOURCE" if the +# compile was successful. + +proc gdb_compile_ada {source dest type options} { + set result [gdb_compile_ada_1 $source $dest $type $options] + gdb_compile_test $source $result return $result }