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

Cross compile qnx, Bazel does not produce shared libraries. #15997

Open
tongtongdi opened this issue Jul 28, 2022 · 5 comments
Open

Cross compile qnx, Bazel does not produce shared libraries. #15997

tongtongdi opened this issue Jul 28, 2022 · 5 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)

Comments

@tongtongdi
Copy link

Description of the bug:
When I cross compile QNX, no dynamic library is generated. At this time, after I add
feature( name = "supports_dynamic_linker", enabled = True, ), it prompts me that ld cannot be found. then i create a ld soft connection ln aarch64-unknown-nto-qnx7.1.0-ld ld, this problem is solved.i'm surprised that i specified ld in the tool_path like this tool_path( name = "ld", path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld",),, but it doesn't seem to work,How can I solve this problem gracefully。

Which operating system are you running Bazel on?
Linux.

What is the output of bazel info release?
5.2.0

Have you found anything relevant by searching the web?
When I cross compile the example , Bazel does not produce shared libraries

@tongtongdi tongtongdi added P1 I'll work on this now. (Assignee required) release team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: process labels Jul 28, 2022
@tongtongdi tongtongdi changed the title Cross compile qnx, Bazel does not produce shared libraries. Release 5.2.0 - $MONTH $YEAR Cross compile qnx, Bazel does not produce shared libraries. Release 5.2.0 7-2022 Jul 28, 2022
@sgowroji sgowroji added more data needed and removed P1 I'll work on this now. (Assignee required) type: process release team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website labels Jul 29, 2022
@sgowroji
Copy link
Member

Hello @tongtongdi, Could you please provide complete steps to reproduce the above issue. Thanks!

@sgowroji sgowroji changed the title Cross compile qnx, Bazel does not produce shared libraries. Release 5.2.0 7-2022 Cross compile qnx, Bazel does not produce shared libraries. Jul 29, 2022
@tongtongdi
Copy link
Author

Hi @sgowroji , i cross compile qnx on x86_64 platform, my computer system is 20.04.1-Ubuntu, I follow the instruction at https://bazel.build/tutorials/cc-toolchain-config, the target cpu is aarch64, and the system is qnx.
my toolchain/cc_toolchain_config.bzl is :

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")

load(
       "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
       "feature",
       "flag_group",
       "flag_set",
       "tool_path",
   )
   
all_link_actions = [
      ACTION_NAMES.cpp_link_executable,
      ACTION_NAMES.cpp_link_dynamic_library,
      ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]

all_compile_actions = [
    ACTION_NAMES.assemble,
    ACTION_NAMES.preprocess_assemble,
    ACTION_NAMES.linkstamp_compile,
    ACTION_NAMES.c_compile,
    ACTION_NAMES.cpp_compile,
    ACTION_NAMES.cpp_header_parsing,
    ACTION_NAMES.cpp_module_codegen,
    ACTION_NAMES.cpp_module_compile,
    ACTION_NAMES.clif_match,
    ACTION_NAMES.lto_backend,
]



QNX_HOST="/qnx710/host/linux/x86_64"
QNX_TARGET="/qnx710/target/qnx7"

def _impl(ctx):
    tool_paths = [
        tool_path(
            name = "ld",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld",
        ),
        tool_path(
            name = "ar",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-ar",
        ),
        tool_path(
            name = "cpp",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-g++",
        ),
        tool_path(
            name = "gcc",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-g++",
        ),
        tool_path(
            name = "gcov",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-gcov",
        ),
        tool_path(
            name = "nm",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-nm",
        ),
        tool_path(
            name = "objdump",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-objdump",
        ),
        tool_path(
            name = "objcopy",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-objcopy",
        ),
        tool_path(
            name = "strip",
            path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-strip",
        ),
    ]

    linker_flags = feature(
        name = "default_linker_flags",
        enabled = True,
        flag_sets = [
            flag_set(
                actions = all_link_actions,
                flag_groups = [
                    flag_group(
                        flags = [
                            "-lstdc++",
                        ],
                    ),
                ],
            ),
        ],
    )


    compiler_flags = feature(
        name = "default_compile_flags",
        enabled = True,
        flag_sets = [
            flag_set(
                actions = all_compile_actions,
                flag_groups = [
                    flag_group(
                        flags = [
                            "-Wall",
                        ],
                    ),
                ],
            ),
        ],
    )

    suportDynamic = feature(
        name = "supports_dynamic_linker",
        enabled = True,
    )

    
    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        features = [linker_flags, compiler_flags, suportDynamic],
        cxx_builtin_include_directories = [
          QNX_TARGET,
          QNX_HOST + "/usr/lib/gcc/aarch64-unknown-nto-qnx7.1.0/8.3.0/include/",
        ],
        toolchain_identifier = "aarch64-toolchain",
        host_system_name = "local",
        target_system_name = "aarch64le",
        target_cpu = "aarch64",
        target_libc = "unknown",
        compiler = "clang",
        abi_version = "unknown",
        abi_libc_version = "unknown",
        tool_paths = tool_paths,
    )

cc_toolchain_config = rule(
    implementation = _impl,
    attrs = {},
    provides = [CcToolchainConfigInfo],
)

my toolchain/BUILD is :

load(":cc_toolchain_config.bzl", "cc_toolchain_config")

cc_toolchain_suite(
    name = "clang_suite",
    toolchains = {
        "aarch64": "aarch64_toolchain",
    },
)

filegroup(name = "empty")

cc_toolchain(
    name = "aarch64_toolchain",
    toolchain_identifier = "aarch64-toolchain",
    toolchain_config = ":aarch64_toolchain_config",
    all_files = ":empty",
    compiler_files = ":empty",
    dwp_files = ":empty",
    linker_files = ":empty",
    objcopy_files = ":empty",
    strip_files = ":empty",
    supports_param_files = 0,
)


cc_toolchain_config(name = "aarch64_toolchain_config")

my .bazelrc file is :

# Use our custom-configured c++ toolchain.

build:clang_config --crosstool_top=//toolchain:clang_suite

# Use --cpu as a differentiator.

build:clang_config --cpu=aarch64

build:clang_config --action_env=QNX_HOST=/qnx710/host/linux/x86_64

build:clang_config --action_env=QNX_TARGET=/qnx710/target/qnx7


# Use the default Bazel C++ toolchain to build the tools used during the
# build.

build:clang_config --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

you should set your qnx info in file cc_toolchain_config.bzl and .bazelrc. then i run bazel build :hello-world --config=clang_config, i get error log collect2: fatal error: cannot find 'ld'.

@tongtongdi
Copy link
Author

when i enter /qnx710/host/linux/x86_64/usr/bin and create a ld soft connection ln aarch64-unknown-nto-qnx7.1.0-ld ld, this problem is solved, but i have set tool_path( name = "ld", path = QNX_HOST + "/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld",), it still find ld not aarch64-unknown-nto-qnx7.1.0-ld.

@tongtongdi
Copy link
Author

Hi @sgowroji ,without creating a soft link, how can i fix this. Can I use a configuration to solve this problem ?

@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Oct 26, 2022
@xzxzzxzxzca
Copy link

xzxzzxzxzca commented May 4, 2023

@tongtongdi the missing ld error is not caused by Bazel but is coming from g++.
I get the same error when trying to run g++ directly.
QNX SDP comes with wrapper commands qcc and q++, for C and C++ respectively, and those make the linker work somehow (well, it seems it just passes some extra flags like -B which it takes from nearby toolchain config files). So the error will go away if you put q++ in your tool_paths as the gcc tool.

Unfortunately, then another issue arises, which only happens under Bazel:

Lockfile (/etc/qnxlicenses.lck) acquisition timed out after 10 seconds. Check that the file and containing folder have write permissions set for this user, and that no other processes are using this file
license check failed

However, this can be solved by passing --sandbox_writable_path="~/.qnx/license/" to bazel. Also, don't forget build --action_env=HOME in your .bazelrc.

If you want to stick to calling gcc directly, then you still have to properly set ALL THREE env vars: QNX_HOST, QNX_TARGET, AND PATH pointing to the SDK's bin dir.
See the note here on how cross-compilers search for ld: https://gcc.gnu.org/onlinedocs/gccint/Collect2.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)
Projects
None yet
Development

No branches or pull requests

4 participants