From a35f9a13a80fa93c251e12402a73a38a89ec397f Mon Sep 17 00:00:00 2001 From: Michael Cronenworth Date: Wed, 21 Oct 2015 20:54:38 -0500 Subject: [PATCH] winegcc: Check for linker relocation support before relying on prelink. Prelink was used to rewrite binares and set their text segment, but modern linkers support setting the value at link time. Prelink is being retired by upstream. Signed-off-by: Michael Cronenworth Signed-off-by: Alexandre Julliard --- configure | 36 +++++++++++++++++++++++++++++++----- configure.ac | 11 ++++++----- tools/winegcc/winegcc.c | 13 ++++++++++--- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/configure b/configure index 6689b65d1ec..f21a860170d 100755 --- a/configure +++ b/configure @@ -8678,7 +8678,32 @@ if test "x$ac_cv_cflags__Wl___section_start__interp_0x7bf00400" = xyes; then : esac fi - # Extract the first word of "prelink", so it can be a program name with args. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports -Wl,-Ttext-segment=0x7bc00000" >&5 +$as_echo_n "checking whether the compiler supports -Wl,-Ttext-segment=0x7bc00000... " >&6; } +if ${ac_cv_cflags__Wl__Ttext_segment_0x7bc00000+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_wine_try_cflags_saved=$CFLAGS +CFLAGS="$CFLAGS -Wl,-Ttext-segment=0x7bc00000" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int main(int argc, char **argv) { return 0; } +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_cflags__Wl__Ttext_segment_0x7bc00000=yes +else + ac_cv_cflags__Wl__Ttext_segment_0x7bc00000=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +CFLAGS=$ac_wine_try_cflags_saved +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cflags__Wl__Ttext_segment_0x7bc00000" >&5 +$as_echo "$ac_cv_cflags__Wl__Ttext_segment_0x7bc00000" >&6; } +if test "x$ac_cv_cflags__Wl__Ttext_segment_0x7bc00000" = xyes; then : + : +else + # Extract the first word of "prelink", so it can be a program name with args. set dummy prelink; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } @@ -8719,10 +8744,11 @@ $as_echo "no" >&6; } fi - if test "x$PRELINK" = xfalse - then - as_fn_append wine_warnings "|prelink not found, base address of core dlls won't be set correctly." - fi + if test "x$PRELINK" = xfalse + then + as_fn_append wine_warnings "|prelink not found and linker does not support relocation, base address of core dlls won't be set correctly." + fi +fi ;; esac diff --git a/configure.ac b/configure.ac index 030aa32eb29..a209fa1bebc 100644 --- a/configure.ac +++ b/configure.ac @@ -988,11 +988,12 @@ wine-installed: main.o *) LDEXECFLAGS="$LDEXECFLAGS -Wl,--section-start,.interp=0x7bf00400" ;; esac ]) - AC_PATH_PROG(PRELINK, prelink, false, [/sbin /usr/sbin $PATH]) - if test "x$PRELINK" = xfalse - then - WINE_WARNING([prelink not found, base address of core dlls won't be set correctly.]) - fi + WINE_TRY_CFLAGS([-Wl,-Ttext-segment=0x7bc00000],[:], + [AC_PATH_PROG(PRELINK, prelink, false, [/sbin /usr/sbin $PATH]) + if test "x$PRELINK" = xfalse + then + WINE_WARNING([prelink not found and linker does not support relocation, base address of core dlls won't be set correctly.]) + fi]) ;; esac diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index 3b2794e8c0c..ad139f5c4ce 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -776,6 +776,7 @@ static void build(struct options* opts) char *output_file; const char *spec_o_name; const char *output_name, *spec_file, *lang; + const char *prelink = NULL; int generate_app_loader = 1; int fake_module = 0; unsigned int j; @@ -1134,6 +1135,13 @@ static void build(struct options* opts) } break; default: + if (opts->image_base) + { + if (!try_link(opts->prefix, link_args, strmake("-Wl,-Ttext-segment=%s", opts->image_base))) + strarray_add(link_args, strmake("-Wl,-Ttext-segment=%s", opts->image_base)); + else + prelink = PRELINK; + } break; } @@ -1167,10 +1175,9 @@ static void build(struct options* opts) spawn(opts->prefix, link_args, 0); strarray_free (link_args); - /* set the base address */ - if (opts->image_base && !opts->target) + /* set the base address with prelink if linker support is not present */ + if (prelink && !opts->target) { - const char *prelink = PRELINK; if (prelink[0] && strcmp(prelink,"false")) { strarray *prelink_args = strarray_alloc();