From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6CMXHl1C2l9eLgAAWB0awg (envelope-from ) for ; Wed, 16 Dec 2020 12:22:37 -0500 Received: by simark.ca (Postfix, from userid 112) id 746D11F0AA; Wed, 16 Dec 2020 12:22:37 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [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 D46A21E552 for ; Wed, 16 Dec 2020 12:22:36 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67B18387089C; Wed, 16 Dec 2020 17:22:36 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id C4755386F441 for ; Wed, 16 Dec 2020 17:22:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C4755386F441 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C133AAC7B; Wed, 16 Dec 2020 17:22:31 +0000 (UTC) Subject: Re: [PATCH][gdb/testsuite] Fix shlib compilation with target board unix/-pie/-fPIE To: Simon Marchi , gdb-patches@sourceware.org References: <20201213164131.GA7699@delia> <60fb40c8-73ca-e6de-e45f-805fba548f88@simark.ca> From: Tom de Vries Message-ID: <1a23f50f-bf4f-ae09-7ff5-b23e59d6438b@suse.de> Date: Wed, 16 Dec 2020 18:22:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <60fb40c8-73ca-e6de-e45f-805fba548f88@simark.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US 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 12/14/20 6:21 PM, Simon Marchi wrote: > 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. > Thanks for the review. I copied this code from gdb_do_cache_wrap, so I left it as is for the commit. This sounds like a good idea for a more broad refactoring. Thanks, - Tom > Otherwise, LGTM. > > Simon >