diff mbox

[v3] configure: Simplify alternate .text segment

Message ID 1371867016-7660-1-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson June 22, 2013, 2:10 a.m. UTC
For bsd-user and linux-user emulation modes QEMU needs to be linked at an
alternate .text segment address, so that it's out of the way of the guest
executable.  Instead of including modified linker scripts for each arch,
just set the address with -Ttext-segment if supported, or by using sed to
edit the default linker script.

Cc: Ed Maste <emaste@freebsd.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 configure | 48 +++++++++++++++++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 18 deletions(-)
--

Changes v2-v3:
  * Move the check for textseg_ldflags much earlier in the configure file,
    so that we've not got cflags invalid for configure time.  Plus, the
    check (and generated ld script) only gets done once, not once per
    target directory.
  * Remove ia64 from the hosts that get relocation
  * Handle s390x like s390.

Tested on x86_64, arm, hppa (old binutils needing config-host.ld),
sparc64, and ia64.  All various versions of linux.


r~

Comments

Peter Maydell June 22, 2013, 10:58 a.m. UTC | #1
On 22 June 2013 03:10, Richard Henderson <rth@twiddle.net> wrote:
> +  ldflags="$ldflags $textseg_ldflags"
>  fi
>
>  echo "LDFLAGS+=$ldflags" >> $config_target_mak

Should we really be putting this in LDFLAGS? That seems
likely to end up getting accidentally applied in places
where we don't want it (helper binaries, etc). It seems
like it would be more robust to have it in a special
variable which we only ever explicitly apply to linking
the foo-linux-user binary.

thanks
-- PMM
Richard Henderson June 23, 2013, 6:20 p.m. UTC | #2
On 06/22/2013 03:58 AM, Peter Maydell wrote:
> On 22 June 2013 03:10, Richard Henderson <rth@twiddle.net> wrote:
>> +  ldflags="$ldflags $textseg_ldflags"
>>  fi
>>
>>  echo "LDFLAGS+=$ldflags" >> $config_target_mak
> 
> Should we really be putting this in LDFLAGS? That seems
> likely to end up getting accidentally applied in places
> where we don't want it (helper binaries, etc). It seems
> like it would be more robust to have it in a special
> variable which we only ever explicitly apply to linking
> the foo-linux-user binary.

This is within the target subdir, not in the main top level.  So... What helper
binaries?

Modifying ldflags is what we do now.  If you think that we should change to a
different variable, then I think that should be a separate change.


r~
Peter Maydell June 23, 2013, 6:22 p.m. UTC | #3
On 23 June 2013 19:20, Richard Henderson <rth@twiddle.net> wrote:
> On 06/22/2013 03:58 AM, Peter Maydell wrote:
>> Should we really be putting this in LDFLAGS? That seems
>> likely to end up getting accidentally applied in places
>> where we don't want it (helper binaries, etc). It seems
>> like it would be more robust to have it in a special
>> variable which we only ever explicitly apply to linking
>> the foo-linux-user binary.
>
> This is within the target subdir, not in the main top level.

Ah, I hadn't noticed that. Fair enough.

-- PMM
Ed Maste June 24, 2013, 7:45 p.m. UTC | #4
On 21 June 2013 22:10, Richard Henderson <rth@twiddle.net> wrote:
> For bsd-user and linux-user emulation modes QEMU needs to be linked at an
> alternate .text segment address, so that it's out of the way of the guest
> executable.  Instead of including modified linker scripts for each arch,
> just set the address with -Ttext-segment if supported, or by using sed to
> edit the default linker script.
>
> Cc: Ed Maste <emaste@freebsd.org>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  configure | 48 +++++++++++++++++++++++++++++++-----------------
>  2 files changed, 31 insertions(+), 18 deletions(-)
> --
>
> Changes v2-v3:
>   * Move the check for textseg_ldflags much earlier in the configure file,
>     so that we've not got cflags invalid for configure time.  Plus, the
>     check (and generated ld script) only gets done once, not once per
>     target directory.
>   * Remove ia64 from the hosts that get relocation
>   * Handle s390x like s390.

Thanks for cleaning this up.  Tested on x86_64 FreeBSD with base
system (old) binutils.

Acked-by: Ed Maste <emaste@freebsd.org>
Or if you prefer, for my contribution to this version,
Signed-off-by: Ed Maste <emaste@freebsd.org>
Richard Henderson July 2, 2013, 3:12 p.m. UTC | #5
Ping.

On 06/21/2013 07:10 PM, Richard Henderson wrote:
> For bsd-user and linux-user emulation modes QEMU needs to be linked at an
> alternate .text segment address, so that it's out of the way of the guest
> executable.  Instead of including modified linker scripts for each arch,
> just set the address with -Ttext-segment if supported, or by using sed to
> edit the default linker script.
> 
> Cc: Ed Maste <emaste@freebsd.org>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  configure | 48 +++++++++++++++++++++++++++++++-----------------
>  2 files changed, 31 insertions(+), 18 deletions(-)
> --
> 
> Changes v2-v3:
>   * Move the check for textseg_ldflags much earlier in the configure file,
>     so that we've not got cflags invalid for configure time.  Plus, the
>     check (and generated ld script) only gets done once, not once per
>     target directory.
>   * Remove ia64 from the hosts that get relocation
>   * Handle s390x like s390.
> 
> Tested on x86_64, arm, hppa (old binutils needing config-host.ld),
> sparc64, and ia64.  All various versions of linux.
> 
> 
> r~
> 
> 
> 
> diff --git a/configure b/configure
> index ad32f87..63da418 100755
> --- a/configure
> +++ b/configure
> @@ -3444,6 +3444,36 @@ if test "$cpu" = "s390x" ; then
>    roms="$roms s390-ccw"
>  fi
>  
> +# Probe for the need for relocating the user-only binary.
> +if test "$pie" = "no" ; then
> +  textseg_addr=
> +  case "$cpu" in
> +    arm | hppa | i386 | m68k | ppc | ppc64 | s390* | sparc | sparc64 | x86_64)
> +      textseg_addr=0x60000000
> +      ;;
> +    mips)
> +      textseg_addr=0x400000
> +      ;;
> +  esac
> +  if [ -n "$textseg_addr" ]; 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.
> +      $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
> +
>  # add pixman flags after all config tests are done
>  QEMU_CFLAGS="$QEMU_CFLAGS $pixman_cflags $fdt_cflags"
>  libs_softmmu="$libs_softmmu $pixman_libs"
> @@ -4072,9 +4102,6 @@ if test "$gcov" = "yes" ; then
>    echo "GCOV=$gcov_tool" >> $config_host_mak
>  fi
>  
> -# generate list of library paths for linker script
> -$ld --verbose -v 2> /dev/null | grep SEARCH_DIR > config-host.ld
> -
>  # use included Linux headers
>  if test "$linux" = "yes" ; then
>    mkdir -p linux-headers
> @@ -4437,21 +4464,8 @@ if test "$gprof" = "yes" ; then
>    fi
>  fi
>  
> -if test "$ARCH" = "tci"; then
> -  linker_script=""
> -else
> -  linker_script="-Wl,-T../config-host.ld -Wl,-T,\$(SRC_PATH)/ldscripts/\$(ARCH).ld"
> -fi
> -
>  if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
> -  case "$ARCH" in
> -  alpha | s390x | aarch64)
> -    # The default placement of the application is fine.
> -    ;;
> -  *)
> -    ldflags="$linker_script $ldflags"
> -    ;;
> -  esac
> +  ldflags="$ldflags $textseg_ldflags"
>  fi
>  
>  echo "LDFLAGS+=$ldflags" >> $config_target_mak
>
Richard Henderson July 9, 2013, 3:43 p.m. UTC | #6
Ping 2.

On 07/02/2013 08:12 AM, Richard Henderson wrote:
> Ping.
> 
> On 06/21/2013 07:10 PM, Richard Henderson wrote:
>> For bsd-user and linux-user emulation modes QEMU needs to be linked at an
>> alternate .text segment address, so that it's out of the way of the guest
>> executable.  Instead of including modified linker scripts for each arch,
>> just set the address with -Ttext-segment if supported, or by using sed to
>> edit the default linker script.
>>
>> Cc: Ed Maste <emaste@freebsd.org>
>> Signed-off-by: Richard Henderson <rth@twiddle.net>
>> ---
>>  configure | 48 +++++++++++++++++++++++++++++++-----------------
>>  2 files changed, 31 insertions(+), 18 deletions(-)
>> --
>>
>> Changes v2-v3:
>>   * Move the check for textseg_ldflags much earlier in the configure file,
>>     so that we've not got cflags invalid for configure time.  Plus, the
>>     check (and generated ld script) only gets done once, not once per
>>     target directory.
>>   * Remove ia64 from the hosts that get relocation
>>   * Handle s390x like s390.
>>
>> Tested on x86_64, arm, hppa (old binutils needing config-host.ld),
>> sparc64, and ia64.  All various versions of linux.
>>
>>
>> r~
>>
>>
>>
>> diff --git a/configure b/configure
>> index ad32f87..63da418 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3444,6 +3444,36 @@ if test "$cpu" = "s390x" ; then
>>    roms="$roms s390-ccw"
>>  fi
>>  
>> +# Probe for the need for relocating the user-only binary.
>> +if test "$pie" = "no" ; then
>> +  textseg_addr=
>> +  case "$cpu" in
>> +    arm | hppa | i386 | m68k | ppc | ppc64 | s390* | sparc | sparc64 | x86_64)
>> +      textseg_addr=0x60000000
>> +      ;;
>> +    mips)
>> +      textseg_addr=0x400000
>> +      ;;
>> +  esac
>> +  if [ -n "$textseg_addr" ]; 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.
>> +      $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
>> +
>>  # add pixman flags after all config tests are done
>>  QEMU_CFLAGS="$QEMU_CFLAGS $pixman_cflags $fdt_cflags"
>>  libs_softmmu="$libs_softmmu $pixman_libs"
>> @@ -4072,9 +4102,6 @@ if test "$gcov" = "yes" ; then
>>    echo "GCOV=$gcov_tool" >> $config_host_mak
>>  fi
>>  
>> -# generate list of library paths for linker script
>> -$ld --verbose -v 2> /dev/null | grep SEARCH_DIR > config-host.ld
>> -
>>  # use included Linux headers
>>  if test "$linux" = "yes" ; then
>>    mkdir -p linux-headers
>> @@ -4437,21 +4464,8 @@ if test "$gprof" = "yes" ; then
>>    fi
>>  fi
>>  
>> -if test "$ARCH" = "tci"; then
>> -  linker_script=""
>> -else
>> -  linker_script="-Wl,-T../config-host.ld -Wl,-T,\$(SRC_PATH)/ldscripts/\$(ARCH).ld"
>> -fi
>> -
>>  if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
>> -  case "$ARCH" in
>> -  alpha | s390x | aarch64)
>> -    # The default placement of the application is fine.
>> -    ;;
>> -  *)
>> -    ldflags="$linker_script $ldflags"
>> -    ;;
>> -  esac
>> +  ldflags="$ldflags $textseg_ldflags"
>>  fi
>>  
>>  echo "LDFLAGS+=$ldflags" >> $config_target_mak
>>
>
Anthony Liguori July 10, 2013, 7:33 p.m. UTC | #7
Applied.  Thanks.

Regards,

Anthony Liguori
Stefan Weil Jan. 7, 2015, 6:02 p.m. UTC | #8
Hello,

this patch which is part of QEMU for more than a year now needs to be 
fixed for builds on Mac OS X:

I just saw that the Mac's native linker ld does not support --verbose, 
but shows a warning.
Would it be sufficient to redirect that warning to /dev/null (as it was 
done in the previous code)?

Regards
Stefan



Am 22.06.2013 um 04:10 schrieb Richard Henderson:
> For bsd-user and linux-user emulation modes QEMU needs to be linked at an
> alternate .text segment address, so that it's out of the way of the guest
> executable.  Instead of including modified linker scripts for each arch,
> just set the address with -Ttext-segment if supported, or by using sed to
> edit the default linker script.
>
> Cc: Ed Maste <emaste@freebsd.org>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>   configure | 48 +++++++++++++++++++++++++++++++-----------------
>   2 files changed, 31 insertions(+), 18 deletions(-)
> --
>
> Changes v2-v3:
>    * Move the check for textseg_ldflags much earlier in the configure file,
>      so that we've not got cflags invalid for configure time.  Plus, the
>      check (and generated ld script) only gets done once, not once per
>      target directory.
>    * Remove ia64 from the hosts that get relocation
>    * Handle s390x like s390.
>
> Tested on x86_64, arm, hppa (old binutils needing config-host.ld),
> sparc64, and ia64.  All various versions of linux.
>
>
> r~
>
>
>
> diff --git a/configure b/configure
> index ad32f87..63da418 100755
> --- a/configure
> +++ b/configure
> @@ -3444,6 +3444,36 @@ if test "$cpu" = "s390x" ; then
>     roms="$roms s390-ccw"
>   fi
>   
> +# Probe for the need for relocating the user-only binary.
> +if test "$pie" = "no" ; then
> +  textseg_addr=
> +  case "$cpu" in
> +    arm | hppa | i386 | m68k | ppc | ppc64 | s390* | sparc | sparc64 | x86_64)
> +      textseg_addr=0x60000000
> +      ;;
> +    mips)
> +      textseg_addr=0x400000
> +      ;;
> +  esac
> +  if [ -n "$textseg_addr" ]; 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.
> +      $ld --verbose | sed \

