cc_rules with bazel on MacOS: what's the right way to disable "-undefined dynamic_lookup"?

906 views
Skip to first unread message

Denis Koroskin

unread,
Feb 21, 2022, 5:10:16 PM2/21/22
to bazel-discuss
When I compile with bazel on MacOS, unresolved symbols do NOT produce a build-time error, and instead produce a runtime error:

As a result, I get runtime errors with 0 useful information:

dyld[10951]: missing symbol called

There is no indication whatsoever what the missing symbol is. I love my builds being reliable, and this is not something I'm comfortable with pushing to prod.

After a fair bit of debugging, I traced it down to -undefined dynamic_lookup being passed to the linker by default, and it's something I'd like to disable.

One way to do so in a non-portable matter is to add linkopts = ["-undefined error"] to my targets. A more portable way is more complex:

linkopts = select({
                "@platforms//os:macos": ["-undefined error"],
                "//conditions:default": [],
        }),

And I'd prefer something that didn't involve adding these 4 lines to all of my targets, but also without changes to the ~/.bazelrc. Thanks!

Keith Smiley

unread,
Feb 24, 2022, 3:20:24 PM2/24/22
to bazel-discuss
I don't know the history of this being set, it comes from here https://github.com/bazelbuild/bazel/blob/ac48e65f702d3e135bb0b6729392f9cb485da100/tools/osx/crosstool/cc_toolchain_config.bzl#L1114-L1136

But unless that changes your solution is probably the best. You can disable the default linker flags feature entirely with --features=-default_link_flags, but then you'd likely need to manually add the `-target` flag that would also remove, which would be harder than what you're doing in that example.

Arun Rao

unread,
Jan 6, 2023, 5:14:42 PM1/6/23
to bazel-discuss
Thank you for figuring this out.  I was tearing out what little is left of my hair!

Keith Smiley

unread,
Jan 6, 2023, 7:09:23 PM1/6/23
to Arun Rao, bazel-discuss
I think we should remove this flag entirely and submitted https://github.com/bazelbuild/bazel/pull/16414 a while back. But definitely passing -Wl,-undefined,error will restore the default
--
Keith Smiley


--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/YGVWGnhFEXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/ce4f5bb2-bea9-4b08-a573-fce97ab142ecn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages