From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id XVaOL0RE1l9vNQAAWB0awg (envelope-from ) for ; Sun, 13 Dec 2020 11:41:40 -0500 Received: by simark.ca (Postfix, from userid 112) id B5D6B1F0AA; Sun, 13 Dec 2020 11:41:40 -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 4CBA01E965 for ; Sun, 13 Dec 2020 11:41:40 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0E1A386102B; Sun, 13 Dec 2020 16:41:39 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 61BDF3861035 for ; Sun, 13 Dec 2020 16:41:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 61BDF3861035 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 41F70AC10 for ; Sun, 13 Dec 2020 16:41:34 +0000 (UTC) Date: Sun, 13 Dec 2020 17:41:32 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/testsuite] Fix shlib compilation with target board unix/-pie/-fPIE Message-ID: <20201213164131.GA7699@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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" 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 +} + # This is just like gdb_compile_shlib, above, except that it tries compiling # against several different thread libraries, to see which one this # system has.