From 1a0285c3b64b121268ced3eb9ad9d5ba396b4905 Mon Sep 17 00:00:00 2001 From: Christopher Sauer Date: Fri, 16 Apr 2021 07:19:18 -0700 Subject: [PATCH] Fix stripping of macOS loadable bundles 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 #11869 Closes #13314. PiperOrigin-RevId: 368841977 --- .../devtools/build/lib/rules/objc/CompilationSupport.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index 53f9dbf3cac5bd..fa78a38ae814f8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -1086,6 +1086,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; } @@ -1593,6 +1596,7 @@ private static CommandLine symbolStripCommandLine( private enum StrippingType { DEFAULT, DYNAMIC_LIB, + LOADABLE_BUNDLE, KERNEL_EXTENSION } @@ -1604,8 +1608,9 @@ private void registerBinaryStripAction(Artifact binaryToLink, StrippingType stri final ImmutableList 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: