Skip to content

Forking UnixLinkerTool into AndroidLinkerTool. - #4719

Merged
benvanik merged 3 commits into
mainfrom
benvanik-android-linking
Feb 26, 2021
Merged

benvanik merged 3 commits into
mainfrom
benvanik-android-linking

Conversation

@benvanik

@benvanik benvanik commented Feb 4, 2021

Copy link
Copy Markdown
Collaborator

There's some common things between them but that's mostly incidental at
this point. Once we have some more platforms working we can see if there
are attributes/etc we can apply everywhere (ensuring they're ignored when
not used on a particular tool/etc). For now, this stuff is whack-a-mole
and having them shared makes it harder to iterate on any one target.

With this our .so's for android end up with no imports and strictly the
functions we generate - an unstripped simple_mul is <500 bytes (most of
which is the source path names and junk in .comment).

Progress on #4606 - needs testing, script updates, and checks that things
like tracy still have symbols.

@benvanik benvanik added platform/android 🤖 Android-specific build, execution, benchmarking, and deployment codegen/llvm LLVM code generation compiler backend labels Feb 4, 2021
@benvanik
benvanik requested a review from ScottTodd February 4, 2021 02:46
@google-cla google-cla Bot added the cla: yes label Feb 4, 2021
@benvanik
benvanik force-pushed the benvanik-android-linking branch 2 times, most recently from 04194ed to d8ca864 Compare February 4, 2021 03:24
@benvanik
benvanik marked this pull request as ready for review February 4, 2021 03:27
@benvanik
benvanik force-pushed the benvanik-android-linking branch 2 times, most recently from 5b79176 to 1fac08f Compare February 4, 2021 04:23
@benvanik

benvanik commented Feb 4, 2021

Copy link
Copy Markdown
Collaborator Author

@benvanik
benvanik requested a review from asaadaldien February 4, 2021 05:32
Comment thread build_tools/cmake/iree_check_test.cmake Resolved
@benvanik
benvanik force-pushed the benvanik-android-linking branch 2 times, most recently from f9f818e to eee2cfd Compare February 4, 2021 19:52
@benvanik
benvanik requested a review from asaadaldien February 4, 2021 19:53

@asaadaldien asaadaldien left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! thanks for refactoring this @benvanik.

@asaadaldien

Copy link
Copy Markdown
Contributor

Looking at the failure.

We need to statically link libc thats why I used to have aarch64-linux-android30-clang++ with -static-libstdc++

/tmpfs/src/github/iree/iree/test/e2e/linalg_tensor_ops/add.mlir:14: undefined reference to `malloc'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Linking failed; command line returned exit code 256:

/usr/src/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang -nostdlib -static -lm -o /tmp/tensor_dispatch_0-54100e.so /tmp/tensor_dispatch_0-54100e.obj

@benvanik

benvanik commented Feb 4, 2021

Copy link
Copy Markdown
Collaborator Author

Looking at the failure.

We need to statically link libc thats why I used to have aarch64-linux-android30-clang++ with -static-libstdc++

/tmpfs/src/github/iree/iree/test/e2e/linalg_tensor_ops/add.mlir:14: undefined reference to `malloc'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Linking failed; command line returned exit code 256:

/usr/src/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang -nostdlib -static -lm -o /tmp/tensor_dispatch_0-54100e.so /tmp/tensor_dispatch_0-54100e.obj

That was just a hack to silence the error and not a fix - we don't need to link libc - we shouldn't be emitting any code that uses anything from it - like malloc :)
We need to not emit malloc.

@benvanik
benvanik force-pushed the benvanik-android-linking branch from eee2cfd to d0f091b Compare February 4, 2021 20:52
There's some common things between them but that's mostly incidental at
this point. Once we have some more platforms working we can see if there
are attributes/etc we can apply everywhere (ensuring they're ignored when
not used on a particular tool/etc). For now, this stuff is whack-a-mole
and having them shared makes it harder to iterate on any one target.

With this our .so's for android end up with no imports and strictly the
functions we generate - an unstripped simple_mul is <500 bytes (most of
which is the source path names and junk in .comment).

Progress on #4606 - needs testing, script updates, and checks that things
like tracy still have symbols.
@benvanik
benvanik force-pushed the benvanik-android-linking branch from d0f091b to bf0cadc Compare February 4, 2021 21:34
@ScottTodd

Copy link
Copy Markdown
Member

This also helps with #4717 (where most of the difficulty is coming from)

@ScottTodd ScottTodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's wait until ~Monday to merge? I'll be build cop then and want to sort out a few things downstream.

