Skip to content

Commit

Permalink
Add -Wl, option
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Dec 7, 2020
1 parent c8df787 commit d1bc9a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d1bc9a4

Please sign in to comment.