/* 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);
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);
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 ------------------------- */