bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.15k stars 4.05k forks source link

bazel shouldn't add -fobjc-link-runtime to link params file automatic #23312

Closed xiedeacc closed 2 months ago

xiedeacc commented 2 months ago

Description of the bug:

my host is linux x86_64, I setup a cross-compiling toolchain for macosx, bazel will add -fobjc-link-runtime to link params file automatic when cross compiling for macosx, if manually remove -fobjc-link-runtime in bazel-out/x86_64-opt/bin/external/xz/xz-2.params, link passed and generated binary can executed on mac

ps: cross-compiling toolchain is gcc

error log:

INFO: Analyzed 2 targets (1 packages loaded, 19 targets configured).
SUBCOMMAND: # @@xz//:xz [action 'Linking external/xz/xz', configuration: cd93e5bfc10e589fdea4b98edb0da3d34db132f8caac147f8e72e4ce51ca0820, execution platform: @@internal_platforms_do_not_use//host:host, mnemonic: CppLink]
(cd /root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/execroot/bazel_template && \
  exec env - \
    PATH=/usr/local/llvm/18/bin:/usr/local/java/jdk/jdk-21.0.3/bin:/usr/local/java/jdk/jdk-21.0.3/jre/bin:/usr/local/nginx/sbin:/root/.nvm/versions/node/v20.16.0/bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/go1.22.1/bin:/root/src/go/bin \
    PWD=/proc/self/cwd \
    ZERO_AR_DATE=1 \
  /root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-gcc @bazel-out/x86_64-opt/bin/external/xz/xz-2.params)
# Configuration: cd93e5bfc10e589fdea4b98edb0da3d34db132f8caac147f8e72e4ce51ca0820
# Execution platform: @@internal_platforms_do_not_use//host:host
ERROR: /root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/xz/BUILD.bazel:302:10: Linking external/xz/xz failed: (Exit 1): x86_64-apple-darwin23.3-gcc failed: error executing CppLink command (from target @@xz//:xz) /root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-gcc ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Using built-in specs.
COLLECT_GCC=/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-gcc
COLLECT_LTO_WRAPPER=/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/../libexec/gcc/x86_64-apple-darwin23.3/14.1.0/lto-wrapper
x86_64-apple-darwin23.3-gcc: error: unrecognized command-line option '-fobjc-link-runtime'
Target: x86_64-apple-darwin23.3
Configured with: ../configure --prefix=/root/src/software/gcc14.1.0-darwin23.3-x86_64_toolchain --target=x86_64-apple-darwin23.3 --with-sysroot=/root/src/software/osxcross/target/SDK/MacOSX14.2.sdk --enable-languages=c,c++,objc,obj-c++ --enable-lto --enable-checking=release --disable-multilib --with-ld=/root/src/software/osxcross/target/bin/x86_64-apple-darwin23.3-ld --with-ar=/root/src/software/osxcross/target/bin/x86_64-apple-darwin23.3-ar --with-as=/root/src/software/osxcross/target/bin/x86_64-apple-darwin23.3-as
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.1.0 (GCC)
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.128s, Critical Path: 0.02s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully
ERROR: No test targets were found, yet testing was requested

external/cc_toolchain_config_x86_64_osx_generic_macosx_gcc/BUILD.bazel

load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@cc_toolchains//toolchain:cc_toolchain_config.bzl", "cc_toolchain_config")
load("@cc_toolchains//toolchain:system_module_map.bzl", "system_module_map")
load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite")

# CC toolchain for x86_64_osx_generic_macosx_gcc.
package(default_visibility = ["//visibility:public"])

filegroup(name = "empty")

filegroup(
    name = "cc_wrapper",
    srcs = ["bin/cc_wrapper.sh"],
)

filegroup(
    name = "all-files-x86_64_osx_generic_macosx_gcc",
    srcs = [
        "bin/cc_wrapper.sh",
        "@cc_toolchain_repo_x86_64_osx_generic_macosx_gcc//:all_files",
    ],
)

filegroup(
    name = "archiver-files-x86_64_osx_generic_macosx_gcc",
    srcs = [
        "bin/cc_wrapper.sh",
    ],
)

filegroup(
    name = "assembler-files-x86_64_osx_generic_macosx_gcc",
    srcs = [
        "bin/cc_wrapper.sh",
    ],
)

filegroup(
    name = "compiler-files-x86_64_osx_generic_macosx_gcc",
    srcs = [
        "bin/cc_wrapper.sh",
        "@cc_toolchain_repo_x86_64_osx_generic_macosx_gcc//:all_files",
    ],
)

filegroup(
    name = "linker-files-x86_64_osx_generic_macosx_gcc",
    srcs = [
        "bin/cc_wrapper.sh",
    ],
)

filegroup(
    name = "objcopy-files-x86_64_osx_generic_macosx_gcc",
    srcs = [
        "bin/cc_wrapper.sh",
    ],
)

filegroup(
    name = "strip-files-x86_64_osx_generic_macosx_gcc",
    srcs = [
        "bin/cc_wrapper.sh",
    ],
)

filegroup(
    name = "include-components-x86_64_osx_generic_macosx_gcc",
    srcs = [
        ":compiler-files-x86_64_osx_generic_macosx_gcc",
    ],
)

system_module_map(
    name = "modulemap-x86_64_osx_generic_macosx_gcc",
    cxx_builtin_include_directories = [
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0/x86_64-apple-darwin23.3",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0/backward",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include-fixed",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include-fixed",
        "/root/src/software/macosx14.2-x86_64_sysroot/usr/include",
    ],
    cxx_builtin_include_files = ":include-components-x86_64_osx_generic_macosx_gcc",
    sysroot_path = "/root/src/software/macosx14.2-x86_64_sysroot/",
)

toolchain(
    name = "toolchain-x86_64_osx_generic_macosx_gcc",
    exec_compatible_with = [
        "@platforms//cpu:x86_64",
        "@platforms//os:linux",
    ],
    target_compatible_with = [
        "@platforms//cpu:x86_64",
        "@platforms//os:osx",
    ],
    toolchain = ":cc_toolchain-x86_64_osx_generic_macosx_gcc",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

cc_toolchain(
    name = "cc_toolchain-x86_64_osx_generic_macosx_gcc",
    all_files = ":all-files-x86_64_osx_generic_macosx_gcc",
    ar_files = ":archiver-files-x86_64_osx_generic_macosx_gcc",
    as_files = ":assembler-files-x86_64_osx_generic_macosx_gcc",
    compiler_files = ":compiler-files-x86_64_osx_generic_macosx_gcc",
    dwp_files = ":empty",
    linker_files = ":linker-files-x86_64_osx_generic_macosx_gcc",
    objcopy_files = ":objcopy-files-x86_64_osx_generic_macosx_gcc",
    strip_files = ":strip-files-x86_64_osx_generic_macosx_gcc",
    toolchain_config = ":local-x86_64_osx_generic_macosx_gcc",
    #module_map = ":modulemap-x86_64_osx_generic_macosx_gcc",
    #supports_header_parsing = 1,
    #supports_param_files = 1,
)

cc_toolchain_config(
    name = "local-x86_64_osx_generic_macosx_gcc",
    compiler = "gcc",
    compiler_configuration = {
        "compile_flags": [
            "-B/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin",
            "-U_FORTIFY_SOURCE",
            "-fstack-protector",
            "-fno-omit-frame-pointer",
            "-Wall",
            "-v",
            "-idirafter",
            "/root/src/software/macosx14.2-x86_64_sysroot/usr/include",
        ],
        "dbg_compile_flags": [
            "-g",
            "-fstack-protector",
            "-fstandalone-debug",
            "-fno-omit-frame-pointer",
            "-Wall",
        ],
        "opt_compile_flags": [
            "-g0",
            "-O2",
            "-D_FORTIFY_SOURCE=1",
            "-DNDEBUG",
            "-ffunction-sections",
            "-fdata-sections",
        ],
        "conly_flags": [
            "-nostdinc",
            "-isystem",
            "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include",
            "-isystem",
            "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include-fixed",
        ],
        "cxx_flags": [
            "-nostdinc",
            "-nostdinc++",
            "-std=c++17",
            "-isystem",
            "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0/x86_64-apple-darwin23.3",
            "-isystem",
            "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0",
            "-isystem",
            "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0/backward",
            "-isystem",
            "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include",
            "-isystem",
            "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include-fixed",
        ],
        "link_flags": [
            "-v",
            "-B/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin",
            "-L/root/src/software/macosx14.2-x86_64_sysroot/lib",
            "-L/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/lib",
            "-Wl,-rpath,/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/lib",
            "-L/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib",
            "-Wl,-rpath,/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib",
            "-L/root/src/software/macosx14.2-x86_64_sysroot/usr/lib",
            "-Wl,-rpath,/root/src/software/macosx14.2-x86_64_sysroot/usr/lib",
        ],
        "archive_flags": [],
        "link_libs": [
            "-lstdc++",
            "-lstdc++fs",
        ],
        "opt_link_flags": [],
        "coverage_compile_flags": ["--coverage"],
        "coverage_link_flags": ["--coverage"],
        "unfiltered_compile_flags": [
            "-no-canonical-prefixes",
            "-Wno-builtin-macro-redefined",
            "-D__DATE__=redacted",
            "-D__TIMESTAMP__=redacted",
            "-D__TIME__=redacted",
        ],
    },
    cxx_builtin_include_directories = [
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0/x86_64-apple-darwin23.3",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/x86_64-apple-darwin23.3/include/c++/14.1.0/backward",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include-fixed",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include",
        "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/lib/gcc/x86_64-apple-darwin23.3/14.1.0/include-fixed",
        "/root/src/software/macosx14.2-x86_64_sysroot/usr/include",
    ],
    libc = "macosx",
    supports_start_end_lib = False,
    sysroot_path = "/root/src/software/macosx14.2-x86_64_sysroot/",
    target_arch = "x86_64",
    target_os = "osx",
    tool_paths = {
        "ar": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-libtool",
        "as": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-as",
        "c++": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-g++",
        "cpp": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-cpp",
        "g++": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-g++",
        "gcc": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-gcc",
        "gcov": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-gcov",
        "ld": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-ld",
        "llvm-cov": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/None",
        "nm": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-nm",
        "objcopy": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin-objcopy",
        "objdump": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin-objdump",
        "strip": "/root/.cache/bazel/_bazel_root/d7f4cad81e2b036f4c3382027c9d9c7a/external/cc_toolchain_repo_x86_64_osx_generic_macosx_gcc/bin/x86_64-apple-darwin23.3-strip",
    },
    toolchain_identifier = "cc_toolchain_x86_64_osx_generic_macosx_gcc",
)

cc_toolchain_config.bzl

load("@bazel_tools//tools/cpp:unix_cc_toolchain_config.bzl", unix_cc_toolchain_config = "cc_toolchain_config")

def cc_toolchain_config(
        name,
        compiler,
        toolchain_identifier,
        target_arch,
        target_os,
        libc,
        cxx_builtin_include_directories,
        tool_paths,
        compiler_configuration,
        supports_start_end_lib,
        sysroot_path):
    compile_flags = []
    dbg_compile_flags = []
    opt_compile_flags = []
    conly_flags = []
    cxx_flags = []
    link_flags = []
    archive_flags = []
    link_libs = []
    opt_link_flags = []
    coverage_compile_flags = []
    coverage_link_flags = []
    unfiltered_compile_flags = []

    if compiler_configuration.get("compile_flags") != None and len(compiler_configuration.get("compile_flags")) != 0:
        compile_flags.extend(compiler_configuration["compile_flags"])

    if compiler_configuration.get("dbg_compile_flags") != None and len(compiler_configuration.get("dbg_compile_flags")) != 0:
        dbg_compile_flags.extend(compiler_configuration["dbg_compile_flags"])

    if compiler_configuration.get("opt_compile_flags") != None and len(compiler_configuration.get("opt_compile_flags")) != 0:
        opt_compile_flags.extend(compiler_configuration["opt_compile_flags"])

    if compiler_configuration.get("conly_flags") != None and len(compiler_configuration.get("conly_flags")) != 0:
        conly_flags.extend(compiler_configuration["conly_flags"])

    if compiler_configuration.get("cxx_flags") != None and len(compiler_configuration.get("cxx_flags")) != 0:
        cxx_flags.extend(compiler_configuration["cxx_flags"])

    if compiler_configuration.get("link_flags") != None and len(compiler_configuration.get("link_flags")) != 0:
        link_flags.extend(compiler_configuration["link_flags"])

    if compiler_configuration.get("archive_flags") != None and len(compiler_configuration.get("archive_flags")) != 0:
        archive_flags.extend(compiler_configuration["archive_flags"])

    if compiler_configuration.get("link_libs") != None and len(compiler_configuration.get("link_libs")) != 0:
        link_libs.extend(compiler_configuration["link_libs"])

    if compiler_configuration.get("opt_link_flags") != None and len(compiler_configuration.get("opt_link_flags")) != 0:
        opt_link_flags.extend(compiler_configuration["opt_link_flags"])

    if compiler_configuration.get("coverage_compile_flags") != None and len(compiler_configuration.get("coverage_compile_flags")) != 0:
        coverage_compile_flags.extend(compiler_configuration["coverage_compile_flags"])

    if compiler_configuration.get("coverage_link_flags") != None and len(compiler_configuration.get("coverage_link_flags")) != 0:
        coverage_link_flags.extend(compiler_configuration["coverage_link_flags"])

    if compiler_configuration.get("unfiltered_compile_flags") != None and len(compiler_configuration.get("unfiltered_compile_flags")) != 0:
        unfiltered_compile_flags.extend(compiler_configuration["unfiltered_compile_flags"])

    unix_cc_toolchain_config(
        name = name,
        cpu = target_arch,
        compiler = compiler,
        toolchain_identifier = toolchain_identifier,
        host_system_name = "local",
        target_system_name = "{}-{}".format(target_arch, target_os),
        target_libc = libc,
        abi_version = compiler,
        abi_libc_version = libc,
        cxx_builtin_include_directories = cxx_builtin_include_directories,
        tool_paths = tool_paths,
        compile_flags = compile_flags,
        dbg_compile_flags = dbg_compile_flags,
        opt_compile_flags = opt_compile_flags,
        conly_flags = conly_flags,
        cxx_flags = cxx_flags,
        link_flags = link_flags,
        archive_flags = archive_flags,
        link_libs = link_libs,
        opt_link_flags = opt_link_flags,
        unfiltered_compile_flags = unfiltered_compile_flags,
        coverage_compile_flags = coverage_compile_flags,
        coverage_link_flags = coverage_link_flags,
        supports_start_end_lib = supports_start_end_lib,
        builtin_sysroot = sysroot_path,
    )

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which operating system are you running Bazel on?

ubuntu 22.04 x86_64

What is the output of bazel info release?

7.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

xiedeacc commented 2 months ago

my mistake, it seems this option added by linker from https://github.com/tpoechtrager/cctools-port

xiedeacc commented 2 months ago

does this option added by bazel or linker?

xiedeacc commented 2 months ago

oops, it's really added by bazel, in ./tools/cpp/unix_cc_toolchain_config.bzl +1509

xiedeacc commented 2 months ago

can guys handle this?

keith commented 2 months ago

it looks like the issue is that gcc doesn't accept this flag. bazel's toolchain assumes that if you're building for macOS you're building with clang. you should likely create your own CC toolchain instead and handle the flags how you'd like

xiedeacc commented 2 months ago

it looks like the issue is that gcc doesn't accept this flag. bazel's toolchain assumes that if you're building for macOS you're building with clang. you should likely create your own CC toolchain instead and handle the flags how you'd like

yes, if change toolchain to clang will works well, I finally copy unix_cc_toolchain_config.bzl from bazel to toolchain, and remove that flag fixed this problem, but bazel can handle this small defect if have time

oliverlee commented 1 month ago

I believe you can also disable the default macOS link flags if using GCC:

--features=-macos_default_link_flags
--linkopt=-no-canonical-prefixes