@benvanik

benvanik commented Feb 5, 2021

Copy link
Copy Markdown
Collaborator Author

Let's wait until ~Monday to merge? I'll be build cop then and want to sort out a few things downstream.

SGTM

@ScottTodd

Copy link
Copy Markdown
Member

Can we merge this now? I had some follow-up tasks to work through, but those can be made after this initial set of work lands.

@benvanik

Copy link
Copy Markdown
Collaborator Author

I'm fine with merging - I was waiting for your OK :)

@ScottTodd

Copy link
Copy Markdown
Member

I'm fine with merging - I was waiting for your OK :)

👍 I'm back around now to handle any follow-up tasks (or fallout from infra failures this may cause :P).

@benvanik
benvanik merged commit a192e14 into main Feb 26, 2021
@benvanik
benvanik deleted the benvanik-android-linking branch February 26, 2021 00:43
ScottTodd added a commit that referenced this pull request Feb 26, 2021
Redo of #4761 after GitHub silliness.

Note that the `docs/get_started/getting_started_riscv_cmake.md` changes slightly overlap with #4940.

Fixes #4606 (now that #4719 is also merged)
@hanhanW hanhanW mentioned this pull request Feb 26, 2021
@ScottTodd

Copy link
Copy Markdown
Member

Hmm, this seems to break building on macOS:

`
[2505/2862] Generating check_llvm-aot-conv_img2col_conv.mlir_module.vmfb
FAILED: iree/test/e2e/llvm_specific/check_llvm-aot-conv_img2col_conv.mlir_module.vmfb
cd /Users/xx/iree-build/iree/test/e2e/llvm_specific && /Users/xx/iree-build/iree/tools/iree-translate -iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=dylib-llvm-aot -iree-codegen-linalg-to-llvm-conv-img2col-conversion=true /Users/xx/iree/iree/test/e2e/llvm_specific/conv.mlir -o check_llvm-aot-conv_img2col_conv.mlir_module.vmfb
ld: unknown option: -nostdlib
Linking failed; command line returned exit code 256:

/usr/bin/ld -nostdlib -shared -undefined suppress -o /var/folders/rp/c0_pxspj11g3dzxkc_qfxvdr0000gn/T/conv_linked_llvm_aot-8eec4a.so -dylib -flat_namespace /var/folders/rp/c0_pxspj11g3dzxkc_qfxvdr0000gn/T/conv_linked_llvm_aot-8eec4a.obj
`

Oh, interesting. I also don't see the nostdlib option for ld on macOS (man ld | grep nostdlib), but I do see it on Linux. Thoughts, @benvanik ? As a workaround for now, we could wrap

https://github.com/google/iree/blob/39980126755bd0c5717a7c0d77c7366231a123ae/iree/compiler/Dialect/HAL/Target/LLVM/internal/UnixLinkerTool.cpp#L102-L104

in #if defined(IREE_PLATFORM_APPLE)...

@benvanik

Copy link
Copy Markdown
Collaborator Author

no no no no never add another #ifdef :)
(and definitely no deps on non-iree/compiler/ files)

you can query the target triple with if (targetTriple.isOSDarwin()) ... and change behavior on that, or the host triple (doing the compilation) with auto hostTriple = Triple(llvm::sys::getProcessTriple()); if (hostTriple.isOSDarwin()) ....

Someone with a mac should figure out what the corresponding equivalent of nostdlib is and use that.

@benvanik

Copy link
Copy Markdown
Collaborator Author

(and, if things get weird, then add a DarwinLinkerTool just like AndroidLinkerTool)

@ScottTodd

Copy link
Copy Markdown
Member

I found a discussion related to nostdlib on macOS here: https://reviews.llvm.org/D58320. Do we have someone familiar with linking set up already on a mac? I'm getting a new machine next week so I'd rather get set up on the new machine instead of spending that time now on an old machine :P

@asaadaldien

Copy link
Copy Markdown
Contributor

no no no no never add another #ifdef :)
(and definitely no deps on non-iree/compiler/ files)

you can query the target triple with if (targetTriple.isOSDarwin()) ... and change behavior on that, or the host triple (doing the compilation) with auto hostTriple = Triple(llvm::sys::getProcessTriple()); if (hostTriple.isOSDarwin()) ....

Someone with a mac should figure out what the corresponding equivalent of nostdlib is and use that.

We can also duplicate the list and explicitly getFlags(targetTriple) instead of concatenation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen/llvm LLVM code generation compiler backend platform/android 🤖 Android-specific build, execution, benchmarking, and deployment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants