Skip to content

Commit c2a9d83

Browse files
Allow lambda-cc to be used in the linking stage.
1 parent 84ad1cf commit c2a9d83

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lambda-cc.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,23 @@ int main(int argc, char **argv) {
239239
lcc_string_destroy(&args_before);
240240
return 1;
241241
}
242-
242+
243243
/* Find the source file */
244244
lcc_source_t source;
245245
if (!lcc_source_find(argc, argv, &source)) {
246-
lcc_error("Couldn't find source file on command line");
247-
goto find_error;
246+
/* If there isn't any source file on the command line it means
247+
* the compiler is being used to invoke the linker.
248+
*/
249+
lcc_string_destroy(&args_after);
250+
lcc_string_appendf(&args_before, "%s", cc);
251+
for (int i = 0; i < argc; i++) {
252+
if (!lcc_string_appendf(&args_before, " %s", argv[i]))
253+
goto args_oom;
254+
}
255+
256+
int attempt = system(args_before.buffer);
257+
lcc_string_destroy(&args_before);
258+
return attempt;
248259
}
249260

250261
/* Find the output file */
@@ -309,9 +320,7 @@ int main(int argc, char **argv) {
309320
lcc_string_destroy(&shell);
310321
args_oom:
311322
lcc_error("Out of memory");
312-
find_error:
313323
lcc_string_destroy(&args_before);
314324
lcc_string_destroy(&args_after);
315325
return 1;
316326
}
317-

0 commit comments

Comments
 (0)