[mach-o] Fix initial live atoms with -dead_strip

When -dead_strip is used with -exported_symbols_list the initial set of
live atoms are those in the export list.

llvm-svn: 216213
This commit is contained in:
Nick Kledzik 2014-08-21 20:25:50 +00:00
parent f00e7e143e
commit 77afc71426
4 changed files with 33 additions and 3 deletions

View File

@ -455,6 +455,22 @@ bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) {
addInitialUndefinedSymbol(symbol.getKey());
}
// If -dead_strip, set up initial live symbols.
if (deadStrip()) {
// Entry point is live.
if (outputTypeHasEntry())
addDeadStripRoot(entrySymbolName());
// Lazy binding helper is live.
if (needsStubsPass())
addDeadStripRoot(binderSymbolName());
// If using -exported_symbols_list, make all exported symbols live.
if (_exportMode == ExportMode::whiteList) {
_globalsAreDeadStripRoots = false;
for (const auto &symbol : _exportedSymbols)
addDeadStripRoot(symbol.getKey());
}
}
return true;
}

View File

@ -13,6 +13,11 @@
# RUN: -unexported_symbol _bar -unexported_symbol _a && \
# RUN: llvm-nm -m %t3 | FileCheck %s
#
# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 -dylib \
# RUN: %s %p/Inputs/libSystem.yaml -dead_strip -o %t \
# RUN: -exported_symbols_list %p/Inputs/exported_symbols_list.exp && \
# RUN: llvm-nm -m %t | FileCheck -check-prefix=CHECK_DEAD %s
#
# Test -exported_symbols_list and -exported_symbol properly changes visibility.
#
@ -65,3 +70,8 @@ global-symbols:
# CHECK: (__DATA,__data) external _b
# CHECK: (__TEXT,__text) non-external (was a private external) _bar
# CHECK: (__TEXT,__text) external _foo
# CHECK_DEAD-NOT: (__DATA,__data) non-external (was a private external) _a
# CHECK_DEAD: (__DATA,__data) external _b
# CHECK_DEAD-NOT: (__TEXT,__text) non-external (was a private external) _bar
# CHECK_DEAD: (__TEXT,__text) external _foo

View File

@ -1,6 +1,9 @@
# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t && \
# RUN: llvm-nm -m -n %t | FileCheck %s
#
# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -dead_strip \
# RUN: -o %t2 && llvm-nm -m -n %t2 | FileCheck %s
#
# Test that x86_64 hello-world can be linked into a mach-o executable
#

View File

@ -79,17 +79,18 @@ TEST_F(DarwinLdParserTest, OutputPath) {
}
TEST_F(DarwinLdParserTest, DeadStrip) {
EXPECT_TRUE(parse("ld", "-dead_strip", "foo.o", nullptr));
EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
EXPECT_TRUE(_context.deadStrip());
}
TEST_F(DarwinLdParserTest, DeadStripRootsExe) {
EXPECT_TRUE(parse("ld", "-dead_strip", "foo.o", nullptr));
EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
EXPECT_FALSE(_context.globalsAreDeadStripRoots());
}
TEST_F(DarwinLdParserTest, DeadStripRootsDylib) {
EXPECT_TRUE(parse("ld", "-dylib", "-dead_strip", "foo.o", nullptr));
EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dylib", "-dead_strip", "foo.o",
nullptr));
EXPECT_TRUE(_context.globalsAreDeadStripRoots());
}