From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id LYuHJjSf11+KZgAAWB0awg (envelope-from ) for ; Mon, 14 Dec 2020 12:21:56 -0500 Received: by simark.ca (Postfix, from userid 112) id 8FFFF1F0AA; Mon, 14 Dec 2020 12:21:56 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 441DE1E99A for ; Mon, 14 Dec 2020 12:21:56 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7182F3858C27; Mon, 14 Dec 2020 17:21:55 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 68A1A3858C27 for ; Mon, 14 Dec 2020 17:21:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 68A1A3858C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [172.16.0.95] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 154B61E99A; Mon, 14 Dec 2020 12:21:52 -0500 (EST) Subject: Re: [PATCH][gdb/testsuite] Fix shlib compilation with target board unix/-pie/-fPIE To: Tom de Vries , gdb-patches@sourceware.org References: <20201213164131.GA7699@delia> From: Simon Marchi Message-ID: <60fb40c8-73ca-e6de-e45f-805fba548f88@simark.ca> Date: Mon, 14 Dec 2020 12:21:51 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201213164131.GA7699@delia> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2020-12-13 11:41 a.m., Tom de Vries wrote: > Hi, > > When running test-case gdb.base/info-shared.exp with target board > unix/-pie/-fPIE, we run into: > ... > spawn -ignore SIGHUP gcc -fno-stack-protector \ > outputs/gdb.base/info-shared/info-shared-solib1.c.o \ > -fdiagnostics-color=never -fPIC -shared -Wl,-soname,info-shared-solib1.so \ > -lm -fPIE -pie -o outputs/gdb.base/info-shared/info-shared-solib1.so^M > ld: Scrt1.o: in function `_start':^M > start.S:104: undefined reference to `main'^M > collect2: error: ld returned 1 exit status^M > compiler exited with status 1 > ... > > The intention of the -pie/-fPIE flags is to build and test PIE executables on > platforms where that is not the default. However, the flags clash with the > flags required to build shared libraries. > > Fix this by filtering out PIE-related flags out of the multilib_flags settings > in compile_shared_lib. > > Tested on x86_64-linux. > > Any comments? > > Thanks, > - Tom > > [gdb/testsuite] Fix shlib compilation with target board unix/-pie/-fPIE > > --- > gdb/testsuite/lib/gdb.exp | 39 ++++++++++++++++++++++++++++++++++++++- > 1 file changed, 38 insertions(+), 1 deletion(-) > > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index e35d236018..071b5afa99 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -4283,7 +4283,7 @@ proc gdb_compile_pthreads {source dest type options} { > > # Build a shared library from SOURCES. > > -proc gdb_compile_shlib {sources dest options} { > +proc gdb_compile_shlib_1 {sources dest options} { > set obj_options $options > > set ada 0 > @@ -4416,6 +4416,43 @@ proc gdb_compile_shlib {sources dest options} { > return "" > } > > +# Build a shared library from SOURCES. Ignore target boards PIE-related > +# multilib_flags. > + > +proc gdb_compile_shlib {sources dest options} { > + global board > + > + # Save multilib_flags. > + set board [target_info name] > + set save_multilib_flag [board_info $board multilib_flags] > + > + # Ignore PIE-related setting in multilib_flags. > + set multilib_flag "" > + foreach op $save_multilib_flag { > + if { $op == "-pie" || $op == "-no-pie" \ > + || $op == "-fPIE" || $op == "-fno-PIE"} { > + } else { > + append multilib_flag " $op" > + } > + } > + unset_board_info "multilib_flags" > + set_board_info multilib_flags "$multilib_flag" > + set code [catch {gdb_compile_shlib_1 $sources $dest $options} result] > + > + # Restore multilib_flags. > + unset_board_info "multilib_flags" > + set_board_info multilib_flags $save_multilib_flag > + > + if {$code == 1} { > + global errorInfo errorCode > + return -code error -errorinfo $errorInfo -errorcode $errorCode $result > + } elseif {$code > 1} { > + return -code $code $result > + } > + > + return $result That sounds reasonable. I wonder if the lines above could be simplified to: if {$code == 1} { ... } return -code $code $result IOW, if it's fine to return an explicit -code even if $code is 0 / OK. Otherwise, LGTM. Simon