diff --git a/main.c b/main.c index f21fa3f..497130e 100644 --- a/main.c +++ b/main.c @@ -208,7 +208,7 @@ static void parse_args(int argc, char **argv) { continue; } - if (!strncmp(argv[i], "-l", 2)) { + if (!strncmp(argv[i], "-l", 2) || !strncmp(argv[i], "-Wl,", 4)) { strarray_push(&input_paths, argv[i]); continue; } @@ -714,6 +714,16 @@ int main(int argc, char **argv) { continue; } + if (!strncmp(input, "-Wl,", 4)) { + char *s = strdup(input + 4); + char *arg = strtok(s, ","); + while (arg) { + strarray_push(&ld_args, arg); + arg = strtok(NULL, ","); + } + continue; + } + char *output; if (opt_o) output = opt_o; diff --git a/test/driver.sh b/test/driver.sh index 5f9af9b..7ccff99 100755 --- a/test/driver.sh +++ b/test/driver.sh @@ -295,4 +295,11 @@ echo 'int foo(); int bar=3; int main() { foo(); }' > $tmp/bar.c $chibicc -o $tmp/foo $tmp/bar.c -L$tmp -lfoobar check -L +# -Wl, +echo 'int foo() {}' | $chibicc -c -o $tmp/foo.o -xc - +echo 'int foo() {}' | $chibicc -c -o $tmp/bar.o -xc - +echo 'int main() {}' | $chibicc -c -o $tmp/baz.o -xc - +cc -Wl,-z,muldefs,--gc-sections -o $tmp/foo $tmp/foo.o $tmp/bar.o $tmp/baz.o +check -Wl, + echo OK