[lld] r259589 - __mh_execute_header atoms should be global and never dead strippped.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 14:19:01 PST 2016


Author: pete
Date: Tue Feb  2 16:19:01 2016
New Revision: 259589

URL: http://llvm.org/viewvc/llvm-project?rev=259589&view=rev
Log:
__mh_execute_header atoms should be global and never dead strippped.

In r259574 I fixed some of the issues with the mach header symbols
and DSO handles.

This is the next issue whereby the __mh_execute_header has to not
be dead stripped, and (to match ld64) should be dynamically referenced.

The test here should also have been added in r259574 to make sure that
we emit this symbol.  But checking that it is not only emitted but also
has the correct reference type is fine.

Modified:
    lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
    lld/trunk/test/mach-o/hello-world-x86_64.yaml

Modified: lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h?rev=259589&r1=259588&r2=259589&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.h Tue Feb  2 16:19:01 2016
@@ -70,6 +70,8 @@ public:
   MachHeaderAliasFile(const MachOLinkingContext &context)
     : SimpleFile("mach_header symbols", kindHeaderObject) {
     StringRef machHeaderSymbolName;
+    DefinedAtom::Scope symbolScope = DefinedAtom::scopeLinkageUnit;
+    bool noDeadStrip = false;
     StringRef dsoHandleName;
     switch (context.outputMachOType()) {
     case llvm::MachO::MH_OBJECT:
@@ -77,6 +79,8 @@ public:
       break;
     case llvm::MachO::MH_EXECUTE:
       machHeaderSymbolName = "__mh_execute_header";
+      symbolScope = DefinedAtom::scopeGlobal;
+      noDeadStrip = true;
       dsoHandleName = "___dso_handle";
       break;
     case llvm::MachO::MH_FVMLIB:
@@ -107,8 +111,8 @@ public:
     }
     if (!machHeaderSymbolName.empty())
       _definedAtoms.push_back(new (allocator()) MachODefinedAtom(
-          *this, machHeaderSymbolName, DefinedAtom::scopeLinkageUnit,
-          DefinedAtom::typeMachHeader, DefinedAtom::mergeNo, false, false,
+          *this, machHeaderSymbolName, symbolScope,
+          DefinedAtom::typeMachHeader, DefinedAtom::mergeNo, false, noDeadStrip,
           ArrayRef<uint8_t>(), DefinedAtom::Alignment(4096)));
 
     if (!dsoHandleName.empty())

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=259589&r1=259588&r2=259589&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Tue Feb  2 16:19:01 2016
@@ -725,6 +725,8 @@ uint16_t Util::descBits(const DefinedAto
   }
   if (atom->contentType() == lld::DefinedAtom::typeResolver)
     desc |= N_SYMBOL_RESOLVER;
+  if (atom->contentType() == lld::DefinedAtom::typeMachHeader)
+    desc |= REFERENCED_DYNAMICALLY;
   if (_archHandler.isThumbFunction(*atom))
     desc |= N_ARM_THUMB_DEF;
   if (atom->deadStrip() == DefinedAtom::deadStripNever) {

Modified: lld/trunk/test/mach-o/hello-world-x86_64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/hello-world-x86_64.yaml?rev=259589&r1=259588&r2=259589&view=diff
==============================================================================
--- lld/trunk/test/mach-o/hello-world-x86_64.yaml (original)
+++ lld/trunk/test/mach-o/hello-world-x86_64.yaml Tue Feb  2 16:19:01 2016
@@ -116,4 +116,5 @@ undefined-symbols:
 # CHECK:	(undefined) external ___stdoutp (from libSystem)
 # CHECK:	(undefined) external _fprintf (from libSystem)
 # CHECK:	(undefined) external dyld_stub_binder (from libSystem)
+# CHECK:	{{[0-9a-f]+}} (__TEXT,__text) [referenced dynamically] external __mh_execute_header
 # CHECK:	{{[0-9a-f]+}} (__TEXT,__text) external _main




More information about the llvm-commits mailing list