Skip to content

Commit

Permalink
Add -Xlinker option
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Dec 7, 2020
1 parent d1bc9a4 commit 469f159
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ static void usage(int status) {
}

static bool take_arg(char *arg) {
char *x[] = {"-o", "-I", "-idirafter", "-include", "-x", "-MF", "-MT"};
char *x[] = {
"-o", "-I", "-idirafter", "-include", "-x", "-MF", "-MT", "-Xlinker",
};

for (int i = 0; i < sizeof(x) / sizeof(*x); i++)
if (!strcmp(arg, x[i]))
Expand Down Expand Up @@ -213,6 +215,11 @@ static void parse_args(int argc, char **argv) {
continue;
}

if (!strcmp(argv[i], "-Xlinker")) {
strarray_push(&ld_extra_args, argv[++i]);
continue;
}

if (!strcmp(argv[i], "-s")) {
strarray_push(&ld_extra_args, "-s");
continue;
Expand Down
7 changes: 7 additions & 0 deletions test/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,11 @@ 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,

# -Xlinker
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 -Xlinker -z -Xlinker muldefs -Xlinker --gc-sections -o $tmp/foo $tmp/foo.o $tmp/bar.o $tmp/baz.o
check -Xlinker

echo OK

0 comments on commit 469f159

Please sign in to comment.