Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved cross-compilation with clang #417

Merged
merged 1 commit into from Sep 27, 2021

Conversation

asheplyakov
Copy link
Contributor

With this patch I can cross-compile Linux kernel with clang and distcc.
Otherwise both remote compilation and local fallback fail like this:

cat > foo.c <<-EOF
int main(int argc, char **argv) { return 0; }
EOF
env DISTCC_HOSTS=127.0.0.1 distcc clang -c --target=aarch64-linux-gnu- foo.c

error: unknown target triple 'unknown', please use -triple or -arch
distcc[304773] ERROR: compile foo.c on 127.0.0.1 failed
distcc[304773] (dcc_build_somewhere) Warning: remote compilation of 'foo.c' failed, retrying locally
distcc[304773] Warning: failed to distribute foo.c to 127.0.0.1, running locally instead
error: unknown target triple 'unknown', please use -triple or -arch
distcc[304773] ERROR: compile foo.c on localhost failed

Linux' kernel makefiles specify the target arch with --target=foo,
and distcc expects -target foo, hence the problem.

Closes: #416

With this patch I can cross-compile Linux kernel with clang and distcc.
Otherwise both remote compilation and local fallback fail like this:

cat > foo.c <<-EOF
int main(int argc, char **argv) { return 0; }
EOF
env DISTCC_HOSTS=127.0.0.1 distcc clang -c --target=aarch64-linux-gnu- -o foo.o foo.c

error: unknown target triple 'unknown', please use -triple or -arch
distcc[304773] ERROR: compile foo.c on 127.0.0.1 failed
distcc[304773] (dcc_build_somewhere) Warning: remote compilation of 'foo.c' failed, retrying locally
distcc[304773] Warning: failed to distribute foo.c to 127.0.0.1, running locally instead
error: unknown target triple 'unknown', please use -triple or -arch
distcc[304773] ERROR: compile foo.c on localhost failed

Linux' kernel makefiles specify the target arch with `--target=foo`,
and distcc expects `-target foo`, hence the problem.

Closes: distcc#416
Copy link
Collaborator

@shawnl shawnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the string processing routine is broken

const char *needle)
{
size_t needle_len = strlen(needle);
for (; *a; a++)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary. strncmp does this for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check it:

char *args[] = { "clang", "-c", "--target=aarch64-linux-gnu", "foo.c", NULL };
int idx = 2;
if (dcc_argv_startswith(args, "--target=") != 1) {
    fprintf(stderr, "wrong answer: args[%d] ('%s') does contain '--target'\n", idx, args[idx]);
    exit(1);
}

Removing for loop from distcc_argv_startswith breaks the test.
Perhaps I'm missing something. Could you elaborate, please? What exactly strncmp is supposed to do?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my bad, I didn't see the double star.

@shawnl shawnl merged commit da74126 into distcc:master Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cross-compilation with clang fails
2 participants