|
From: Bart V. A. <bva...@ac...> - 2010-06-10 18:22:10
|
Hello,
The patch below replaces link_tool_exe.c by a shell script such that
the Valgrind source code can again be cross-compiled. Are there any
comments about this approach ?
Note: so far this patch has only been tested on Linux. I will test it
on Darwin too before committing.
Bart.
Index: configure.in
===================================================================
--- configure.in (revision 11164)
+++ configure.in (working copy)
@@ -1817,6 +1817,7 @@
include/Makefile
auxprogs/Makefile
mpi/Makefile
+ coregrind/link_tool
coregrind/Makefile
memcheck/Makefile
memcheck/tests/Makefile
Index: coregrind/link_tool.in
===================================================================
--- coregrind/link_tool.in (revision 0)
+++ coregrind/link_tool.in (revision 0)
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+target_os="@VGCONF_OS@"
+absolute_load_address="$1"
+link_command="$2"
+shift
+shift
+
+case "${target_os}" in
+ linux)
+ "${link_command}" -static -Ttext="${absolute_load_address}" "$@"
+ ;;
+ darwin)
+ "${link_command}" "$@"
+ ;;
+ *)
+ echo "Unknown target OS ${target_os}."
+ exit 1
+ ;;
+esac
Index: Makefile.all.am
===================================================================
--- Makefile.all.am (revision 11162)
+++ Makefile.all.am (working copy)
@@ -37,10 +37,8 @@
inplace-noinst_PROGRAMS: $(noinst_PROGRAMS)
mkdir -p $(inplacedir); \
for f in $(noinst_PROGRAMS) ; do \
- if [ $$f != link_tool_exe ] ; then \
- rm -f $(inplacedir)/$$f; \
- ln -f -s ../$(subdir)/$$f $(inplacedir); \
- fi; \
+ rm -f $(inplacedir)/$$f; \
+ ln -f -s ../$(subdir)/$$f $(inplacedir); \
done
# Similar to inplace-noinst_PROGRAMS
@@ -57,9 +55,7 @@
install-noinst_PROGRAMS: $(noinst_PROGRAMS)
$(mkinstalldirs) $(DESTDIR)$(pkglibdir); \
for f in $(noinst_PROGRAMS); do \
- if [ $$f != link_tool_exe ] ; then \
- $(INSTALL_PROGRAM) $$f $(DESTDIR)$(pkglibdir); \
- fi; \
+ $(INSTALL_PROGRAM) $$f $(DESTDIR)$(pkglibdir); \
done
# Similar to install-noinst_PROGRAMS.
Index: helgrind/Makefile.am
===================================================================
--- helgrind/Makefile.am (revision 11162)
+++ helgrind/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(helgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: exp-ptrcheck/Makefile.am
===================================================================
--- exp-ptrcheck/Makefile.am (revision 11162)
+++ exp-ptrcheck/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(exp_ptrcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: callgrind/Makefile.am
===================================================================
--- callgrind/Makefile.am (revision 11162)
+++ callgrind/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(callgrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: exp-bbv/Makefile.am
===================================================================
--- exp-bbv/Makefile.am (revision 11162)
+++ exp-bbv/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(exp_bbv_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: memcheck/Makefile.am
===================================================================
--- memcheck/Makefile.am (revision 11162)
+++ memcheck/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(memcheck_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: massif/Makefile.am
===================================================================
--- massif/Makefile.am (revision 11162)
+++ massif/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(massif_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: cachegrind/Makefile.am
===================================================================
--- cachegrind/Makefile.am (revision 11162)
+++ cachegrind/Makefile.am (working copy)
@@ -56,7 +56,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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(cachegrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -76,7 +76,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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(cachegrind_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: none/Makefile.am
===================================================================
--- none/Makefile.am (revision 11162)
+++ none/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(none_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: lackey/Makefile.am
===================================================================
--- lackey/Makefile.am (revision 11162)
+++ lackey/Makefile.am (working copy)
@@ -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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(lackey_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: drd/Makefile.am
===================================================================
--- drd/Makefile.am (revision 11162)
+++ drd/Makefile.am (working copy)
@@ -80,7 +80,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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(drd_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS) \
@@ -100,7 +100,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 \
+ @SHELL@ $(top_builddir)/coregrind/link_tool \
@VALT_LOAD_ADDRESS@ \
$(LINK) \
$(drd_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS) \
Index: coregrind/Makefile.am
===================================================================
--- coregrind/Makefile.am (revision 11162)
+++ coregrind/Makefile.am (working copy)
@@ -422,27 +422,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
#----------------------------------------------------------------------------
Index: coregrind/link_tool_exe.c
===================================================================
--- coregrind/link_tool_exe.c (revision 11162)
+++ coregrind/link_tool_exe.c (working copy)
@@ -1,171 +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.
-*/
-
-// 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", 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)
-
-/* Run the specified command as-is; ignore the specified load address
- (argv[1]). */
-
-// Don't NDEBUG this; the asserts are necesary for
-// safety checks.
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-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');
-
- // command to run is argv[2 ..]
-
- // so, build up the complete command here:
- // argv[2 ..]
-
- // first, do length safety checks
- for (i = 2; i < argc; i++)
- reqd += 1+ strlen(argv[i]);
-
- reqd += 1;
- char* cmd = calloc(reqd,1);
- assert(cmd);
-
- for (i = 2; 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;
-}
-
-
-#else
-# error "Unsupported OS"
-#endif
|