Add -Wl, option

This commit is contained in:
Rui Ueyama 2020-09-19 21:09:17 +09:00
parent c8df7874c6
commit d1bc9a4eb0
2 changed files with 18 additions and 1 deletions

12
main.c
View File

@ -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;

View File

@ -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