Skip to content

Have a better solution to AOT linker discovery #2645

Description

@antiagainst

At the moment we are relying on the IREE_LLVMAOT_LINKER_PATH environment variable for discovering the linker for LLVM AOT CodeGen. This is quite fragile and obscure. Figure out a better way for doing it. For example, for Android cross-compilation we can probably do #2391.

Activity

  1. added
    codegen
    infrastructure
    codegen/llvm
    on Jul 24, 2020
  2. asaadaldien commented on Jul 24, 2020

    @asaadaldien
    Contributor

    Totally agree the environment variable was a short term solution to support cross platform codegen. Will need to do a generalizing version #2391 so build system discover and populates target platform linker path along with providing a flag to override this value.

  3. GMNGeoffrey commented on Jul 28, 2020

    @GMNGeoffrey
    Member

    In the meantime, can we document what developers should do to make sure they can build/test? I think this env variable isn't documented in any of our getting started guides and a few people have had test failures because of it.

  4. linked a pull request that will close this issueRemove dylib-llvm-aot tests #2694on Jul 28, 2020
  5. asaadaldien commented on Jul 28, 2020

    @asaadaldien
    Contributor

    In the meantime, can we document what developers should do to make sure they can build/test? I think this env variable isn't documented in any of our getting started guides and a few people have had test failures because of it.

    Yeah, its only documented for android build. Getting rid of it is better though!

  6. GMNGeoffrey commented on Jul 28, 2020

    @GMNGeoffrey
    Member

    I think this is not closed? We still need a better way to do this :-D

  7. GMNGeoffrey commented on Jul 28, 2020

    @GMNGeoffrey
    Member

    Maybe GitHub auto-closed it because your commit description said "#2645 is resolved"?

  8. 8 remaining items

  9. ScottTodd commented on Nov 18, 2020

    @ScottTodd
    Member

    I'm resolving those TODOs right now.

  10. GMNGeoffrey commented on Nov 18, 2020

    @GMNGeoffrey
    Member

    I'm resolving those TODOs right now.

    Great! Let's close the issue when the cleanup is complete

  11. ScottTodd commented on Nov 20, 2020

    @ScottTodd
    Member

    I think the default tool path should be looked at a bit more closely prior to merging #3928 and enabling LLVM AOT by default for builds/tests. I have /usr/bin/ld, but we default to ld.lld: https://github.com/google/iree/blob/bf84e445b846f58295b0e903383ae2c82e642707/iree/compiler/Dialect/HAL/Target/LLVM/AOT/internal/UnixLinkerTool.cpp#L32-L35
    Because of this, I still need to set IREE_LLVMAOT_LINKER_PATH=/usr/bin/ld in my environment (or --test_env under Bazel).

    ld (https://linux.die.net/man/1/ld) is typically installed on Linux while ld.lld (https://lld.llvm.org/#using-lld) comes with LLVM but isn't hooked up as part of our build process. Can we search for both on $PATH and pick our preference?

    On Windows, https://github.com/microsoft/vswhere looks nice, but is not installed by default. Requiring vcvarsall isn't unreasonable, but takes a bit of extra IDE setup.

  12. benvanik commented on Nov 20, 2020

    @benvanik
    Collaborator

    agreed - the intent with getToolPath() was that we could have that search and then cache the result so we aren't searching N times per compilation for every link we do.

    We can also - if the IREE-specific envvar isn't set - fallback and use $CC and let the compiler (gcc/clang) figure out how to find the linker. Just clang our_output_object.o -Wl,-linker-flags-here -o our_output_library.so. On Windows we may still need vswhere, but I feel like I'm ok with that or telling users to run vcvarsall for now (since we don't even have a bot for that yet I don't want it to block things).

  13. asaadaldien commented on Nov 20, 2020

    @asaadaldien
    Contributor

    And maybe we can make cross compiling more explicit so the tool will search outside $CC paths, e.g for android search in $ANDROID_NDK subdirectories

  14. benvanik commented on Nov 20, 2020

    @benvanik
    Collaborator

    yep! if we use $CC it takes care of this (mostly) for us, just as if you were building yourself by hand:

    export CC=$NDK/toolchains/llvm/prebuilt/$HOST_TAG/bin/aarch64-linux-android21-clang++
    $CC -shared foo.c -o foo.so  # ndk cc used to link
    iree-translate input.mlir -o output.vmbf  # ndk cc used to link
    
  15. asaadaldien commented on Nov 20, 2020

    @asaadaldien
    Contributor

    IIRC for we always have have CC points to host side clang, I think we need something like CC_TARGET points to android toolchain path?

  16. benvanik commented on Nov 20, 2020

    @benvanik
    Collaborator

    Correct!
    If we used targetTriple.isAndroid() then we can multitarget by building the toolchain path:
    https://developer.android.com/ndk/guides/other_build_systems#overview
    (we can get the host triple from LLVM and then the target triple is given to us)
    All we'd need is ANDROID_NDK.

    Similarly MSVC can do the same thing.

  17. benvanik commented on Nov 20, 2020

    @benvanik
    Collaborator

    The other thing we should try as part of this in follow-on is LTO. If we know we want it anyway (we do) it may be easiest to just jump to it instead of getting things working first in a state we know we don't want and then rewriting it all/figuring it all out again immediately afterward.

    With LTO we could use whatever triples the user has linker support for vs. what we decide to link in to our binaries (x86/arm64/etc today). If the user has mips or arm32 (or riscv!) or whatever we would just be able to use those with no changes needed for us. See #3736.

    Relevant to this issue too is their linker discovery/handling, which we may be able to take some flags from:
    https://github.com/ldc-developers/ldc/pull/1840/files#diff-b8b40d59689f59dad18937a8c46c590b90158783da3634c53adbb111615a4b0f

  18. ScottTodd commented on Nov 20, 2020

    @ScottTodd
    Member

    My immediate motivation here is keeping the Linux getting started steps functional for most users, with LLVM AOT enabled by default. The Windows steps already recommend running vcvarsall.bat. Deeper / more general improvements can be secondary to that IMO. If it's easy to do all at once then great, I'm just not comfortable in this "some tests are disabled for [reasons] state" for long.

  19. benvanik commented on Nov 20, 2020

    @benvanik
    Collaborator

    Agreed - what we're talking about here is the difference between 10 lines of code writing out a native .o as it is today or 1 line of code writing out a .bc. Same shape of problem, same work to figure out the CC path. I don't want to see this take a week because there's futzing with things needed we don't need to solve anyway. If someone can literally go hack in getenv(IREE_LLVMAOT_LINKER || CC) and this all works then of course do that first. I'd have expected you all to have already done that if it was that easy, though ;)

  20. GMNGeoffrey commented on Dec 2, 2020

    @GMNGeoffrey
    Member

    I'm still seeing two TODOs referencing this issue. My preference is that we don't close issues until all the TODOs are cleaned up as well. Otherwise tech debt tends to not get cleaned up

  21. asaadaldien commented on Dec 2, 2020

    @asaadaldien
    Contributor

    @GMNGeoffrey, fair enouph will create a new issue related to the TODOs which are:
    1- LinkerTool support when compiling for android target on windows host.
    2- LinkerTool support when compiling for linux target on windows host.

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

Metadata

Metadata

Assignees

Labels

codegencodegen/llvminfrastructure

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions