From patchwork Thu Oct 10 14:03:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 34907 Received: (qmail 3999 invoked by alias); 10 Oct 2019 14:03:39 -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 3991 invoked by uid 89); 10 Oct 2019 14:03:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=Independent, 09-10-2019 X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Oct 2019 14:03:38 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B9697AF23; Thu, 10 Oct 2019 14:03:35 +0000 (UTC) Subject: [gdb/testsuite] Compile ada with -lgnarl_pic and -lgnat_pic if required To: Tom Tromey Cc: gdb-patches@sourceware.org, Joel Brobecker References: <20190807110713.GA23000@delia> <87v9v96oul.fsf@tromey.com> <7eb7d7c6-7b32-846d-369f-9bd6a466850d@suse.de> <12cc8627-17db-d52d-73cc-d352b011791c@suse.de> <87tv8idleo.fsf@tromey.com> From: Tom de Vries Message-ID: <373ebbd0-d646-3162-31af-174e8b08f8a4@suse.de> Date: Thu, 10 Oct 2019 16:03:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <87tv8idleo.fsf@tromey.com> X-IsSubscribed: yes [ Re: [PING][PATCH][gdb/testsuite] Fix ada tests with -fPIE/-pie ] On 09-10-2019 16:49, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > >>> 2019-08-08 Tom de Vries >>> >>> PR testsuite/24888 >>> * lib/ada.exp (target_compile_ada_from_dir): Route -pie/-no-pie to >>> gnatlink. > > I'm sorry about the delay on this. Np, thanks for the review. > I think this is ok. Committed. And now that the approach has been deemed acceptable, here's a followup patch that makes gdb.ada work for me on openSUSE Leap 15.1 with -fPIE/-pie. OK for trunk? Thanks, - Tom [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: ... nr of unexpected failures 2 ... where one failure also happens with native, and the other 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. --- gdb/testsuite/lib/ada.exp | 86 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 45c41806a64..4bdb12051ec 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -17,6 +17,78 @@ # after having temporarily changed the current working directory to # BUILDDIR. +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 calculating_ada_needs_libs_pic_suffix +set calculating_ada_needs_libs_pic_suffix 0 +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 + 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 + return 1 + } + + set calculating_ada_needs_libs_pic_suffix 0 + return 0 +} + proc target_compile_ada_from_dir {builddir source dest type options} { set saved_cwd [pwd] @@ -29,6 +101,10 @@ proc target_compile_ada_from_dir {builddir source dest type options} { # 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" } @@ -54,7 +130,7 @@ proc target_compile_ada_from_dir {builddir source dest type options} { # Compile some Ada code. -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 +154,14 @@ proc gdb_compile_ada {source dest type options} { # 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. + +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 }