]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
(for linux):
authorJulian Seward <jseward@acm.org>
Thu, 3 Jun 2010 08:19:59 +0000 (08:19 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 3 Jun 2010 08:19:59 +0000 (08:19 +0000)
* pass --build-id=none to ld to stop it creating a.note.gnu.build-id
  exactly where we don't want it

* propagate error code from system() properly

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11146

coregrind/link_tool_exe.c

index e3a03708a78c6ae85aae55654b8e360ab289e9b1..cb01372e990e2eb902bfc001a2cbf45ac93593be 100644 (file)
 
 /* 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
 #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 @@ int main ( int argc, char** argv )
    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,13 +104,13 @@ int main ( int argc, char** argv )
    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 ------------------------- */