|
From: <sv...@va...> - 2010-06-14 00:02:37
|
Author: sewardj
Date: 2010-06-14 01:02:27 +0100 (Mon, 14 Jun 2010)
New Revision: 11175
Log:
Merge from trunk, r11174 (remove link_tool_exe.c and replace it with
perl scripts that do the same thing) and parts of 11164/11169
(check for --build-id=none at configure time).
Added:
branches/MACOSX106/coregrind/link_tool_exe_aix5.in
branches/MACOSX106/coregrind/link_tool_exe_darwin.in
branches/MACOSX106/coregrind/link_tool_exe_linux.in
Removed:
branches/MACOSX106/coregrind/link_tool_exe.c
Modified:
branches/MACOSX106/Makefile.tool.am
branches/MACOSX106/cachegrind/Makefile.am
branches/MACOSX106/callgrind/Makefile.am
branches/MACOSX106/configure.in
branches/MACOSX106/coregrind/Makefile.am
branches/MACOSX106/drd/Makefile.am
branches/MACOSX106/exp-bbv/Makefile.am
branches/MACOSX106/exp-ptrcheck/Makefile.am
branches/MACOSX106/helgrind/Makefile.am
branches/MACOSX106/lackey/Makefile.am
branches/MACOSX106/massif/Makefile.am
branches/MACOSX106/memcheck/Makefile.am
branches/MACOSX106/none/Makefile.am
Modified: branches/MACOSX106/Makefile.tool.am
===================================================================
--- branches/MACOSX106/Makefile.tool.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/Makefile.tool.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -26,13 +26,16 @@
endif
+# -Wl,--build-id=none is needed when linking tools on Linux. Without this
+# flag newer ld versions (2.20 and later) create a .note.gnu.build-id at the
+# default text segment address, which of course means the resulting executable
+# is unusable. So we have to tell ld not to generate that, with --build-id=none.
TOOL_LDFLAGS_COMMON_LINUX = \
- -static -nodefaultlibs -nostartfiles -u _start
+ -static -nodefaultlibs -nostartfiles -u _start @FLAG_NO_BUILD_ID@
TOOL_LDFLAGS_COMMON_AIX5 = \
-static -Wl,-e_start_valgrind
TOOL_LDFLAGS_COMMON_DARWIN = \
- -nodefaultlibs -nostartfiles \
- -Wl,-u,__start -Wl,-e,__start -Wl,-bind_at_load /usr/lib/dyld
+ -nodefaultlibs -nostartfiles -Wl,-u,__start -Wl,-e,__start
TOOL_LDFLAGS_X86_LINUX = \
$(TOOL_LDFLAGS_COMMON_LINUX) @FLAG_M32@
Modified: branches/MACOSX106/cachegrind/Makefile.am
===================================================================
--- branches/MACOSX106/cachegrind/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/cachegrind/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -59,7 +59,7 @@
cachegrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
cachegrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(cachegrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -79,7 +79,7 @@
cachegrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
cachegrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(cachegrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/callgrind/Makefile.am
===================================================================
--- branches/MACOSX106/callgrind/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/callgrind/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -66,7 +66,7 @@
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -86,7 +86,7 @@
callgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
callgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(callgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/configure.in
===================================================================
--- branches/MACOSX106/configure.in 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/configure.in 2010-06-14 00:02:27 UTC (rev 11175)
@@ -251,11 +251,6 @@
VGCONF_OS="aix5"
;;
- *freebsd*)
- AC_MSG_RESULT([ok (${host_os})])
- VGCONF_OS="freebsd"
- ;;
-
*darwin*)
AC_MSG_RESULT([ok (${host_os})])
VGCONF_OS="darwin"
@@ -1335,6 +1330,28 @@
CFLAGS=$safe_CFLAGS
+# does the linker support -Wl,--build-id=none ? Note, it's
+# important that we test indirectly via whichever C compiler
+# is selected, rather than testing /usr/bin/ld or whatever
+# directly.
+
+AC_MSG_CHECKING([if the linker accepts -Wl,--build-id=none])
+
+safe_CFLAGS=$CFLAGS
+CFLAGS="-Wl,--build-id=none"
+
+AC_LINK_IFELSE(
+[AC_LANG_PROGRAM([ ], [return 0;])],
+[
+ AC_SUBST([FLAG_NO_BUILD_ID], ["-Wl,--build-id=none"])
+ AC_MSG_RESULT([yes])
+], [
+ AC_SUBST([FLAG_NO_BUILD_ID], [""])
+ AC_MSG_RESULT([no])
+])
+CFLAGS=$safe_CFLAGS
+
+
# does the ppc assembler support "mtocrf" et al?
AC_MSG_CHECKING([if ppc32/64 as supports mtocrf/mfocrf])
@@ -1902,6 +1919,12 @@
exp-bbv/tests/ppc32-linux/Makefile
exp-bbv/tests/arm-linux/Makefile
])
+AC_CONFIG_FILES([coregrind/link_tool_exe_linux],
+ [chmod +x coregrind/link_tool_exe_linux])
+AC_CONFIG_FILES([coregrind/link_tool_exe_darwin],
+ [chmod +x coregrind/link_tool_exe_darwin])
+AC_CONFIG_FILES([coregrind/link_tool_exe_aix5],
+ [chmod +x coregrind/link_tool_exe_aix5])
AC_OUTPUT
cat<<EOF
Modified: branches/MACOSX106/coregrind/Makefile.am
===================================================================
--- branches/MACOSX106/coregrind/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/coregrind/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -430,27 +430,6 @@
endif
#----------------------------------------------------------------------------
-# link_tool_exe, the wrapper for the system linker
-#----------------------------------------------------------------------------
-
-noinst_PROGRAMS += link_tool_exe
-
-link_tool_exe_SOURCES = link_tool_exe.c
-link_tool_exe_CPPFLAGS = $(AM_CPPFLAGS_PRI)
-link_tool_exe_CFLAGS = $(AM_CFLAGS_PRI)
-link_tool_exe_CCASFLAGS = $(AM_CCASFLAGS_PRI)
-link_tool_exe_LDFLAGS = $(AM_CFLAGS_PRI)
-
-# force link_tool_exe to be built before libcoregrind.a is, and hence
-# before any of the tool executables are linked, since they in turn
-# are dependent on libcoregrind.a. Unfortunately this doesn't give a
-# dependence on link_tool_exe.c: ideally if link_tool_exe.c is
-# changed, then 'make' rebuilds link_tool_exe, but the tool
-# executables themselves are not relinked. I can't figure out how
-# to get that to happen.
-BUILT_SOURCES += link_tool_exe
-
-#----------------------------------------------------------------------------
# General stuff
#----------------------------------------------------------------------------
Deleted: branches/MACOSX106/coregrind/link_tool_exe.c
===================================================================
--- branches/MACOSX106/coregrind/link_tool_exe.c 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/coregrind/link_tool_exe.c 2010-06-14 00:02:27 UTC (rev 11175)
@@ -1,294 +0,0 @@
-
-/* This program handles linking the tool executables, statically and
- at an alternative load address. Linking them statically sidesteps
- all sorts of complications to do with having two copies of the
- dynamic linker (valgrind's and the client's) coexisting in the same
- process. The alternative load address is needed because Valgrind
- itself will load the client at whatever address it specifies, which
- is almost invariably the default load address. Hence we can't
- allow Valgrind itself (viz, the tool executable) to be loaded at
- that address.
-
- Unfortunately there's no standard way to do 'static link at
- alternative address', so this program handles the per-platform
- hoop-jumping.
-*/
-
-/* What we get passed here is:
- first arg
- the alternative load address
- all the rest of the args
- the gcc invokation to do the final link, that
- the build system would have done, left to itself
-
- We just let assertions fail rather than do proper error reporting.
- We don't expect the users to run this directly. It is only run
- from as part of the build process, with carefully constrained
- inputs.
-*/
-
-/* ------------------------- LINUX ------------------------- */
-
-#if defined(VGO_linux)
-
-/* Scheme is simple: pass the specified command to the linker as-is,
- except, add "-static" and "-Ttext=<argv[1]>" to it.
-
- Also apparently we need --build-id=none. For older ld's (2.18
- vintage) the first two flags are fine. For newer ones (2.20), a
- .note.gnu.build-id is nevertheless created at the default text
- segment address, which of course means the resulting executable is
- unusable. So we have to tell ld not to generate that, with
- --build-id=none.
-
- As to "how far back is this flag supported", it's available at
- least in ld 2.18 and 2.20 and gold 2.20.
-*/
-
-// Don't NDEBUG this; the asserts are necesary for
-// safety checks.
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/wait.h> /* WEXITSTATUS */
-
-int main ( int argc, char** argv )
-{
- int i;
- int/*bool*/ failed = 0;
- size_t reqd = 0;
-
- // expect at least: alt-load-address gcc -o foo bar.o
- assert(argc > 5);
-
- // check for plausible-ish alt load address
- char* ala = argv[1];
- assert(ala[0] == '0');
- assert(ala[1] == 'x');
-
- // We'll need to invoke this to do the linking
- char* gcc = argv[2];
-
- // and the 'restargs' are argv[3 ..]
-
- // so, build up the complete command here:
- // 'gcc' -static -Ttext='ala' 'restargs'
-
- // first, do length safety checks
- reqd += 1+ strlen(gcc);
- reqd += 1+ 100/*let's say*/ + strlen(ala);
- for (i = 3; i < argc; i++)
- reqd += 1+ strlen(argv[i]);
-
- reqd += 1;
- char* cmd = calloc(reqd,1);
- assert(cmd);
-
- char ttext[100];
- assert(strlen(ala) < 30);
- memset(ttext, 0, sizeof(ttext));
- sprintf(ttext, " -static -Wl,-Ttext=%s -Wl,--build-id=none", ala);
-
- strcpy(cmd, gcc);
- strcat(cmd, ttext);
- for (i = 3; i < argc; i++) {
- strcat(cmd, " ");
- strcat(cmd, argv[i]);
- }
-
- assert(cmd[reqd-1] == 0);
-
- if (0) printf("\n");
- printf("link_tool_exe: %s\n", cmd);
- if (0) printf("\n");
-
- int r = system(cmd);
- if (r == -1 || WEXITSTATUS(r) != 0)
- failed = 1;
-
- free(cmd);
-
- // return the result of system.
- return failed ? 1 : 0;
-}
-
-/* ------------------------- DARWIN ------------------------ */
-
-#elif defined(VGO_darwin)
-
-/* Plan is: look at the specified gcc invokation. Ignore all parts of
- it except the *.a, *.o and -o outfile parts. Wrap them up in a new
- command which looks (eg) as follows:
-
- (64-bit):
-
- /usr/bin/ld -static -arch x86_64 -macosx_version_min 10.5 \
- -o memcheck-amd64-darwin -u __start -e __start \
- -image_base 0x138000000 -stack_addr 0x13c000000 \
- -stack_size 0x800000 \
- memcheck_amd*.o \
- ../coregrind/libcoregrind-amd64-darwin.a \
- ../VEX/libvex-amd64-darwin.a
-
- (32-bit)
-
- /usr/bin/ld -static -arch i386 -macosx_version_min 10.5 \
- -o memcheck-x86-darwin -u __start -e __start \
- -image_base 0x38000000 -stack_addr 0x3c000000 \
- -stack_size 0x800000 \
- memcheck_x86*.o \
- ../coregrind/libcoregrind-x86-darwin.a \
- ../VEX/libvex-x86-darwin.a
-
- The addresses shown above will actually work, although "for real" we
- of course need to take it from argv[1]. In these examples the stack
- is placed 64M after the executable start. It is probably safer to
- place it 64M before the executable's start point, so the executable
- + data + bss can grow arbitrarily in future without colliding with
- the stack.
-
- There's one more twist: this executable (for the program in this
- file) could be compiled as either 32- or 64-bit. That has no
- bearing at all on the word size of the executable for which we are
- linking. We need to know the latter since we need to hand to the
- linker, "-arch x86_64" or "-arch i386". Fortunately we can figure
- this out by scanning the gcc invokation, which itself must contain
- either "-arch x86_64" or "-arch i386".
-*/
-
-/* user configurable constants: how far before the exe should we
- place the stack? */
-#define TX_STACK_OFFSET_BEFORE_TEXT (64 * 1024 * 1024)
-/* and how big should the stack be */
-#define TX_STACK_SIZE (8 * 1024 * 1024)
-
-
-// Don't NDEBUG this; the asserts are necesary for
-// safety checks.
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-static void add_to ( char** str, size_t* str_sz, char* to_add )
-{
- size_t needed = strlen(to_add) +2/*paranoia*/;
- size_t currlen = strlen(*str);
- assert(currlen < *str_sz);
-
- while (needed >= *str_sz - currlen) {
- *str = realloc(*str, 2 * *str_sz);
- assert(*str);
- (*str_sz) *= 2;
- }
-
- assert(currlen < *str_sz);
- assert(needed < *str_sz - currlen);
- strcat(*str, to_add);
-}
-
-static int/*bool*/ is_dota_or_doto ( char* str )
-{
- assert(str);
- size_t n = strlen(str);
- if (n < 2) return 0;
- if (str[n-2] == '.' && (str[n-1] == 'a' || str[n-1] == 'o'))
- return 1;
- return 0;
-}
-
-/* Run the specified command as-is; ignore the specified load address
- (argv[1]). */
-
-int main ( int argc, char** argv )
-{
- int i;
- int/*bool*/ failed = 0;
-
- // expect at least: alt-load-address gcc -o foo bar.o
- assert(argc > 5);
-
- // check for plausible-ish alt load address, and get hold
- // of it
- char* ala_str = argv[1];
- unsigned long long int ala = 0;
-
- assert(ala_str[0] == '0');
- assert(ala_str[1] == 'x');
-
- int r = sscanf(ala_str, "0x%llx", &ala);
- assert(r == 1);
-
- // get hold of the outfile name
- char* outfile_name = NULL;
- for (i = 1; i < argc-1; i++) {
- if (0 == strcmp(argv[i], "-o")) {
- outfile_name = argv[i+1];
- break;
- }
- }
- assert(outfile_name);
-
- // get hold of the string following -arch
- char* arch_str = NULL;
- for (i = 1; i < argc-1; i++) {
- if (0 == strcmp(argv[i], "-arch")) {
- arch_str = argv[i+1];
- break;
- }
- }
- assert(arch_str);
-
- // build the command line
- size_t cmd_sz = 1;
- char* cmd = calloc(cmd_sz, 1);
- assert(cmd);
-
- add_to(&cmd, &cmd_sz, "/usr/bin/ld");
- add_to(&cmd, &cmd_sz, " -static");
- add_to(&cmd, &cmd_sz, " -arch ");
- add_to(&cmd, &cmd_sz, arch_str);
- add_to(&cmd, &cmd_sz, " -macosx_version_min 10.5");
- add_to(&cmd, &cmd_sz, " -o ");
- add_to(&cmd, &cmd_sz, outfile_name);
- add_to(&cmd, &cmd_sz, " -u __start -e __start");
-
- char buf[40];
- sprintf(buf, "0x%llx", ala);
- add_to(&cmd, &cmd_sz, " -image_base ");
- add_to(&cmd, &cmd_sz, buf);
-
- sprintf(buf, "0x%llx", ala - TX_STACK_OFFSET_BEFORE_TEXT);
- add_to(&cmd, &cmd_sz, " -stack_addr ");
- add_to(&cmd, &cmd_sz, buf);
-
- sprintf(buf, "0x%llx", (unsigned long long int)TX_STACK_SIZE);
- add_to(&cmd, &cmd_sz, " -stack_size ");
- add_to(&cmd, &cmd_sz, buf);
-
- for (i = 3; i < argc; i++) {
- if (is_dota_or_doto(argv[i])) {
- add_to(&cmd, &cmd_sz, " ");
- add_to(&cmd, &cmd_sz, argv[i]);
- }
- }
-
- if (0) printf("\n");
- printf("link_tool_exe: %s\n", cmd);
- if (0) printf("\n");
-
- r = system(cmd);
- if (r == -1 || WEXITSTATUS(r) != 0)
- failed = 1;
-
- free(cmd);
-
- // return the result of system.
- return failed ? 1 : 0;
-}
-
-
-#else
-# error "Unsupported OS"
-#endif
Copied: branches/MACOSX106/coregrind/link_tool_exe_aix5.in (from rev 11174, trunk/coregrind/link_tool_exe_aix5.in)
===================================================================
--- branches/MACOSX106/coregrind/link_tool_exe_aix5.in (rev 0)
+++ branches/MACOSX106/coregrind/link_tool_exe_aix5.in 2010-06-14 00:02:27 UTC (rev 11175)
@@ -0,0 +1,6 @@
+#! @PERL@
+
+use warnings;
+use strict;
+
+die "link_tool_exe_@VGCONF_OS@ requires implementation";
Copied: branches/MACOSX106/coregrind/link_tool_exe_darwin.in (from rev 11174, trunk/coregrind/link_tool_exe_darwin.in)
===================================================================
--- branches/MACOSX106/coregrind/link_tool_exe_darwin.in (rev 0)
+++ branches/MACOSX106/coregrind/link_tool_exe_darwin.in 2010-06-14 00:02:27 UTC (rev 11175)
@@ -0,0 +1,173 @@
+#! @PERL@
+
+# This script handles linking the tool executables on Linux,
+# statically and at an alternative load address.
+#
+# Linking statically sidesteps all sorts of complications to do with
+# having two copies of the dynamic linker (valgrind's and the
+# client's) coexisting in the same process. The alternative load
+# address is needed because Valgrind itself will load the client at
+# whatever address it specifies, which is almost invariably the
+# default load address. Hence we can't allow Valgrind itself (viz,
+# the tool executable) to be loaded at that address.
+#
+# Unfortunately there's no standard way to do 'static link at
+# alternative address', so these link_tool_exe_*.in scripts handle
+# the per-platform hoop-jumping.
+#
+# What we get passed here is:
+# first arg
+# the alternative load address
+# all the rest of the args
+# the gcc invokation to do the final link, that
+# the build system would have done, left to itself
+#
+# We just let the script 'die' if something is wrong, rather than do
+# proper error reporting. We don't expect the users to run this
+# directly. It is only run as part of the build process, with
+# carefully constrained inputs.
+#
+#
+# So: what we actually do is:
+#
+# Look at the specified gcc invokation. Ignore all parts of it except
+# the *.a, *.o and -o outfile parts. Wrap them up in a new command
+# which looks (eg) as follows:
+#
+# (64-bit):
+#
+# /usr/bin/ld -static -arch x86_64 -macosx_version_min 10.5 \
+# -o memcheck-amd64-darwin -u __start -e __start \
+# -image_base 0x138000000 -stack_addr 0x13c000000 \
+# -stack_size 0x800000 \
+# memcheck_amd*.o \
+# ../coregrind/libcoregrind-amd64-darwin.a \
+# ../VEX/libvex-amd64-darwin.a
+#
+# (32-bit)
+#
+# /usr/bin/ld -static -arch i386 -macosx_version_min 10.5 \
+# -o memcheck-x86-darwin -u __start -e __start \
+# -image_base 0x38000000 -stack_addr 0x3c000000 \
+# -stack_size 0x800000 \
+# memcheck_x86*.o \
+# ../coregrind/libcoregrind-x86-darwin.a \
+# ../VEX/libvex-x86-darwin.a
+#
+# The addresses shown above will actually work, although "for real" we
+# of course need to take it from argv[1]. In these examples the stack
+# is placed 64M after the executable start. It is probably safer to
+# place it 64M before the executable's start point, so the executable
+# + data + bss can grow arbitrarily in future without colliding with
+# the stack.
+#
+# There's one more twist: we need to know the word size of the
+# executable for which we are linking. We need to know this because
+# we must tell the linker that, by handing it either "-arch x86_64" or
+# "-arch i386". Fortunately we can figure this out by scanning the
+# gcc invokation, which itself must contain either "-arch x86_64" or
+# "-arch i386".
+
+use warnings;
+use strict;
+# we need to be able to do 64-bit arithmetic:
+use Math::BigInt;
+
+
+# User configurable constants: how far before the exe should we
+# place the stack?
+my $TX_STACK_OFFSET_BEFORE_TEXT = 64 * 1024 * 1024;
+
+# and how big should the stack be?
+my $TX_STACK_SIZE = 8 * 1024 * 1024;
+
+
+# string -> bool
+sub is_dota_or_doto($)
+{
+ my ($str) = @_;
+ if ($str =~ /.\.a$/ || $str =~ /.\.o$/) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+
+# expect at least: alt-load-address gcc -o foo bar.o
+die "Not enougn arguments"
+ if (($#ARGV + 1) < 5);
+
+my $ala = $ARGV[0];
+
+# check for plausible-ish alt load address
+die "Bogus alt-load address (1)"
+ if (length($ala) < 3 || index($ala, "0x") != 0);
+
+die "Bogus alt-load address (2)"
+ if ($ala !~ /^0x[0-9a-fA-F]+$/);
+
+
+# get hold of the outfile name (following "-o")
+my $outname = "";
+
+foreach my $n (2 .. $#ARGV - 1) {
+ my $str = $ARGV[$n];
+ if ($str eq "-o" && $outname eq "") {
+ $outname = $ARGV[$n + 1];
+ }
+}
+
+die "Can't find '-o outfilename' in command line"
+ if ($outname eq "");
+
+
+# get hold of the string following "-arch"
+my $archstr = "";
+
+foreach my $n (2 .. $#ARGV - 1) {
+ my $str = $ARGV[$n];
+ if ($str eq "-arch" && $archstr eq "") {
+ $archstr = $ARGV[$n + 1];
+ }
+}
+
+die "Can't find '-arch archstr' in command line"
+ if ($archstr eq "");
+
+
+# build the command line
+my $cmd = "/usr/bin/ld";
+
+$cmd = "$cmd -static";
+$cmd = "$cmd -arch $archstr";
+$cmd = "$cmd -macosx_version_min 10.5";
+$cmd = "$cmd -o $outname";
+$cmd = "$cmd -u __start -e __start";
+
+my $stack_addr = Math::BigInt->new( $ala ) - $TX_STACK_OFFSET_BEFORE_TEXT;
+my $stack_addr_str = $stack_addr->as_hex();
+my $stack_size_str = Math::BigInt::as_hex($TX_STACK_SIZE);
+
+$cmd = "$cmd -image_base $ala";
+$cmd = "$cmd -stack_addr $stack_addr_str";
+$cmd = "$cmd -stack_size $stack_size_str";
+
+foreach my $n (2 .. $#ARGV) {
+ my $str = $ARGV[$n];
+ if (is_dota_or_doto($str)) {
+ $cmd = "$cmd $str";
+ }
+}
+
+print "link_tool_exe_darwin: $cmd\n";
+
+
+# Execute the command:
+my $r = system("$cmd");
+
+if ($r == 0) {
+ exit 0;
+} else {
+ exit 1;
+}
Copied: branches/MACOSX106/coregrind/link_tool_exe_linux.in (from rev 11174, trunk/coregrind/link_tool_exe_linux.in)
===================================================================
--- branches/MACOSX106/coregrind/link_tool_exe_linux.in (rev 0)
+++ branches/MACOSX106/coregrind/link_tool_exe_linux.in 2010-06-14 00:02:27 UTC (rev 11175)
@@ -0,0 +1,88 @@
+#! @PERL@
+
+# This script handles linking the tool executables on Linux,
+# statically and at an alternative load address.
+#
+# Linking statically sidesteps all sorts of complications to do with
+# having two copies of the dynamic linker (valgrind's and the
+# client's) coexisting in the same process. The alternative load
+# address is needed because Valgrind itself will load the client at
+# whatever address it specifies, which is almost invariably the
+# default load address. Hence we can't allow Valgrind itself (viz,
+# the tool executable) to be loaded at that address.
+#
+# Unfortunately there's no standard way to do 'static link at
+# alternative address', so these link_tool_exe_*.in scripts handle
+# the per-platform hoop-jumping.
+#
+# What we get passed here is:
+# first arg
+# the alternative load address
+# all the rest of the args
+# the gcc invokation to do the final link, that
+# the build system would have done, left to itself
+#
+# We just let the script 'die' if something is wrong, rather than do
+# proper error reporting. We don't expect the users to run this
+# directly. It is only run as part of the build process, with
+# carefully constrained inputs.
+#
+# Linux specific complications:
+#
+# - need to support both old GNU ld and gold: use -Ttext= to
+# set the text segment address.
+#
+# - need to pass --build-id=none (that is, -Wl,--build-id=none to
+# gcc) if it accepts it, to ensure the linker doesn't add a
+# notes section which ends up at the default load address and
+# so defeats our attempts to keep that address clear for the
+# client. However, older linkers don't support this flag, so it
+# is tested for by configure.in and is shipped to us as part of
+# argv[2 ..].
+#
+#
+# So: what we actually do:
+#
+# pass the specified command to the linker as-is, except, add
+# "-static" and "-Ttext=<argv[1]>" to it.
+#
+
+use warnings;
+use strict;
+
+# expect at least: alt-load-address gcc -o foo bar.o
+die "Not enougn arguments"
+ if (($#ARGV + 1) < 5);
+
+my $ala = $ARGV[0];
+
+# check for plausible-ish alt load address
+die "Bogus alt-load address"
+ if (length($ala) < 3 || index($ala, "0x") != 0);
+
+# The cc invokation to do the final link
+my $cc = $ARGV[1];
+
+# and the 'restargs' are argv[2 ..]
+
+# so, build up the complete command here:
+# 'cc' -static -Ttext='ala' 'restargs'
+
+my $cmd="$cc -static -Wl,-Ttext=$ala";
+
+# Add the rest of the parameters
+foreach my $n (2 .. $#ARGV) {
+ $cmd = "$cmd $ARGV[$n]";
+}
+
+print "link_tool_exe_linux: $cmd\n";
+
+
+# Execute the command:
+my $r = system("$cmd");
+
+if ($r == 0) {
+ exit 0;
+} else {
+ exit 1;
+}
Modified: branches/MACOSX106/drd/Makefile.am
===================================================================
--- branches/MACOSX106/drd/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/drd/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -79,7 +79,7 @@
drd_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
drd_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(drd_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -99,7 +99,7 @@
drd_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
drd_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(drd_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/exp-bbv/Makefile.am
===================================================================
--- branches/MACOSX106/exp-bbv/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/exp-bbv/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -26,7 +26,7 @@
exp_bbv_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
exp_bbv_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(exp_bbv_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -46,7 +46,7 @@
exp_bbv_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
exp_bbv_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(exp_bbv_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/exp-ptrcheck/Makefile.am
===================================================================
--- branches/MACOSX106/exp-ptrcheck/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/exp-ptrcheck/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -39,7 +39,7 @@
exp_ptrcheck_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
exp_ptrcheck_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(exp_ptrcheck_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -59,7 +59,7 @@
exp_ptrcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
exp_ptrcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(exp_ptrcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/helgrind/Makefile.am
===================================================================
--- branches/MACOSX106/helgrind/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/helgrind/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -48,7 +48,7 @@
helgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
helgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(helgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -68,7 +68,7 @@
helgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
helgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(helgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/lackey/Makefile.am
===================================================================
--- branches/MACOSX106/lackey/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/lackey/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -26,7 +26,7 @@
lackey_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
lackey_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(lackey_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -46,7 +46,7 @@
lackey_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
lackey_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(lackey_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/massif/Makefile.am
===================================================================
--- branches/MACOSX106/massif/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/massif/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -36,7 +36,7 @@
massif_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
massif_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(massif_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -56,7 +56,7 @@
massif_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
massif_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(massif_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/memcheck/Makefile.am
===================================================================
--- branches/MACOSX106/memcheck/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/memcheck/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -44,7 +44,7 @@
memcheck_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
memcheck_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(memcheck_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -64,7 +64,7 @@
memcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
memcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(memcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Modified: branches/MACOSX106/none/Makefile.am
===================================================================
--- branches/MACOSX106/none/Makefile.am 2010-06-13 22:13:58 UTC (rev 11174)
+++ branches/MACOSX106/none/Makefile.am 2010-06-14 00:02:27 UTC (rev 11175)
@@ -26,7 +26,7 @@
none_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
none_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_PRI@ \
$(LINK) \
$(none_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -46,7 +46,7 @@
none_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
none_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LINK = \
- $(top_builddir)/coregrind/link_tool_exe \
+ $(top_builddir)/coregrind/link_tool_exe_@VGCONF_OS@ \
@VALT_LOAD_ADDRESS_SEC@ \
$(LINK) \
$(none_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
|