From: Julian Seward Date: Wed, 2 Jun 2010 00:46:58 +0000 (+0000) Subject: Make link_tool_exe.c work for MacOSX. This un-breaks the MacOS build X-Git-Tag: svn/VALGRIND_3_6_0~282 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bf5ac57cd0677163fdd9cc5ae0b7a73c60c35aa;p=thirdparty%2Fvalgrind.git Make link_tool_exe.c work for MacOSX. This un-breaks the MacOS build following r11141. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11142 --- diff --git a/coregrind/link_tool_exe.c b/coregrind/link_tool_exe.c index e858a98d91..e3a03708a7 100644 --- a/coregrind/link_tool_exe.c +++ b/coregrind/link_tool_exe.c @@ -27,8 +27,14 @@ inputs. */ +/* ------------------------- LINUX ------------------------- */ + #if defined(VGO_linux) +/* Scheme is simple: pass the specified command to the linker as-is, + except, add "-static" and "-Ttext=" to it. +*/ + // Don't NDEBUG this; the asserts are necesary for // safety checks. #include @@ -95,9 +101,67 @@ int main ( int argc, char** argv ) return r; } +/* ------------------------- LINUX ------------------------- */ + #elif defined(VGO_darwin) -#error Daaaawin +/* 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 +#include +#include +#include + +int main ( int argc, char** argv ) +{ + int i; + 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); + + free(cmd); + + // return the result of system. Note, we should handle it + // properly; that would involve using WEXITSTATUS on the + // value system gives back to us. + return r; +} + #else # error "Unsupported OS"