This $ld --verbose raises a warning when configure is run.


> +        -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
> +
>   # add pixman flags after all config tests are done
>   QEMU_CFLAGS="$QEMU_CFLAGS $pixman_cflags $fdt_cflags"
>   libs_softmmu="$libs_softmmu $pixman_libs"
> @@ -4072,9 +4102,6 @@ if test "$gcov" = "yes" ; then
>     echo "GCOV=$gcov_tool" >> $config_host_mak
>   fi
>   
> -# generate list of library paths for linker script
> -$ld --verbose -v 2> /dev/null | grep SEARCH_DIR > config-host.ld

The old code redirected stderr, so any warning was not visible.

> -
>   # use included Linux headers
>   if test "$linux" = "yes" ; then
>     mkdir -p linux-headers
> @@ -4437,21 +4464,8 @@ if test "$gprof" = "yes" ; then
>     fi
>   fi
>   
> -if test "$ARCH" = "tci"; then
> -  linker_script=""
> -else
> -  linker_script="-Wl,-T../config-host.ld -Wl,-T,\$(SRC_PATH)/ldscripts/\$(ARCH).ld"
> -fi
> -
>   if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
> -  case "$ARCH" in
> -  alpha | s390x | aarch64)
> -    # The default placement of the application is fine.
> -    ;;
> -  *)
> -    ldflags="$linker_script $ldflags"
> -    ;;
> -  esac
> +  ldflags="$ldflags $textseg_ldflags"
>   fi
>   
>   echo "LDFLAGS+=$ldflags" >> $config_target_mak
Richard Henderson Jan. 7, 2015, 6:44 p.m. UTC | #9
On 01/07/2015 10:02 AM, Stefan Weil wrote:
> Would it be sufficient to redirect that warning to /dev/null (as it was done in
> the previous code)?

Probably.


r~
Peter Maydell Jan. 7, 2015, 8:37 p.m. UTC | #10
On 7 January 2015 at 18:02, Stefan Weil <sw@weilnetz.de> wrote:
> Hello,
>
> this patch which is part of QEMU for more than a year now needs to be fixed
> for builds on Mac OS X:

> I just saw that the Mac's native linker ld does not support --verbose, but
> shows a warning.

Cosmetically ugly, but not a show stopper :-) I haven't noticed
it in a year of building OSX...

> Would it be sufficient to redirect that warning to /dev/null (as it was done
> in the previous code)?

The other option would be to just skip the test unless we're building
one of the linux-user or bsd-user targets : we'll never build either
on OSX.

-- PMM
diff mbox

Patch

diff --git a/configure b/configure
index ad32f87..63da418 100755
--- a/configure
+++ b/configure
@@ -3444,6 +3444,36 @@  if test "$cpu" = "s390x" ; then
   roms="$roms s390-ccw"
 fi
 
+# Probe for the need for relocating the user-only binary.
+if test "$pie" = "no" ; then
+  textseg_addr=
+  case "$cpu" in
+    arm | hppa | i386 | m68k | ppc | ppc64 | s390* | sparc | sparc64 | x86_64)
+      textseg_addr=0x60000000
+      ;;
+    mips)
+      textseg_addr=0x400000
+      ;;
+  esac
+  if [ -n "$textseg_addr" ]; 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.
+      $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
+
 # add pixman flags after all config tests are done
 QEMU_CFLAGS="$QEMU_CFLAGS $pixman_cflags $fdt_cflags"
 libs_softmmu="$libs_softmmu $pixman_libs"
@@ -4072,9 +4102,6 @@  if test "$gcov" = "yes" ; then
   echo "GCOV=$gcov_tool" >> $config_host_mak
 fi
 
-# generate list of library paths for linker script
-$ld --verbose -v 2> /dev/null | grep SEARCH_DIR > config-host.ld
-
 # use included Linux headers
 if test "$linux" = "yes" ; then
   mkdir -p linux-headers
@@ -4437,21 +4464,8 @@  if test "$gprof" = "yes" ; then
   fi
 fi
 
-if test "$ARCH" = "tci"; then
-  linker_script=""
-else
-  linker_script="-Wl,-T../config-host.ld -Wl,-T,\$(SRC_PATH)/ldscripts/\$(ARCH).ld"
-fi
-
 if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
-  case "$ARCH" in
-  alpha | s390x | aarch64)
-    # The default placement of the application is fine.
-    ;;
-  *)
-    ldflags="$linker_script $ldflags"
-    ;;
-  esac
+  ldflags="$ldflags $textseg_ldflags"
 fi
 
 echo "LDFLAGS+=$ldflags" >> $config_target_mak