Skip to content

Commit

Permalink
Fix stripping of macOS loadable bundles
Browse files Browse the repository at this point in the history
Adds `-x` flag to stripping of macOS loadable bundles.

Loadable bundles--i.e. truly dynamically loadable libraries on macOS--cannot be stripped without this flag, since you'd be trying to strip away the all symbols, including those used for dynamic loading. Doing so results in `error: symbols referenced by indirect symbol table entries that can't be stripped`.

`-x` instead leads to the removal of the unneeded local symbols. As Apple notes in their man page: "For dynamic shared libraries, the maximum level of stripping is usually -x (to remove all non-global symbols)."

This should fix bazelbuild#11869

Closes bazelbuild#13314.

PiperOrigin-RevId: 368841977
  • Loading branch information
cpsauer authored and katre committed Jul 19, 2021
1 parent ff9919b commit f0d8cc7
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,9 @@ private StrippingType getStrippingType(ExtraLinkArgs extraLinkArgs) {
if (Iterables.contains(extraLinkArgs, "-dynamiclib")) {
return StrippingType.DYNAMIC_LIB;
}
if (Iterables.contains(extraLinkArgs, "-bundle")) {
return StrippingType.LOADABLE_BUNDLE;
}
if (Iterables.contains(extraLinkArgs, "-kext")) {
return StrippingType.KERNEL_EXTENSION;
}
Expand Down Expand Up @@ -1544,6 +1547,7 @@ private static CommandLine symbolStripCommandLine(
private enum StrippingType {
DEFAULT,
DYNAMIC_LIB,
LOADABLE_BUNDLE,
KERNEL_EXTENSION
}

Expand All @@ -1555,8 +1559,9 @@ private void registerBinaryStripAction(Artifact binaryToLink, StrippingType stri
final ImmutableList<String> stripArgs;
switch (strippingType) {
case DYNAMIC_LIB:
case LOADABLE_BUNDLE:
case KERNEL_EXTENSION:
// For dylibs and kexts, must strip only local symbols.
// For dylibs, loadable bundles, and kexts, must strip only local symbols.
stripArgs = ImmutableList.of("-x");
break;
case DEFAULT:
Expand Down

0 comments on commit f0d8cc7

Please sign in to comment.