Skip to content

Compiler tool dynamic linking may not be setting CMake dependencies completely #11331

Open

Description

@ScottTodd

Likely culprit: #11285

I'm noticing that when I make changes to compiler code and rebuild iree-test-deps, the .vmfb test files are not regenerated. I think we're missing a dependency link between IREECompiler.dll (.so on Linux) and iree-compile.exe. The iree_check_test targets depend on the compiler tool here:

# Depending on the binary instead of the target here given we might not have
# a target in this CMake invocation when cross-compiling.
add_custom_command(
OUTPUT
${_OUTPUT_FILES}
COMMAND
${_COMPILE_TOOL_EXECUTABLE}
${_ARGS}
# Changes to either the compiler tool or the input sources should rebuild.
DEPENDS
${_COMPILE_TOOL_EXECUTABLE}
${_LINKER_TOOL_EXECUTABLE}
${_RULE_SRC}
${_RULE_DEPENDS}
COMMENT
"Generating ${_MODULE_FILE_NAME} from ${_FRIENDLY_NAME}"
VERBATIM
)

Can anyone else confirm similar behavior? This might need more investigation.

Activity

  1. added
    bug 🐞
    infrastructure
    compiler/tools
    on Nov 29, 2022
  2. ScottTodd commented on Nov 29, 2022

    @ScottTodd
    MemberAuthor

    I think the PRIVATE linkage here is the problem:

    # DANGER: iree_cc_library links its deps with PUBLIC scope, which causes
    # usage requirements to propagate from dependents to users of the shared
    # library. The shared library is intended to be used as an isolated boundary
    # for C consumers. Therefore, we depend on the backing static library with
    # PRIVATE scope explicitly here vs using a DEPS above. This kind of "boundary
    # shared library" seems to be the only place this happens, so we special
    # case vs generalizing.
    target_link_libraries(
    iree_compiler_API2_SharedImpl
    PRIVATE
    iree_compiler_API2_StaticImpl
    )

    I don't quite follow that comment (and why a "boundary shared library" is useful within the build system). @stellaraccident ?

    I can restore the expected behavior (changing the compiler rebuilds iree-test-deps) by either flipping that to PUBLIC or by inserting a dep on iree::compiler::API2::StaticImpl here (though other places may similarly be "broken"):

    # Changes to either the compiler tool or the input sources should rebuild.
    DEPENDS
    ${_COMPILE_TOOL_EXECUTABLE}
    ${_LINKER_TOOL_EXECUTABLE}
    ${_RULE_SRC}
    ${_RULE_DEPENDS}

  3. benvanik commented on Nov 29, 2022

    @benvanik
    Collaborator

    The goal of the library is to have one dynamic library that all consumers dynamically link against. If you add the static library as PUBLIC then all consumers will also statically link against everything. If you look in your build dir you should see either 50KB for iree-compile/iree-opt/etc + the 400MB (debug) compiler binary if dynamically linking or iree-compile/iree-opt/etc all at 400MB if statically linking.

    There should be a straight-line dep here: code -> static library -> shared library -> tools -> test artifacts. The thing to investigate is where that breaks down as code changes should propagate all the way through: code changes, static library picks up those code changes, shared library picks up the static library changes, tools pick up the shared library changes, etc.

    Maybe there's something special to get a shared library to invalidate dependent targets? Seems like something we could try to reproduce standalone to see if we're holding cmake right.

  4. ScottTodd commented on Nov 29, 2022

    @ScottTodd
    MemberAuthor

    (By "inserting a dep on iree::compiler::API2::StaticImpl" I mean to DEPENDS in add_custom_command, which is just for computing when to rebuild - not actually adding any new linking)

    RE: PUBLIC vs PRIVATE, https://cmake.org/cmake/help/latest/command/target_link_libraries.html:

    Libraries and targets following PUBLIC are linked to, and are made part of the link interface. Libraries and targets following PRIVATE are linked to, but are not made part of the link interface

  5. stellaraccident commented on Nov 30, 2022

    @stellaraccident
    Collaborator

    I think the PRIVATE linkage here is the problem:

    # DANGER: iree_cc_library links its deps with PUBLIC scope, which causes
    # usage requirements to propagate from dependents to users of the shared
    # library. The shared library is intended to be used as an isolated boundary
    # for C consumers. Therefore, we depend on the backing static library with
    # PRIVATE scope explicitly here vs using a DEPS above. This kind of "boundary
    # shared library" seems to be the only place this happens, so we special
    # case vs generalizing.
    target_link_libraries(
    iree_compiler_API2_SharedImpl
    PRIVATE
    iree_compiler_API2_StaticImpl
    )

    I don't quite follow that comment (and why a "boundary shared library" is useful within the build system). @stellaraccident ?

    I can restore the expected behavior (changing the compiler rebuilds iree-test-deps) by either flipping that to PUBLIC or by inserting a dep on iree::compiler::API2::StaticImpl here (though other places may similarly be "broken"):

    # Changes to either the compiler tool or the input sources should rebuild.
    DEPENDS
    ${_COMPILE_TOOL_EXECUTABLE}
    ${_LINKER_TOOL_EXECUTABLE}
    ${_RULE_SRC}
    ${_RULE_DEPENDS}

    If you link as public, then the compile options get inherited, which is not what you want for such a C API. I discovered it because the flags to disable exceptions were being added to all dependents when linked public.

    I didn't notice the vmfb deps not rebuilding (I could have sworn they were for me). Adding it as a depends should be fine.

    This was a bit of a head scratcher...

  6. ScottTodd commented on Nov 30, 2022

    @ScottTodd
    MemberAuthor

    I didn't notice the vmfb deps not rebuilding (I could have sworn they were for me). Adding it as a depends should be fine.

    Just tested on Linux, and I do see them rebuilding correctly with no changes. This might be Windows specific...

  7. ScottTodd commented on Nov 30, 2022

    @ScottTodd
    MemberAuthor

    I'm not on my Windows machine right now to test, but maybe we could flip this PRIVATE to PUBLIC (looking for what's different on Windows vs Linux):

    if(_RULE_SHARED)
    add_library(${_NAME} SHARED "$<TARGET_OBJECTS:${_OBJECTS_NAME}>")
    if(_RULE_WINDOWS_DEF_FILE AND WIN32)
    target_sources(${_NAME} PRIVATE "${_RULE_WINDOWS_DEF_FILE}")
    endif()
    else()

  8. moved this from Not Started to Backlog in (Deprecated) IREEon Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞compiler/toolsinfrastructure

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions