qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Richard Henderson" <rth@twiddle.net>
Subject: Re: [PATCH] configure: Use lld --image-base for --disable-pie user mode binaries
Date: Wed, 27 Nov 2019 19:01:05 +0000	[thread overview]
Message-ID: <87woblf8jy.fsf@linaro.org> (raw)
In-Reply-To: <20191116052815.nop3xkmd4umqsdsb@google.com>


Fangrui Song <i@maskray.me> writes:

> For lld, --image-base is the preferred way to set the base address.
> lld does not actually implement -Ttext-segment, but treats it as an alias for
> -Ttext. -Ttext-segment=0x60000000 combined with --no-rosegment can
> create a 1.6GB executable.
>
> Fix the problem by using --image-base for lld. GNU ld and gold will
> still get -Ttext-segment. Also delete the ld --verbose fallback introduced
> in 2013, which is no longer relevant or correct (the default linker
> script has changed).
>
> Signed-off-by: Fangrui Song <i@maskray.me>

This patch no longer applies cleanly to configure so I couldn't test it.

> ---
>   configure | 33 ++++++++++++---------------------
>   1 file changed, 12 insertions(+), 21 deletions(-)
>
> diff --git a/configure b/configure
> index 6099be1d84..2d45af0d09 100755
> --- a/configure
> +++ b/configure
> @@ -6336,43 +6336,34 @@ fi
>   
>   # Probe for the need for relocating the user-only binary.
>   if ( [ "$linux_user" = yes ] || [ "$bsd_user" = yes ] ) && [ "$pie" = no ]; then
> -  textseg_addr=
> +  image_base=
>     case "$cpu" in
>       arm | i386 | ppc* | s390* | sparc* | x86_64 | x32)
> -      # ??? Rationale for choosing this address
> -      textseg_addr=0x60000000
> +      # An arbitrary address that makes it unlikely to collide with user
> +      # programs.
> +      image_base=0x60000000

The comment probably belongs up above when we define the empty variable
unless it really is specifically about these targets.

Renaming textseg_addr seems like unnecessary churn for this patch. 

>         ;;
>       mips)
>         # A 256M aligned address, high in the address space, with enough
>         # room for the code_gen_buffer above it before the stack.
> -      textseg_addr=0x60000000
> +      image_base=0x60000000
>         ;;
>     esac
> -  if [ -n "$textseg_addr" ]; then
> +  if [ -n "$image_base" ]; then
>       cat > $TMPC <<EOF
>       int main(void) { return 0; }
>   EOF
> -    textseg_ldflags="-Wl,-Ttext-segment=$textseg_addr"
> -    if ! compile_prog "" "$textseg_ldflags"; then
> -      # In case ld does not support -Ttext-segment, edit the default linker
> -      # script via sed to set the .text start addr.  This is needed on FreeBSD
> -      # at least.
> -      if ! $ld --verbose >/dev/null 2>&1; then
> +    image_base_ldflags="-Wl,--image-base=$image_base"
> +    if ! compile_prog "" "$image_base_ldflags"; then
> +      image_base_ldflags="-Wl,-Ttext-segment=$image_base"
> +      if ! compile_prog "" "$image_base_ldflags"; then
>           error_exit \
>               "We need to link the QEMU user mode binaries at a" \
>               "specific text address. Unfortunately your linker" \
> -            "doesn't support either the -Ttext-segment option or" \
> -            "printing the default linker script with --verbose." \
> +            "supports neither --image-base nor -Ttext-segment. " \
>               "If you don't want the user mode binaries, pass the" \
>               "--disable-user option to configure."
>         fi
> -
> -      $ld --verbose | sed \
> -        -e '1,/==================================================/d' \
> -        -e '/==================================================/,$d' \
> -        -e "s/[.] = [0-9a-fx]* [+] SIZEOF_HEADERS/. = $textseg_addr + SIZEOF_HEADERS/" \
> -        -e "s/__executable_start = [0-9a-fx]*/__executable_start = $textseg_addr/" > config-host.ld
> -      textseg_ldflags="-Wl,-T../config-host.ld"
>       fi
>     fi
>   fi
> @@ -7945,7 +7936,7 @@ if test "$gprof" = "yes" ; then
>   fi
>   
>   if test "$target_linux_user" = "yes" || test "$target_bsd_user" = "yes" ; then
> -  ldflags="$ldflags $textseg_ldflags"
> +  ldflags="$ldflags $image_base_ldflags"
>   fi
>   
>   # Newer kernels on s390 check for an S390_PGSTE program header and


-- 
Alex Bennée


      parent reply	other threads:[~2019-11-27 19:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-16  5:28 [PATCH] configure: Use lld --image-base for --disable-pie user mode binaries Fangrui Song
2019-11-20 21:02 ` Fangrui Song
2019-11-27 18:36   ` Fangrui Song
2019-12-01 21:48     ` Richard Henderson
2019-12-02  4:06       ` Fangrui Song
2019-12-10  7:10         ` Fangrui Song
2019-12-17  7:11           ` Fangrui Song
2019-11-27 19:01 ` Alex Bennée [this message]

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=87woblf8jy.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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;
as well as URLs for NNTP newsgroup(s).