Add support for export_dynamic cmdline option and behaviour.

This option matches the behaviour of ld64, that is it prevents globals
from being dead stripped in executables and dylibs.

Reviewed by Lang Hames

Differential Revision: http://reviews.llvm.org/D16026

llvm-svn: 258554
diff --git a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp
index e2809c4..4b3bfe8 100644
--- a/lld/unittests/DriverTests/DarwinLdDriverTest.cpp
+++ b/lld/unittests/DriverTests/DarwinLdDriverTest.cpp
@@ -84,9 +84,34 @@
 TEST_F(DarwinLdParserTest, DeadStripRootsDylib) {
   EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dylib", "-dead_strip", "foo.o",
                     nullptr));
+  EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
+}
+
+TEST_F(DarwinLdParserTest, DeadStripRootsRelocatable) {
+  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-r", "-dead_strip", "foo.o",
+                    nullptr));
+  EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
+}
+
+TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicExe) {
+  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip",
+                    "-export_dynamic", "foo.o", nullptr));
   EXPECT_TRUE(_ctx.globalsAreDeadStripRoots());
 }
 
+TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicDylib) {
+  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dylib", "-dead_strip",
+                    "-export_dynamic", "foo.o",
+                    nullptr));
+  EXPECT_TRUE(_ctx.globalsAreDeadStripRoots());
+}
+
+TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicRelocatable) {
+  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-r", "-dead_strip",
+                    "-export_dynamic", "foo.o", nullptr));
+  EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
+}
+
 TEST_F(DarwinLdParserTest, Arch) {
   EXPECT_TRUE(parse("ld", "-arch", "x86_64", "foo.o", nullptr));
   EXPECT_EQ(MachOLinkingContext::arch_x86_64, _ctx.arch());