Skip to content

Commit

Permalink
CROSSTOOL linker flags are incorrect for dead_strip feature which lea…
Browse files Browse the repository at this point in the history
…ds to linker errors. This mainly affects the `objc_enable_binary_stripping` feature and leads to bloated applications

Closes bazelbuild#6166.

PiperOrigin-RevId: 214046346
  • Loading branch information
rahul-malik authored and Copybara-Service committed Sep 21, 2018
1 parent 959f462 commit c361da0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
40 changes: 40 additions & 0 deletions src/test/shell/bazel/apple/bazel_objc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,44 @@ EOF
fail "Timestamp of contents of archive file should be zero"
}

function test_strip_symbols() {
setup_objc_test_support

rm -rf ios
mkdir -p ios

cat >ios/main.m <<EOF
#import <UIKit/UIKit.h>
/* function declaration */
int addOne(int num);
int addOne(int num) {
return num + 1;
}
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
EOF

cat >ios/BUILD <<EOF
apple_binary(name = 'app',
deps = [':main'],
platform_type = 'ios')
objc_library(name = 'main',
non_arc_srcs = ['main.m'])
EOF

bazel build --verbose_failures \
--ios_sdk_version=$IOS_SDK_VERSION \
--objc_enable_binary_stripping=true \
--compilation_mode=opt \
//ios:app >$TEST_log 2>&1 || fail "should pass"
ls bazel-out/apl-ios_x86_64-opt/bin/ios/app_lipobin \
|| fail "should generate lipobin (stripped binary)"
! nm bazel-out/apl-ios_x86_64-opt/bin/ios/app_lipobin | grep addOne \
|| fail "should fail to find symbol addOne"
}

run_suite "objc/ios test suite"
40 changes: 20 additions & 20 deletions tools/osx/crosstool/CROSSTOOL.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -2784,8 +2784,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -4476,8 +4476,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -6167,8 +6167,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -7887,8 +7887,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -9577,8 +9577,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -11257,8 +11257,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -12936,8 +12936,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -14644,8 +14644,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down Expand Up @@ -16323,8 +16323,8 @@ toolchain {
action: "objc-executable"
action: "objc++-executable"
flag_group {
flag: "--dead_strip"
flag: "--no_dead_strip_inits_and_terms"
flag: "-dead_strip"
flag: "-no_dead_strip_inits_and_terms"
}
}
requires {
Expand Down

0 comments on commit c361da0

Please sign in to comment.