From: Simon Marchi <simark@simark.ca>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH][gdb/testsuite] Fix shlib compilation with target board unix/-pie/-fPIE
Date: Mon, 14 Dec 2020 12:21:51 -0500 [thread overview]
Message-ID: <60fb40c8-73ca-e6de-e45f-805fba548f88@simark.ca> (raw)
In-Reply-To: <20201213164131.GA7699@delia>
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
next prev parent reply other threads:[~2020-12-14 17:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-13 16:41 Tom de Vries
2020-12-14 17:21 ` Simon Marchi [this message]
2020-12-16 17:22 ` Tom de Vries
2020-12-19 17:44 ` Tom de Vries
2020-12-20 2:29 ` Simon Marchi via Gdb-patches
2020-12-20 8:37 ` [committed][gdb/testsuite] Add save_target_board_info Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=60fb40c8-73ca-e6de-e45f-805fba548f88@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tdevries@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox