|
From: <sv...@va...> - 2010-06-03 20:36:46
|
Author: sewardj
Date: 2010-06-03 21:36:37 +0100 (Thu, 03 Jun 2010)
New Revision: 11148
Log:
merge from trunk: r11146 and r11147: make error propagation work
properly in link_tool_exe.c.
Modified:
branches/MACOSX106/coregrind/link_tool_exe.c
Modified: branches/MACOSX106/coregrind/link_tool_exe.c
===================================================================
--- branches/MACOSX106/coregrind/link_tool_exe.c 2010-06-03 20:27:19 UTC (rev 11147)
+++ branches/MACOSX106/coregrind/link_tool_exe.c 2010-06-03 20:36:37 UTC (rev 11148)
@@ -33,6 +33,16 @@
/* 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
@@ -41,11 +51,13 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/wait.h> /* WEXITSTATUS */
int main ( int argc, char** argv )
{
- int i;
- size_t reqd = 0;
+ int i;
+ int/*bool*/ failed = 0;
+ size_t reqd = 0;
// expect at least: alt-load-address gcc -o foo bar.o
assert(argc > 5);
@@ -76,7 +88,7 @@
char ttext[100];
assert(strlen(ala) < 30);
memset(ttext, 0, sizeof(ttext));
- sprintf(ttext, " -static -Wl,-Ttext=%s", ala);
+ sprintf(ttext, " -static -Wl,-Ttext=%s -Wl,--build-id=none", ala);
strcpy(cmd, gcc);
strcat(cmd, ttext);
@@ -92,16 +104,16 @@
if (0) printf("\n");
int r = system(cmd);
+ if (r == -1 || WEXITSTATUS(r) != 0)
+ failed = 1;
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;
+ // return the result of system.
+ return failed ? 1 : 0;
}
-/* ------------------------- LINUX ------------------------- */
+/* ------------------------- DARWIN ------------------------ */
#elif defined(VGO_darwin)
@@ -191,7 +203,9 @@
int main ( int argc, char** argv )
{
- int i;
+ int i;
+ int/*bool*/ failed = 0;
+ size_t reqd = 0;
// expect at least: alt-load-address gcc -o foo bar.o
assert(argc > 5);
@@ -266,13 +280,13 @@
if (1) printf("\n");
r = system(cmd);
+ if (r == -1 || WEXITSTATUS(r) != 0)
+ failed = 1;
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;
+ // return the result of system.
+ return failed ? 1 : 0;
}
|