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
Support Android NDK #3331
Support Android NDK #3331
Conversation
Yes, we don't need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just a few tweaks and I think it's ready to merge.
src/link.cpp
Outdated
@@ -1653,15 +1653,25 @@ static void construct_linker_job_elf(LinkJob *lj) { | |||
soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major); | |||
} | |||
|
|||
if (target_requires_pie(g->zig_target) && !is_dyn_lib && g->libc != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (target_requires_pie(g->zig_target) && !is_dyn_lib && g->libc != nullptr) { | |
if (target_requires_pie(g->zig_target) && g->out_type == OutTypeExe) { |
src/link.cpp
Outdated
lj->args.append("-o"); | ||
lj->args.append(buf_ptr(&g->output_file_path)); | ||
|
||
if (lj->link_in_crt) { | ||
const char *crt1o; | ||
if (g->zig_target->os == OsNetBSD) { | ||
crt1o = "crt0.o"; | ||
} else if (target_is_android(g->zig_target)) { | ||
crt1o = "crtbegin_dynamic.o"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the logic below, shouldn't it be here?
if (g->have_dynamic_link) {
crt1o = "crtbegin_dynamic.o";
} else {
crt1o = "crtbegin_static.o";
}
Then the other logic remains unchanged:
} else if (!g->have_dynamic_link) {
crt1o = "crt1.o";
}
src/link.cpp
Outdated
@@ -1805,7 +1821,9 @@ static void construct_linker_job_elf(LinkJob *lj) { | |||
} | |||
|
|||
// crt end | |||
if (lj->link_in_crt && target_libc_needs_crti_crtn(g->zig_target)) { | |||
if (target_is_android(g->zig_target) && g->libc != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning for g->libc != nullptr
? I don't think it's necessary - even if you were running zig compiler on android you'd want crtend_android.o
on the link line, right? g->libc
is just if someone provided a custom libc.txt file with paths.
I think you want g->link_in_crt
instead (see the below if statement). This is whether we want to link against libc.
libc
-variant, bioniclibc
now link without trouble, provided you use a properlibc.txt
You can test this for yourself by downloading the latest Android NDK at https://developer.android.com/ndk/downloads/ and creating a
libc.txt
for AArch64, for example (of course directed to where your NDK is) then runningzig build-exe
:(note that this example uses Android SDK version 21)
Note that you must pass the path to thegcc
runtime, or else you will get errors regarding missing-lgcc
-- @andrewrk, can we do away with linking againstlibgcc
on Android entirely?The same steps above may also be used for producing a static archive, or shared object --
producing statically compiled Android executables is broken with these changes, should be fixed before merge