From 3a92c35539bd729e12bed95c65c2878f7fb93983 Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Tue, 2 Feb 2016 22:19:01 +0000 Subject: [PATCH] __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. llvm-svn: 259589 --- lld/lib/ReaderWriter/MachO/ExecutableAtoms.h | 8 ++++++-- lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp | 2 ++ lld/test/mach-o/hello-world-x86_64.yaml | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.h b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.h index f1dd799..e98139e 100644 --- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.h +++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.h @@ -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(), DefinedAtom::Alignment(4096))); if (!dsoHandleName.empty()) diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index 0d6e188..ea15c3e 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -725,6 +725,8 @@ uint16_t Util::descBits(const DefinedAtom* atom) { } 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) { diff --git a/lld/test/mach-o/hello-world-x86_64.yaml b/lld/test/mach-o/hello-world-x86_64.yaml index 340ceef..082ed20 100644 --- a/lld/test/mach-o/hello-world-x86_64.yaml +++ b/lld/test/mach-o/hello-world-x86_64.yaml @@ -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 -- 2.7.4