#include <set>
#include <map>
#include <algorithm>
+#include <type_traits>
#include "dwarf2.h"
#include "debugline.h"
#include "Architectures.hpp"
+#include "Bitcode.hpp"
#include "ld.hpp"
#include "macho_relocatable_file.h"
class File : public ld::relocatable::File
{
public:
- File(const char* p, time_t mTime, const uint8_t* content, uint32_t ord) :
+ File(const char* p, time_t mTime, const uint8_t* content, ld::File::Ordinal ord) :
ld::relocatable::File(p,mTime,ord), _fileContent(content),
_sectionsArray(NULL), _atomsArray(NULL),
- _sectionsArrayCount(0), _atomsArrayCount(0),
+ _sectionsArrayCount(0), _atomsArrayCount(0), _aliasAtomsArrayCount(0),
_debugInfoKind(ld::relocatable::File::kDebugInfoNone),
- _dwarfTranslationUnitDir(NULL), _dwarfTranslationUnitFile(NULL),
+ _dwarfTranslationUnitPath(NULL),
_dwarfDebugInfoSect(NULL), _dwarfDebugAbbrevSect(NULL),
_dwarfDebugLineSect(NULL), _dwarfDebugStringSect(NULL),
_objConstraint(ld::File::objcConstraintNone),
+ _swiftVersion(0),
_cpuSubType(0),
- _ojcReplacmentClass(false), _canScatterAtoms(false) {}
+ _minOSVersion(0),
+ _platform(0),
+ _canScatterAtoms(false),
+ _srcKind(kSourceUnknown) {}
virtual ~File();
// overrides of ld::File
virtual bool forEachAtom(ld::File::AtomHandler&) const;
virtual bool justInTimeforEachAtom(const char* name, ld::File::AtomHandler&) const
{ return false; }
-
+ virtual uint32_t minOSVersion() const { return _minOSVersion; }
+ virtual uint32_t platformLoadCommand() const { return _platform; }
+
// overrides of ld::relocatable::File
- virtual bool objcReplacementClasses() const { return _ojcReplacmentClass; }
virtual ObjcConstraint objCConstraint() const { return _objConstraint; }
virtual uint32_t cpuSubType() const { return _cpuSubType; }
virtual DebugInfoKind debugInfo() const { return _debugInfoKind; }
- virtual const std::vector<ld::relocatable::File::Stab>* stabs() const { return &_stabs; }
+ virtual const std::vector<ld::relocatable::File::Stab>* stabs() const { return &_stabs; }
virtual bool canScatterAtoms() const { return _canScatterAtoms; }
- bool translationUnitSource(const char** dir, const char** name) const;
+ virtual const char* translationUnitSource() const;
+ virtual LinkerOptionsList* linkerOptions() const { return &_linkerOptions; }
+ virtual uint8_t swiftVersion() const { return _swiftVersion; }
+ virtual ld::Bitcode* getBitcode() const { return _bitcode.get(); }
+ virtual SourceKind sourceKind() const { return _srcKind; }
+ virtual void setSourceKind(SourceKind src) { _srcKind = src; }
const uint8_t* fileContent() { return _fileContent; }
private:
const uint8_t* _fileContent;
Section<A>** _sectionsArray;
uint8_t* _atomsArray;
+ uint8_t* _aliasAtomsArray;
uint32_t _sectionsArrayCount;
uint32_t _atomsArrayCount;
+ uint32_t _aliasAtomsArrayCount;
std::vector<ld::Fixup> _fixups;
std::vector<ld::Atom::UnwindInfo> _unwindInfos;
std::vector<ld::Atom::LineInfo> _lineInfos;
std::vector<ld::relocatable::File::Stab>_stabs;
ld::relocatable::File::DebugInfoKind _debugInfoKind;
- const char* _dwarfTranslationUnitDir;
- const char* _dwarfTranslationUnitFile;
+ const char* _dwarfTranslationUnitPath;
const macho_section<P>* _dwarfDebugInfoSect;
const macho_section<P>* _dwarfDebugAbbrevSect;
const macho_section<P>* _dwarfDebugLineSect;
const macho_section<P>* _dwarfDebugStringSect;
ld::File::ObjcConstraint _objConstraint;
+ uint8_t _swiftVersion;
uint32_t _cpuSubType;
- bool _ojcReplacmentClass;
+ uint32_t _minOSVersion;
+ uint32_t _platform;
bool _canScatterAtoms;
+ std::vector<std::vector<const char*> > _linkerOptions;
+ std::unique_ptr<ld::Bitcode> _bitcode;
+ SourceKind _srcKind;
};
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr);
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeUnclassified; }
virtual bool dontDeadStrip() { return (this->_machOSection->flags() & S_ATTR_NO_DEAD_STRIP); }
+ virtual bool dontDeadStripIfReferencesLive() { return ( (this->_machOSection != NULL) && (this->_machOSection->flags() & S_ATTR_LIVE_SUPPORT) ); }
virtual Atom<A>* findAtomByAddress(pint_t addr) { return this->findContentAtomByAddress(addr, this->_beginAtoms, this->_endAtoms); }
virtual bool addFollowOnFixups() const { return ! _file.canScatterAtoms(); }
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer,
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const { return 0; }
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const { return false; }
+ virtual bool ignoreLabel(const char* label) const { return false; }
static const char* makeSectionName(const macho_section<typename A::P>* s);
protected:
_beginAtoms(NULL), _endAtoms(NULL), _hasAliases(false) { }
- bool addRelocFixup_powerpc(class Parser<A>& parser,const macho_relocation_info<typename A::P>* reloc);
Atom<A>* findContentAtomByAddress(pint_t addr, class Atom<A>* start, class Atom<A>* end);
uint32_t x86_64PcRelOffset(uint8_t r_type);
+ void addLOH(class Parser<A>& parser, int kind, int count, const uint64_t addrs[]);
static const char* makeSegmentName(const macho_section<typename A::P>* s);
static bool readable(const macho_section<typename A::P>* s);
static bool writable(const macho_section<typename A::P>* s);
class Atom<A>* _beginAtoms;
class Atom<A>* _endAtoms;
bool _hasAliases;
+ std::set<const class Atom<A>*> _altEntries;
};
public:
CFISection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: Section<A>(f, s) { }
- uint32_t cfiCount();
+ uint32_t cfiCount(Parser<A>& parser);
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeCFI; }
virtual uint32_t computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
typedef typename A::P::uint_t pint_t;
typedef libunwind::CFI_Atom_Info<OAS> CFI_Atom_Info;
- void cfiParse(class Parser<A>& parser, uint8_t* buffer, CFI_Atom_Info cfiArray[], uint32_t cfiCount);
+ void cfiParse(class Parser<A>& parser, uint8_t* buffer, CFI_Atom_Info cfiArray[], uint32_t& cfiCount, const pint_t cuStarts[], uint32_t cuCount);
bool needsRelocating();
static bool bigEndian();
uint32_t count();
void parse(class Parser<A>& parser, uint32_t cnt, Info array[]);
+ static bool encodingMeansUseDwarf(compact_unwind_encoding_t enc);
private:
virtual bool addFollowOnFixups() const { return false; }
virtual const char* unlabeledAtomName(Parser<A>& parser, pint_t addr) = 0;
- virtual ld::Atom::SymbolTableInclusion symbolTableInclusion() { return ld::Atom::symbolTableNotIn; }
+ virtual ld::Atom::SymbolTableInclusion symbolTableInclusion();
virtual pint_t elementSizeAtAddress(pint_t addr) = 0;
virtual ld::Atom::Scope scopeAtAddress(Parser<A>& parser, pint_t addr) { return ld::Atom::scopeLinkageUnit; }
virtual bool useElementAt(Parser<A>& parser,
struct Parser<A>::LabelAndCFIBreakIterator& it, pint_t addr) = 0;
virtual ld::Atom::Definition definition() { return ld::Atom::definitionRegular; }
virtual ld::Atom::Combine combine(Parser<A>& parser, pint_t addr) = 0;
- virtual bool ignoreLabel(const char* label) { return (label[0] == 'L'); }
+ virtual bool ignoreLabel(const char* label) const { return (label[0] == 'L'); }
};
+
template <typename A>
class FixedSizeSection : public ImplicitSizeSection<A>
{
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
+ virtual bool ignoreLabel(const char* label) const;
};
template <typename A>
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
+ virtual bool ignoreLabel(const char* label) const;
};
template <typename A>
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
+ virtual bool ignoreLabel(const char* label) const;
};
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Scope scopeAtAddress(Parser<A>& parser, pint_t addr);
virtual ld::Atom::Combine combine(Parser<A>&, pint_t);
- virtual bool ignoreLabel(const char* label) { return true; }
+ virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
static ld::Fixup::Kind fixupKind();
};
+template <typename A>
+class TLVPointerSection : public FixedSizeSection<A>
+{
+public:
+ TLVPointerSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
+ : FixedSizeSection<A>(parser, f, s) {}
+protected:
+ typedef typename A::P::uint_t pint_t;
+ typedef typename A::P P;
+
+ virtual ld::Atom::ContentType contentType() { return ld::Atom::typeTLVPointer; }
+ virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
+ virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "tlv_lazy_ptr"; }
+ virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
+ virtual ld::Atom::Combine combine(Parser<A>&, pint_t);
+ virtual bool ignoreLabel(const char* label) const { return true; }
+ virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
+ virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
+ const ld::IndirectBindingTable& ind) const;
+
+private:
+ static const char* targetName(const class Atom<A>* atom, const ld::IndirectBindingTable& ind, bool* isStatic);
+};
+
template <typename A>
class CFStringSection : public FixedSizeSection<A>
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "CFString"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return 4*sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndReferences; }
- virtual bool ignoreLabel(const char* label) { return true; }
+ virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
virtual ld::Atom::SymbolTableInclusion symbolTableInclusion() { return ld::Atom::symbolTableIn; }
virtual pint_t elementSizeAtAddress(pint_t addr);
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineNever; }
- virtual bool ignoreLabel(const char* label) { return true; }
+ virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const
{ return 0; }
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "objc-class-ref"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndReferences; }
- virtual bool ignoreLabel(const char* label) { return true; }
+ virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "objc-cat-list"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineNever; }
- virtual bool ignoreLabel(const char* label) { return true; }
+ virtual bool ignoreLabel(const char* label) const { return true; }
private:
const char* targetClassName(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
};
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "pointer-to-literal-cstring"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndReferences; }
- virtual bool ignoreLabel(const char* label) { return true; }
+ virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
virtual Atom<A>* findAtomByAddress(pint_t addr);
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "cstring"; }
virtual pint_t elementSizeAtAddress(pint_t addr);
- virtual bool ignoreLabel(const char* label);
+ virtual bool ignoreLabel(const char* label) const;
virtual bool useElementAt(Parser<A>& parser,
struct Parser<A>::LabelAndCFIBreakIterator& it, pint_t addr);
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndContent; }
{
public:
// overrides of ld::Atom
- virtual ld::File* file() const { return §().file(); }
- virtual bool translationUnitSource(const char** dir, const char** nm) const
- { return sect().file().translationUnitSource(dir, nm); }
+ virtual const ld::File* file() const;
+ virtual const char* translationUnitSource() const
+ { return sect().file().translationUnitSource(); }
virtual const char* name() const { return _name; }
virtual uint64_t size() const { return _size; }
virtual uint64_t objectAddress() const { return _objAddress; }
virtual ld::Atom::UnwindInfo::iterator endUnwind() const { return &machofile()._unwindInfos[_unwindInfoStartIndex+_unwindInfoCount]; }
virtual ld::Atom::LineInfo::iterator beginLineInfo() const{ return &machofile()._lineInfos[_lineInfoStartIndex]; }
virtual ld::Atom::LineInfo::iterator endLineInfo() const { return &machofile()._lineInfos[_lineInfoStartIndex+_lineInfoCount]; }
+ virtual void setFile(const ld::File* f);
private:
throwf("too may fixups in %s", name()); ++_fixupsCount; }
const uint8_t* contentPointer() const;
uint32_t fixupCount() const { return _fixupsCount; }
- void verifyAlignment() const;
+ void verifyAlignment(const macho_section<typename A::P>&) const;
typedef typename A::P P;
typedef typename A::P::E E;
parser.combineFromSymbol(sym), parser.scopeFromSymbol(sym),
parser.resolverFromSymbol(sym) ? ld::Atom::typeResolver : sct.contentType(),
parser.inclusionFromSymbol(sym),
- parser.dontDeadStripFromSymbol(sym) || sct.dontDeadStrip(),
+ (parser.dontDeadStripFromSymbol(sym) && !sct.dontDeadStripIfReferencesLive()) || sct.dontDeadStrip(),
parser.isThumbFromSymbol(sym), alias,
sct.alignmentForAddress(sym.n_value())),
_size(sz), _objAddress(sym.n_value()),
if ( _scope == ld::Atom::scopeGlobal &&
(sym.n_desc() & (N_WEAK_DEF|N_WEAK_REF)) == (N_WEAK_DEF|N_WEAK_REF) )
this->setAutoHide();
- this->verifyAlignment();
+ this->verifyAlignment(*sct.machoSection());
+ if ( sct.dontDeadStripIfReferencesLive() )
+ this->setDontDeadStripIfReferencesLive();
}
private:
_fixupsCount : kFixupCountBits,
_lineInfoCount : kLineInfoCountBits,
_unwindInfoCount : kUnwindInfoCountBits;
-
+
+ static std::map<const ld::Atom*, const ld::File*> _s_fileOverride;
};
+template <typename A>
+std::map<const ld::Atom*, const ld::File*> Atom<A>::_s_fileOverride;
+
+template <typename A>
+void Atom<A>::setFile(const ld::File* f) {
+ _s_fileOverride[this] = f;
+}
+template <typename A>
+const ld::File* Atom<A>::file() const
+{
+ std::map<const ld::Atom*, const ld::File*>::iterator pos = _s_fileOverride.find(this);
+ if ( pos != _s_fileOverride.end() )
+ return pos->second;
+
+ return §().file();
+}
template <typename A>
void Atom<A>::setFixupsRange(uint32_t startIndex, uint32_t count)
const uint8_t* Atom<A>::contentPointer() const
{
const macho_section<P>* sct = this->sect().machoSection();
+ if ( this->_objAddress > sct->addr() + sct->size() )
+ throwf("malformed .o file, symbol has address 0x%0llX which is outside range of its section", (uint64_t)this->_objAddress);
uint32_t fileOffset = sct->offset() - sct->addr() + this->_objAddress;
return this->sect().file().fileContent()+fileOffset;
}
}
template <>
-void Atom<arm>::verifyAlignment() const
+void Atom<arm>::verifyAlignment(const macho_section<P>&) const
{
if ( (this->section().type() == ld::Section::typeCode) && ! isThumb() ) {
if ( ((_objAddress % 4) != 0) || (this->alignment().powerOf2 < 2) )
}
}
+#if SUPPORT_ARCH_arm64
+template <>
+void Atom<arm64>::verifyAlignment(const macho_section<P>& sect) const
+{
+ if ( (this->section().type() == ld::Section::typeCode) && (sect.size() != 0) ) {
+ if ( ((_objAddress % 4) != 0) || (this->alignment().powerOf2 < 2) )
+ warning("arm64 function not 4-byte aligned: %s from %s", this->name(), this->file()->path());
+ }
+}
+#endif
+
template <typename A>
-void Atom<A>::verifyAlignment() const
+void Atom<A>::verifyAlignment(const macho_section<P>&) const
{
}
+class AliasAtom : public ld::Atom
+{
+public:
+ AliasAtom(const char* name, bool hidden, const ld::File* file, const char* aliasOfName) :
+ ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever,
+ (hidden ? ld::Atom::scopeLinkageUnit : ld::Atom::scopeGlobal),
+ ld::Atom::typeUnclassified, ld::Atom::symbolTableIn,
+ false, false, true, 0),
+ _file(file),
+ _name(name),
+ _fixup(0, ld::Fixup::k1of1, ld::Fixup::kindNoneFollowOn, ld::Fixup::bindingByNameUnbound, aliasOfName) { }
+
+ virtual const ld::File* file() const { return _file; }
+ virtual const char* translationUnitSource() const
+ { return NULL; }
+ virtual const char* name() const { return _name; }
+ virtual uint64_t size() const { return 0; }
+ virtual uint64_t objectAddress() const { return 0; }
+ virtual void copyRawContent(uint8_t buffer[]) const { }
+ virtual ld::Fixup::iterator fixupsBegin() const { return &((ld::Fixup*)&_fixup)[0]; }
+ virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; }
+
+private:
+ static ld::Section _s_section;
+
+ const ld::File* _file;
+ const char* _name;
+ ld::Fixup _fixup;
+};
+
+ld::Section AliasAtom::_s_section("__LD", "__aliases", ld::Section::typeTempAlias, true);
+
+
template <typename A>
class Parser
{
static bool validFile(const uint8_t* fileContent, bool subtypeMustMatch=false,
cpu_subtype_t subtype=0);
static const char* fileKind(const uint8_t* fileContent);
+ static Options::Platform findPlatform(const macho_header<typename A::P>* header);
static bool hasObjC2Categories(const uint8_t* fileContent);
+ static bool hasObjC1Categories(const uint8_t* fileContent);
+ static bool getNonLocalSymbols(const uint8_t* fileContnet, std::vector<const char*> &syms);
static ld::relocatable::File* parse(const uint8_t* fileContent, uint64_t fileLength,
- const char* path, time_t modTime, uint32_t ordinal,
+ const char* path, time_t modTime, ld::File::Ordinal ordinal,
const ParserOptions& opts) {
Parser p(fileContent, fileLength, path, modTime,
- ordinal, opts.convertUnwindInfo);
+ ordinal, opts.warnUnwindConversionProblems,
+ opts.keepDwarfUnwind, opts.forceDwarfConversion,
+ opts.neverConvertDwarf, opts.verboseOptimizationHints,
+ opts.ignoreMismatchPlatform);
return p.parse(opts);
}
_allFixups.push_back(FixupInAtom(src, c, k));
}
-
+ const char* path() { return _path; }
uint32_t symbolCount() { return _symbolCount; }
uint32_t indirectSymbol(uint32_t indirectIndex);
const macho_nlist<P>& symbolFromIndex(uint32_t index);
static bool isThumbFromSymbol(const macho_nlist<P>& sym);
static bool weakImportFromSymbol(const macho_nlist<P>& sym);
static bool resolverFromSymbol(const macho_nlist<P>& sym);
+ static bool altEntryFromSymbol(const macho_nlist<P>& sym);
uint32_t symbolIndexFromIndirectSectionAddress(pint_t,const macho_section<P>*);
const macho_section<P>* firstMachOSection() { return _sectionsStart; }
const macho_section<P>* machOSectionFromSectionIndex(uint32_t index);
unsigned int stubsSectionNum() { return _stubsSectionNum; }
void addDtraceExtraInfos(const SourceLocation& src, const char* provider);
const char* scanSymbolTableForAddress(uint64_t addr);
- bool convertUnwindInfo() { return _convertUnwindInfo; }
+ bool warnUnwindConversionProblems() { return _warnUnwindConversionProblems; }
+ bool hasDataInCodeLabels() { return _hasDataInCodeLabels; }
+ bool keepDwarfUnwind() { return _keepDwarfUnwind; }
+ bool forceDwarfConversion() { return _forceDwarfConversion; }
+ bool verboseOptimizationHints() { return _verboseOptimizationHints; }
+ bool neverConvertDwarf() { return _neverConvertDwarf; }
+ bool armUsesZeroCostExceptions() { return _armUsesZeroCostExceptions; }
+
+ macho_data_in_code_entry<P>* dataInCodeStart() { return _dataInCodeStart; }
+ macho_data_in_code_entry<P>* dataInCodeEnd() { return _dataInCodeEnd; }
+ const uint8_t* optimizationHintsStart() { return _lohStart; }
+ const uint8_t* optimizationHintsEnd() { return _lohEnd; }
+ bool hasOptimizationHints() { return _lohStart != _lohEnd; }
void addFixups(const SourceLocation& src, ld::Fixup::Kind kind, const TargetDesc& target);
: sortedSymbolIndexes(ssa), sortedSymbolCount(ssc), cfiStartsArray(cfisa),
cfiStartsCount(cfisc), fileHasOverlappingSymbols(ols),
newSection(false), cfiIndex(0), symIndex(0) {}
- bool next(Parser<A>& parser, uint32_t sectNum, pint_t startAddr, pint_t endAddr,
+ bool next(Parser<A>& parser, const Section<A>& sect, uint32_t sectNum, pint_t startAddr, pint_t endAddr,
pint_t* addr, pint_t* size, const macho_nlist<P>** sym);
pint_t peek(Parser<A>& parser, pint_t startAddr, pint_t endAddr);
void beginSection() { newSection = true; symIndex = 0; }
sectionTypeUTF16Strings, sectionTypeCFString, sectionTypeObjC2ClassRefs, typeObjC2CategoryList,
sectionTypeObjC1Classes, sectionTypeSymboled, sectionTypeObjC1ClassRefs,
sectionTypeTentativeDefinitions, sectionTypeAbsoluteSymbols, sectionTypeTLVDefs,
- sectionTypeCompactUnwind };
+ sectionTypeCompactUnwind, sectionTypeTLVPointers};
template <typename P>
struct MachOSectionAndSectionClass
Parser(const uint8_t* fileContent, uint64_t fileLength,
- const char* path, time_t modTime,
- uint32_t ordinal, bool convertUnwindInfo);
+ const char* path, time_t modTime, ld::File::Ordinal ordinal,
+ bool warnUnwindConversionProblems, bool keepDwarfUnwind,
+ bool forceDwarfConversion, bool neverConvertDwarf,
+ bool verboseOptimizationHints, bool ignoreMismatchPlatform);
ld::relocatable::File* parse(const ParserOptions& opts);
- uint8_t loadCommandSizeMask();
- bool parseLoadCommands();
+ static uint8_t loadCommandSizeMask();
+ bool parseLoadCommands(Options::Platform platform, uint32_t minOSVersion, bool simulator, bool ignoreMismatchPlatform);
void makeSections();
void prescanSymbolTable();
void makeSortedSymbolsArray(uint32_t symArray[], const uint32_t sectionArray[]);
void parseDebugInfo();
void parseStabs();
+ void appendAliasAtoms(uint8_t* atomBuffer);
static bool isConstFunStabs(const char *stabStr);
bool read_comp_unit(const char ** name, const char ** comp_dir,
uint64_t *stmt_list);
- const char* getDwarfString(uint64_t form, const uint8_t* p);
+ pint_t realAddr(pint_t addr);
+ const char* getDwarfString(uint64_t form, const uint8_t*& p);
+ uint64_t getDwarfOffset(uint64_t form, const uint8_t*& di, bool dwarf64);
bool skip_form(const uint8_t ** offset, const uint8_t * end,
uint64_t form, uint8_t addr_size, bool dwarf64);
uint32_t _fileLength;
const char* _path;
time_t _modTime;
- uint32_t _ordinal;
+ ld::File::Ordinal _ordinal;
// filled in by parseLoadCommands()
File<A>* _file;
const macho_nlist<P>* _symbols;
uint32_t _symbolCount;
+ uint32_t _indirectSymbolCount;
const char* _strings;
uint32_t _stringsSize;
const uint32_t* _indirectTable;
const macho_section<P>* _sectionsStart;
uint32_t _machOSectionsCount;
bool _hasUUID;
-
+ macho_data_in_code_entry<P>* _dataInCodeStart;
+ macho_data_in_code_entry<P>* _dataInCodeEnd;
+ const uint8_t* _lohStart;
+ const uint8_t* _lohEnd;
+
// filled in by parse()
CFISection<A>* _EHFrameSection;
CUSection<A>* _compactUnwindSection;
bool _hasLongBranchStubs;
bool _AppleObjc; // FSF has objc that uses different data layout
bool _overlappingSymbols;
- bool _convertUnwindInfo;
+ bool _warnUnwindConversionProblems;
+ bool _hasDataInCodeLabels;
+ bool _keepDwarfUnwind;
+ bool _forceDwarfConversion;
+ bool _neverConvertDwarf;
+ bool _verboseOptimizationHints;
+ bool _armUsesZeroCostExceptions;
+ bool _ignoreMismatchPlatform;
unsigned int _stubsSectionNum;
const macho_section<P>* _stubsMachOSection;
std::vector<const char*> _dtraceProviderInfo;
template <typename A>
Parser<A>::Parser(const uint8_t* fileContent, uint64_t fileLength, const char* path, time_t modTime,
- uint32_t ordinal, bool convertDUI)
+ ld::File::Ordinal ordinal, bool convertDUI, bool keepDwarfUnwind, bool forceDwarfConversion,
+ bool neverConvertDwarf, bool verboseOptimizationHints, bool ignoreMismatchPlatform)
: _fileContent(fileContent), _fileLength(fileLength), _path(path), _modTime(modTime),
_ordinal(ordinal), _file(NULL),
- _symbols(NULL), _symbolCount(0), _strings(NULL), _stringsSize(0),
+ _symbols(NULL), _symbolCount(0), _indirectSymbolCount(0), _strings(NULL), _stringsSize(0),
_indirectTable(NULL), _indirectTableCount(0),
_undefinedStartIndex(0), _undefinedEndIndex(0),
_sectionsStart(NULL), _machOSectionsCount(0), _hasUUID(false),
+ _dataInCodeStart(NULL), _dataInCodeEnd(NULL),
+ _lohStart(NULL), _lohEnd(NULL),
_EHFrameSection(NULL), _compactUnwindSection(NULL), _absoluteSection(NULL),
_tentativeDefinitionCount(0), _absoluteSymbolCount(0),
_symbolsInSections(0), _hasLongBranchStubs(false), _AppleObjc(false),
- _overlappingSymbols(false), _convertUnwindInfo(convertDUI),
+ _overlappingSymbols(false), _warnUnwindConversionProblems(convertDUI), _hasDataInCodeLabels(false),
+ _keepDwarfUnwind(keepDwarfUnwind), _forceDwarfConversion(forceDwarfConversion),
+ _neverConvertDwarf(neverConvertDwarf),
+ _verboseOptimizationHints(verboseOptimizationHints),
+ _ignoreMismatchPlatform(ignoreMismatchPlatform),
_stubsSectionNum(0), _stubsMachOSection(NULL)
{
}
-template <>
-bool Parser<ppc>::validFile(const uint8_t* fileContent, bool, cpu_subtype_t)
-{
- const macho_header<P>* header = (const macho_header<P>*)fileContent;
- if ( header->magic() != MH_MAGIC )
- return false;
- if ( header->cputype() != CPU_TYPE_POWERPC )
- return false;
- if ( header->filetype() != MH_OBJECT )
- return false;
- return true;
-}
-
-template <>
-bool Parser<ppc64>::validFile(const uint8_t* fileContent, bool, cpu_subtype_t)
-{
- const macho_header<P>* header = (const macho_header<P>*)fileContent;
- if ( header->magic() != MH_MAGIC_64 )
- return false;
- if ( header->cputype() != CPU_TYPE_POWERPC64 )
- return false;
- if ( header->filetype() != MH_OBJECT )
- return false;
- return true;
-}
template <>
bool Parser<x86>::validFile(const uint8_t* fileContent, bool, cpu_subtype_t)
template <>
-const char* Parser<ppc>::fileKind(const uint8_t* fileContent)
+bool Parser<arm64>::validFile(const uint8_t* fileContent, bool subtypeMustMatch, cpu_subtype_t subtype)
{
const macho_header<P>* header = (const macho_header<P>*)fileContent;
- if ( header->magic() != MH_MAGIC )
- return NULL;
- if ( header->cputype() != CPU_TYPE_POWERPC )
- return NULL;
- switch ( header->cpusubtype() ) {
- case CPU_SUBTYPE_POWERPC_750:
- return "ppc750";
- case CPU_SUBTYPE_POWERPC_7400:
- return "ppc7400";
- case CPU_SUBTYPE_POWERPC_7450:
- return "ppc7450";
- case CPU_SUBTYPE_POWERPC_970:
- return "ppc970";
- case CPU_SUBTYPE_POWERPC_ALL:
- return "ppc";
- }
- return "ppc???";
+ if ( header->magic() != MH_MAGIC_64 )
+ return false;
+ if ( header->cputype() != CPU_TYPE_ARM64 )
+ return false;
+ if ( header->filetype() != MH_OBJECT )
+ return false;
+ return true;
}
-template <>
-const char* Parser<ppc64>::fileKind(const uint8_t* fileContent)
-{
- const macho_header<P>* header = (const macho_header<P>*)fileContent;
- if ( header->magic() != MH_MAGIC )
- return NULL;
- if ( header->cputype() != CPU_TYPE_POWERPC64 )
- return NULL;
- return "ppc64";
-}
template <>
const char* Parser<x86>::fileKind(const uint8_t* fileContent)
const char* Parser<x86_64>::fileKind(const uint8_t* fileContent)
{
const macho_header<P>* header = (const macho_header<P>*)fileContent;
- if ( header->magic() != MH_MAGIC )
+ if ( header->magic() != MH_MAGIC_64 )
return NULL;
if ( header->cputype() != CPU_TYPE_X86_64 )
return NULL;
return NULL;
if ( header->cputype() != CPU_TYPE_ARM )
return NULL;
- for (const ARMSubType* t=ARMSubTypes; t->subTypeName != NULL; ++t) {
- if ( t->subType == (cpu_subtype_t)header->cpusubtype() ) {
- return t->subTypeName;
+ for (const ArchInfo* t=archInfoArray; t->archName != NULL; ++t) {
+ if ( (t->cpuType == CPU_TYPE_ARM) && ((cpu_subtype_t)header->cpusubtype() == t->cpuSubType) ) {
+ return t->archName;
}
}
return "arm???";
}
+#if SUPPORT_ARCH_arm64
+template <>
+const char* Parser<arm64>::fileKind(const uint8_t* fileContent)
+{
+ const macho_header<P>* header = (const macho_header<P>*)fileContent;
+ if ( header->magic() != MH_MAGIC_64 )
+ return NULL;
+ if ( header->cputype() != CPU_TYPE_ARM64 )
+ return NULL;
+ return "arm64";
+}
+#endif
template <typename A>
bool Parser<A>::hasObjC2Categories(const uint8_t* fileContent)
return false;
}
+
+template <typename A>
+bool Parser<A>::hasObjC1Categories(const uint8_t* fileContent)
+{
+ const macho_header<P>* header = (const macho_header<P>*)fileContent;
+ const uint32_t cmd_count = header->ncmds();
+ const macho_load_command<P>* const cmds = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>));
+ const macho_load_command<P>* const cmdsEnd = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>) + header->sizeofcmds());
+ const macho_load_command<P>* cmd = cmds;
+ for (uint32_t i = 0; i < cmd_count; ++i) {
+ if ( cmd->cmd() == macho_segment_command<P>::CMD ) {
+ const macho_segment_command<P>* segment = (macho_segment_command<P>*)cmd;
+ const macho_section<P>* sectionsStart = (macho_section<P>*)((char*)segment + sizeof(macho_segment_command<P>));
+ for (uint32_t si=0; si < segment->nsects(); ++si) {
+ const macho_section<P>* sect = §ionsStart[si];
+ if ( (sect->size() > 0)
+ && (strcmp(sect->sectname(), "__category") == 0)
+ && (strcmp(sect->segname(), "__OBJC") == 0) ) {
+ return true;
+ }
+ }
+ }
+ cmd = (const macho_load_command<P>*)(((char*)cmd)+cmd->cmdsize());
+ if ( cmd > cmdsEnd )
+ throwf("malformed mach-o file, load command #%d is outside size of load commands", i);
+ }
+ return false;
+}
+
+
+template <typename A>
+bool Parser<A>::getNonLocalSymbols(const uint8_t* fileContent, std::vector<const char*> &syms)
+{
+ const macho_header<P>* header = (const macho_header<P>*)fileContent;
+ const uint32_t cmd_count = header->ncmds();
+ const macho_load_command<P>* const cmds = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>));
+ const macho_load_command<P>* const cmdsEnd = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>) + header->sizeofcmds());
+ const macho_load_command<P>* cmd = cmds;
+ for (uint32_t i = 0; i < cmd_count; ++i) {
+ if ( cmd->cmd() == LC_SYMTAB ) {
+ const macho_symtab_command<P>* symtab = (macho_symtab_command<P>*)cmd;
+ uint32_t symbolCount = symtab->nsyms();
+ const macho_nlist<P>* symbols = (const macho_nlist<P>*)(fileContent + symtab->symoff());
+ const char* strings = (char*)fileContent + symtab->stroff();
+ for (uint32_t i = 0; i < symbolCount; ++i) {
+ // ignore stabs and count only ext symbols
+ if ( (symbols[i].n_type() & N_STAB) == 0 &&
+ (symbols[i].n_type() & N_EXT) != 0 ) {
+ const char* symName = &strings[symbols[i].n_strx()];
+ syms.push_back(symName);
+ }
+ }
+ return true;
+ }
+ cmd = (const macho_load_command<P>*)(((char*)cmd)+cmd->cmdsize());
+ if ( cmd > cmdsEnd )
+ throwf("malformed mach-o file, load command #%d is outside size of load commands", i);
+ }
+ return false;
+}
+
+
template <typename A>
int Parser<A>::pointerSorter(const void* l, const void* r)
{
// was becuase of a label, the symbol). Returns false when no more chunks.
//
template <typename A>
-bool Parser<A>::LabelAndCFIBreakIterator::next(Parser<A>& parser, uint32_t sectNum, pint_t startAddr, pint_t endAddr,
+bool Parser<A>::LabelAndCFIBreakIterator::next(Parser<A>& parser, const Section<A>& sect, uint32_t sectNum, pint_t startAddr, pint_t endAddr,
pint_t* addr, pint_t* size, const macho_nlist<P>** symbol)
{
// may not be a label on start of section, but need atom demarcation there
// advance symIndex until we get to the first label at or past the start of this section
while ( symIndex < sortedSymbolCount ) {
const macho_nlist<P>& sym = parser.symbolFromIndex(sortedSymbolIndexes[symIndex]);
- pint_t nextSymbolAddr = sym.n_value();
- //fprintf(stderr, "sectNum=%d, nextSymbolAddr=0x%08llX, name=%s\n", sectNum, (uint64_t)nextSymbolAddr, parser.nameFromSymbol(sym));
- if ( (nextSymbolAddr > startAddr) || ((nextSymbolAddr == startAddr) && (sym.n_sect() == sectNum)) )
- break;
+ if ( ! sect.ignoreLabel(parser.nameFromSymbol(sym)) ) {
+ pint_t nextSymbolAddr = sym.n_value();
+ //fprintf(stderr, "sectNum=%d, nextSymbolAddr=0x%08llX, name=%s\n", sectNum, (uint64_t)nextSymbolAddr, parser.nameFromSymbol(sym));
+ if ( (nextSymbolAddr > startAddr) || ((nextSymbolAddr == startAddr) && (sym.n_sect() == sectNum)) )
+ break;
+ }
++symIndex;
}
if ( symIndex < sortedSymbolCount ) {
*symbol = NULL;
return true;
}
- // no symbols left in whole file, so entire section is one chunk
+ // no symbols in section, check CFI
+ if ( cfiIndex < cfiStartsCount ) {
+ pint_t nextCfiAddr = cfiStartsArray[cfiIndex];
+ if ( nextCfiAddr < endAddr ) {
+ // use cfi
+ ++cfiIndex;
+ *addr = nextCfiAddr;
+ *size = peek(parser, startAddr, endAddr) - nextCfiAddr;
+ *symbol = NULL;
+ return true;
+ }
+ }
+ // no cfi, so whole section is one chunk
*addr = startAddr;
*size = endAddr - startAddr;
*symbol = NULL;
return false;
}
+template <>
+typename arm::P::uint_t Parser<arm>::realAddr(typename arm::P::uint_t addr)
+{
+ return addr & (-2);
+}
+
+template <typename A>
+typename A::P::uint_t Parser<A>::realAddr(typename A::P::uint_t addr)
+{
+ return addr;
+}
+
+#define STACK_ALLOC_IF_SMALL(_type, _name, _actual_count, _maxCount) \
+ _type* _name = NULL; \
+ uint32_t _name##_count = 1; \
+ if ( _actual_count > _maxCount ) \
+ _name = (_type*)malloc(sizeof(_type) * _actual_count); \
+ else \
+ _name##_count = _actual_count; \
+ _type _name##_buffer[_name##_count]; \
+ if ( _name == NULL ) \
+ _name = _name##_buffer;
template <typename A>
// create file object
_file = new File<A>(_path, _modTime, _fileContent, _ordinal);
+ // set input source
+ _file->setSourceKind(opts.srcKind);
+
// respond to -t option
if ( opts.logAllFiles )
printf("%s\n", _path);
+
+ _armUsesZeroCostExceptions = opts.armUsesZeroCostExceptions;
// parse start of mach-o file
- if ( ! parseLoadCommands() )
+ if ( ! parseLoadCommands(opts.platform, opts.minOSVersion, opts.simulator, opts.ignoreMismatchPlatform) )
return _file;
- // make array of
+ // make array of
uint32_t sortedSectionIndexes[_machOSectionsCount];
this->makeSortedSectionsArray(sortedSectionIndexes);
uint32_t countOfCUs = 0;
if ( _compactUnwindSection != NULL )
countOfCUs = _compactUnwindSection->count();
- uint8_t cuInfoBuffer[sizeof(typename CUSection<A>::Info) * countOfCUs];
- typename CUSection<A>::Info* cuInfoArray = (typename CUSection<A>::Info*)cuInfoBuffer;
+ // stack allocate (if not too large) cuInfoBuffer
+ STACK_ALLOC_IF_SMALL(typename CUSection<A>::Info, cuInfoArray, countOfCUs, 1024);
if ( countOfCUs != 0 )
_compactUnwindSection->parse(*this, countOfCUs, cuInfoArray);
+
+ // create lists of address that already have compact unwind and thus don't need the dwarf parsed
+ unsigned cuLsdaCount = 0;
+ pint_t cuStarts[countOfCUs];
+ for (uint32_t i=0; i < countOfCUs; ++i) {
+ if ( CUSection<A>::encodingMeansUseDwarf(cuInfoArray[i].compactUnwindInfo) )
+ cuStarts[i] = -1;
+ else
+ cuStarts[i] = cuInfoArray[i].functionStartAddress;
+ if ( cuInfoArray[i].lsdaAddress != 0 )
+ ++cuLsdaCount;
+ }
+
// if it exists, do special early parsing of __eh_frame section
- // stack allocate array of CFI_Atom_Info
+ // stack allocate (if not too large) array of CFI_Atom_Info
uint32_t countOfCFIs = 0;
if ( _EHFrameSection != NULL )
- countOfCFIs = _EHFrameSection->cfiCount();
- typename CFISection<A>::CFI_Atom_Info cfiArray[countOfCFIs];
+ countOfCFIs = _EHFrameSection->cfiCount(*this);
+ STACK_ALLOC_IF_SMALL(typename CFISection<A>::CFI_Atom_Info, cfiArray, countOfCFIs, 1024);
+
// stack allocate (if not too large) a copy of __eh_frame to apply relocations to
- uint8_t* ehBuffer = NULL;
- uint32_t stackAllocSize = 0;
- if ( (countOfCFIs != 0) && _EHFrameSection->needsRelocating() ) {
- uint32_t sectSize = _EHFrameSection->machoSection()->size();
- if ( sectSize > 50*1024 )
- ehBuffer = (uint8_t*)malloc(sectSize);
- else
- stackAllocSize = sectSize;
- }
- uint32_t ehStackBuffer[1+stackAllocSize/4]; // make 4-byte aligned stack bufffer
- if ( ehBuffer == NULL )
- ehBuffer = (uint8_t*)&ehStackBuffer;
+ uint32_t sectSize = 4;
+ if ( (countOfCFIs != 0) && _EHFrameSection->needsRelocating() )
+ sectSize = _EHFrameSection->machoSection()->size()+4;
+ STACK_ALLOC_IF_SMALL(uint8_t, ehBuffer, sectSize, 50*1024);
uint32_t cfiStartsCount = 0;
if ( countOfCFIs != 0 ) {
- _EHFrameSection->cfiParse(*this, ehBuffer, cfiArray, countOfCFIs);
+ _EHFrameSection->cfiParse(*this, ehBuffer, cfiArray, countOfCFIs, cuStarts, countOfCUs);
// count functions and lsdas
for(uint32_t i=0; i < countOfCFIs; ++i) {
if ( cfiArray[i].isCIE )
continue;
- //fprintf(stderr, "cfiArray[i].func = 0x%08llX, cfiArray[i].lsda = 0x%08llX, encoding=0x%08X\n",
- // (uint64_t)cfiArray[i].u.fdeInfo.function.targetAddress,
- // (uint64_t)cfiArray[i].u.fdeInfo.lsda.targetAddress,
+ //fprintf(stderr, "cfiArray[i].func = 0x%08llX, cfiArray[i].lsda = 0x%08llX, encoding=0x%08X\n",
+ // (uint64_t)cfiArray[i].u.fdeInfo.function.targetAddress,
+ // (uint64_t)cfiArray[i].u.fdeInfo.lsda.targetAddress,
// cfiArray[i].u.fdeInfo.compactUnwindInfo);
if ( cfiArray[i].u.fdeInfo.function.targetAddress != CFI_INVALID_ADDRESS )
++cfiStartsCount;
CFI_CU_InfoArrays cfis(cfiArray, countOfCFIs, cuInfoArray, countOfCUs);
// create sorted array of function starts and lsda starts
- pint_t cfiStartsArray[cfiStartsCount];
+ pint_t cfiStartsArray[cfiStartsCount+cuLsdaCount];
uint32_t countOfFDEs = 0;
+ uint32_t cfiStartsArrayCount = 0;
if ( countOfCFIs != 0 ) {
- int index = 0;
for(uint32_t i=0; i < countOfCFIs; ++i) {
if ( cfiArray[i].isCIE )
continue;
if ( cfiArray[i].u.fdeInfo.function.targetAddress != CFI_INVALID_ADDRESS )
- cfiStartsArray[index++] = cfiArray[i].u.fdeInfo.function.targetAddress;
+ cfiStartsArray[cfiStartsArrayCount++] = realAddr(cfiArray[i].u.fdeInfo.function.targetAddress);
if ( cfiArray[i].u.fdeInfo.lsda.targetAddress != CFI_INVALID_ADDRESS )
- cfiStartsArray[index++] = cfiArray[i].u.fdeInfo.lsda.targetAddress;
+ cfiStartsArray[cfiStartsArrayCount++] = cfiArray[i].u.fdeInfo.lsda.targetAddress;
++countOfFDEs;
}
- ::qsort(cfiStartsArray, cfiStartsCount, sizeof(pint_t), pointerSorter);
+ }
+ if ( cuLsdaCount != 0 ) {
+ // merge in an lsda info from compact unwind
+ for (uint32_t i=0; i < countOfCUs; ++i) {
+ if ( cuInfoArray[i].lsdaAddress == 0 )
+ continue;
+ // append to cfiStartsArray if not already in that list
+ bool found = false;
+ for(uint32_t j=0; j < cfiStartsArrayCount; ++j) {
+ if ( cfiStartsArray[j] == cuInfoArray[i].lsdaAddress )
+ found = true;
+ }
+ if ( ! found ) {
+ cfiStartsArray[cfiStartsArrayCount++] = cuInfoArray[i].lsdaAddress;
+ }
+ }
+ }
+ if ( cfiStartsArrayCount != 0 ) {
+ ::qsort(cfiStartsArray, cfiStartsArrayCount, sizeof(pint_t), pointerSorter);
#ifndef NDEBUG
// scan for FDEs claming the same function
- for(int i=1; i < index; ++i) {
+ for(uint32_t i=1; i < cfiStartsArrayCount; ++i) {
assert( cfiStartsArray[i] != cfiStartsArray[i-1] );
}
#endif
// figure out how many atoms will be allocated and allocate
LabelAndCFIBreakIterator breakIterator(sortedSymbolIndexes, _symbolsInSections, cfiStartsArray,
- cfiStartsCount, _overlappingSymbols);
+ cfiStartsArrayCount, _overlappingSymbols);
uint32_t computedAtomCount = 0;
for (uint32_t i=0; i < sectionsCount; ++i ) {
breakIterator.beginSection();
// have each section append atoms to _atomsArray
LabelAndCFIBreakIterator breakIterator2(sortedSymbolIndexes, _symbolsInSections, cfiStartsArray,
- cfiStartsCount, _overlappingSymbols);
+ cfiStartsArrayCount, _overlappingSymbols);
for (uint32_t i=0; i < sectionsCount; ++i ) {
uint8_t* atoms = _file->_atomsArray + _file->_atomsArrayCount*sizeof(Atom<A>);
breakIterator2.beginSection();
p += sizeof(Atom<A>);
}
assert(fixupOffset == _allFixups.size());
- _file->_fixups.reserve(fixupOffset);
+ _file->_fixups.resize(fixupOffset);
// copy each fixup for each atom
for(typename std::vector<FixupInAtom>::iterator it=_allFixups.begin(); it != _allFixups.end(); ++it) {
_file->_unwindInfos.push_back(info);
Atom<A>* func = findAtomByAddress(cfiArray[i].u.fdeInfo.function.targetAddress);
func->setUnwindInfoRange(_file->_unwindInfos.size()-1, 1);
+ //fprintf(stderr, "cu from dwarf =0x%08X, atom=%s\n", info.unwindInfo, func->name());
}
}
// apply compact infos in __LD,__compact_unwind section to each function
assert(info->function != NULL);
ld::Atom::UnwindInfo ui;
ui.startOffset = info->functionStartAddress - info->function->objectAddress();
- ui.unwindInfo = info->compactUnwindInfo;
+ ui.unwindInfo = info->compactUnwindInfo;
_file->_unwindInfos.push_back(ui);
- // if previous is for same function, extend range
- if ( info->function == lastFunc ) {
- if ( lastEnd != ui.startOffset ) {
- if ( lastEnd < ui.startOffset )
- warning("__LD,__compact_unwind entries for %s have a gap at offset 0x%0X", info->function->name(), lastEnd);
- else
- warning("__LD,__compact_unwind entries for %s overlap at offset 0x%0X", info->function->name(), lastEnd);
+ // don't override with converted cu with "use dwarf" cu, if forcing dwarf conversion
+ if ( !_forceDwarfConversion || !CUSection<A>::encodingMeansUseDwarf(info->compactUnwindInfo) ) {
+ //fprintf(stderr, "cu=0x%08X, atom=%s\n", ui.unwindInfo, info->function->name());
+ // if previous is for same function, extend range
+ if ( info->function == lastFunc ) {
+ if ( lastEnd != ui.startOffset ) {
+ if ( lastEnd < ui.startOffset )
+ warning("__LD,__compact_unwind entries for %s have a gap at offset 0x%0X", info->function->name(), lastEnd);
+ else
+ warning("__LD,__compact_unwind entries for %s overlap at offset 0x%0X", info->function->name(), lastEnd);
+ }
+ lastFunc->extendUnwindInfoRange();
}
- lastFunc->extendUnwindInfoRange();
+ else
+ info->function->setUnwindInfoRange(_file->_unwindInfos.size()-1, 1);
+ lastFunc = info->function;
+ lastEnd = ui.startOffset + info->rangeLength;
}
- else
- info->function->setUnwindInfoRange(_file->_unwindInfos.size()-1, 1);
- lastFunc = info->function;
- lastEnd = ui.startOffset + info->rangeLength;
}
+ // process indirect symbols which become AliasAtoms
+ _file->_aliasAtomsArray = NULL;
+ _file->_aliasAtomsArrayCount = 0;
+ if ( _indirectSymbolCount != 0 ) {
+ _file->_aliasAtomsArrayCount = _indirectSymbolCount;
+ _file->_aliasAtomsArray = new uint8_t[_file->_aliasAtomsArrayCount*sizeof(AliasAtom)];
+ this->appendAliasAtoms(_file->_aliasAtomsArray);
+ }
+
+
// parse dwarf debug info to get line info
this->parseDebugInfo();
return _file;
}
+static void versionToString(uint32_t value, char buffer[32])
+{
+ if ( value & 0xFF )
+ sprintf(buffer, "%d.%d.%d", value >> 16, (value >> 8) & 0xFF, value & 0xFF);
+ else
+ sprintf(buffer, "%d.%d", value >> 16, (value >> 8) & 0xFF);
+}
-
-template <> uint8_t Parser<ppc>::loadCommandSizeMask() { return 0x03; }
-template <> uint8_t Parser<ppc64>::loadCommandSizeMask() { return 0x07; }
template <> uint8_t Parser<x86>::loadCommandSizeMask() { return 0x03; }
template <> uint8_t Parser<x86_64>::loadCommandSizeMask() { return 0x07; }
template <> uint8_t Parser<arm>::loadCommandSizeMask() { return 0x03; }
+template <> uint8_t Parser<arm64>::loadCommandSizeMask() { return 0x07; }
template <typename A>
-bool Parser<A>::parseLoadCommands()
+bool Parser<A>::parseLoadCommands(Options::Platform platform, uint32_t linkMinOSVersion, bool simulator, bool ignoreMismatchPlatform)
{
const macho_header<P>* header = (const macho_header<P>*)_fileContent;
// <rdar://problem/5394172> an empty .o file with zero load commands will crash linker
if ( cmd_count == 0 )
return false;
+ Options::Platform lcPlatform = Options::kPlatformUnknown;
const macho_load_command<P>* const cmds = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>));
const macho_load_command<P>* const cmdsEnd = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>) + header->sizeofcmds());
const macho_load_command<P>* cmd = cmds;
case LC_UUID:
_hasUUID = true;
break;
-
+ case LC_DATA_IN_CODE:
+ {
+ const macho_linkedit_data_command<P>* dc = (macho_linkedit_data_command<P>*)cmd;
+ _dataInCodeStart = (macho_data_in_code_entry<P>*)(_fileContent + dc->dataoff());
+ _dataInCodeEnd = (macho_data_in_code_entry<P>*)(_fileContent + dc->dataoff() + dc->datasize());
+ if ( _dataInCodeEnd > (macho_data_in_code_entry<P>*)endOfFile )
+ throw "LC_DATA_IN_CODE table extends beyond end of file";
+ }
+ break;
+ case LC_LINKER_OPTION:
+ {
+ const macho_linker_option_command<P>* loc = (macho_linker_option_command<P>*)cmd;
+ const char* buffer = loc->buffer();
+ _file->_linkerOptions.resize(_file->_linkerOptions.size() + 1);
+ std::vector<const char*>& vec = _file->_linkerOptions.back();
+ for (uint32_t j=0; j < loc->count(); ++j) {
+ vec.push_back(buffer);
+ buffer += strlen(buffer) + 1;
+ }
+ if ( buffer > ((char*)cmd + loc->cmdsize()) )
+ throw "malformed LC_LINKER_OPTION";
+ }
+ break;
+ case LC_LINKER_OPTIMIZATION_HINTS:
+ {
+ const macho_linkedit_data_command<P>* loh = (macho_linkedit_data_command<P>*)cmd;
+ _lohStart = _fileContent + loh->dataoff();
+ _lohEnd = _fileContent + loh->dataoff() + loh->datasize();
+ if ( _lohEnd > endOfFile )
+ throw "LC_LINKER_OPTIMIZATION_HINTS table extends beyond end of file";
+ }
+ break;
+ case LC_VERSION_MIN_MACOSX:
+ case LC_VERSION_MIN_IPHONEOS:
+ case LC_VERSION_MIN_WATCHOS:
+ #if SUPPORT_APPLE_TV
+ case LC_VERSION_MIN_TVOS:
+ #endif
+ if ( ignoreMismatchPlatform )
+ break;
+ _file->_platform = cmd->cmd();
+ lcPlatform = Options::platformForLoadCommand(cmd->cmd());
+ _file->_minOSVersion = ((macho_version_min_command<P>*)cmd)->version();
+ break;
default:
if ( cmd->cmd() == macho_segment_command<P>::CMD ) {
if ( segment != NULL )
if ( cmd > cmdsEnd )
throwf("malformed mach-o file, load command #%d is outside size of load commands", i);
}
+ // arm/arm64 objects are default to ios platform if not set.
+ // rdar://problem/21746314
+ if (lcPlatform == Options::kPlatformUnknown &&
+ (std::is_same<A, arm>::value || std::is_same<A, arm64>::value))
+ lcPlatform = Options::kPlatformiOS;
+
+ // Check platform cross-linking.
+ if ( !ignoreMismatchPlatform ) {
+ if ( lcPlatform != platform ) {
+ switch (platform) {
+ case Options::kPlatformOSX:
+ case Options::kPlatformiOS:
+ if ( lcPlatform == Options::kPlatformUnknown )
+ break;
+ // fall through if the Platform is not Unknown
+ case Options::kPlatformWatchOS:
+ // WatchOS errors on cross-linking all the time.
+ throwf("building for %s%s, but linking in object file built for %s,",
+ Options::platformName(platform), (simulator ? " simulator" : ""),
+ Options::platformName(lcPlatform));
+ break;
+ #if SUPPORT_APPLE_TV
+ case Options::kPlatform_tvOS:
+ // tvOS is a warning temporarily. rdar://problem/21746965
+ if (platform == Options::kPlatform_tvOS)
+ warning("URGENT: building for %s%s, but linking in object file (%s) built for %s. "
+ "Note: This will be an error in the future.",
+ Options::platformName(platform), (simulator ? " simulator" : ""), path(),
+ Options::platformName(lcPlatform));
+ break;
+ #endif
+ case Options::kPlatformUnknown:
+ // skip if the target platform is unknown
+ break;
+ }
+ }
+ if ( linkMinOSVersion && (_file->_minOSVersion > linkMinOSVersion) ) {
+ char t1[32];
+ char t2[32];
+ versionToString(_file->_minOSVersion, t1);
+ versionToString(linkMinOSVersion, t2);
+ warning("object file (%s) was built for newer %s version (%s) than being linked (%s)",
+ _path, Options::platformName(lcPlatform), t1, t2);
+ }
+ }
+
// record range of sections
if ( segment == NULL )
return true;
}
+template <typename A>
+Options::Platform Parser<A>::findPlatform(const macho_header<P>* header)
+{
+ const uint32_t cmd_count = header->ncmds();
+ if ( cmd_count == 0 )
+ return Options::kPlatformUnknown;
+ const macho_load_command<P>* const cmds = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>));
+ const macho_load_command<P>* const cmdsEnd = (macho_load_command<P>*)((char*)header + sizeof(macho_header<P>) + header->sizeofcmds());
+ const macho_load_command<P>* cmd = cmds;
+ for (uint32_t i = 0; i < cmd_count; ++i) {
+ uint32_t size = cmd->cmdsize();
+ if ( (size & loadCommandSizeMask()) != 0 )
+ throwf("load command #%d has a unaligned size", i);
+ const uint8_t* endOfCmd = ((uint8_t*)cmd)+cmd->cmdsize();
+ if ( endOfCmd > (uint8_t*)cmdsEnd )
+ throwf("load command #%d extends beyond the end of the load commands", i);
+ switch (cmd->cmd()) {
+ case LC_VERSION_MIN_MACOSX:
+ return Options::kPlatformOSX;
+ case LC_VERSION_MIN_IPHONEOS:
+ return Options::kPlatformiOS;
+ }
+ cmd = (const macho_load_command<P>*)(((char*)cmd)+cmd->cmdsize());
+ if ( cmd > cmdsEnd )
+ throwf("malformed mach-o file, load command #%d is outside size of load commands", i);
+ }
+ return Options::kPlatformUnknown;
+}
+
template <typename A>
void Parser<A>::prescanSymbolTable()
_tentativeDefinitionCount = 0;
_absoluteSymbolCount = 0;
_symbolsInSections = 0;
+ _hasDataInCodeLabels = false;
for (uint32_t i=0; i < this->_symbolCount; ++i) {
const macho_nlist<P>& sym = symbolFromIndex(i);
// ignore stabs
}
continue;
}
-
+ else if ( ((sym.n_type() & N_TYPE) == N_INDR) && ((sym.n_type() & N_EXT) != 0) ) {
+ _indirectSymbolCount++;
+ continue;
+ }
+
// count absolute symbols
if ( (sym.n_type() & N_TYPE) == N_ABS ) {
const char* absName = this->nameFromSymbol(sym);
continue;
// 'L' labels do not denote atom breaks
- if ( symbolName[0] == 'L' )
+ if ( symbolName[0] == 'L' ) {
+ // <rdar://problem/9218847> Formalize data in code with L$start$ labels
+ if ( strncmp(symbolName, "L$start$", 8) == 0 )
+ _hasDataInCodeLabels = true;
continue;
-
+ }
// how many def syms in each section
if ( sym.n_sect() > _machOSectionsCount )
throw "bad n_sect in symbol table";
}
}
+template <typename A>
+void Parser<A>::appendAliasAtoms(uint8_t* p)
+{
+ for (uint32_t i=0; i < this->_symbolCount; ++i) {
+ const macho_nlist<P>& sym = symbolFromIndex(i);
+ // ignore stabs
+ if ( (sym.n_type() & N_STAB) != 0 )
+ continue;
+
+ // only look at N_INDR symbols
+ if ( (sym.n_type() & N_TYPE) != N_INDR )
+ continue;
+
+ // skip non-external aliases
+ if ( (sym.n_type() & N_EXT) == 0 )
+ continue;
+
+ const char* symbolName = this->nameFromSymbol(sym);
+ const char* aliasOfName = &_strings[sym.n_value()];
+ bool isHiddenVisibility = (sym.n_type() & N_PEXT);
+ AliasAtom* allocatedSpace = (AliasAtom*)p;
+ new (allocatedSpace) AliasAtom(symbolName, isHiddenVisibility, _file, aliasOfName);
+ p += sizeof(AliasAtom);
+ }
+}
+
+
+
template <typename A>
int Parser<A>::sectionIndexSorter(void* extra, const void* l, const void* r)
{
}
}
// two symbols in same section, means one is an alias
+ // if one is ltmp*, make it an alias (sort first)
+ const char* leftName = parser->nameFromSymbol(leftSym);
+ const char* rightName = parser->nameFromSymbol(rightSym);
+ bool leftIsTmp = strncmp(leftName, "ltmp", 4);
+ bool rightIsTmp = strncmp(rightName, "ltmp", 4);
+ if ( leftIsTmp != rightIsTmp ) {
+ return (rightIsTmp ? -1 : 1);
+ }
+
// if only one is global, make the other an alias (sort first)
if ( (leftSym.n_type() & N_EXT) != (rightSym.n_type() & N_EXT) ) {
if ( (rightSym.n_type() & N_EXT) != 0 )
else
return 1;
}
- // if both are global, make alphabetically last one be the alias
- return ( strcmp(parser->nameFromSymbol(rightSym), parser->nameFromSymbol(leftSym)) );
+ // if both are global, sort alphabetically. earlier one will be the alias
+ return ( strcmp(rightName, leftName) );
}
else if ( result < 0 )
return -1;
// sort by symbol table address
ParserAndSectionsArray extra = { this, sectionArray };
::qsort_r(array, _symbolsInSections, sizeof(uint32_t), &extra, &symbolIndexSorter);
+
// look for two symbols at same address
_overlappingSymbols = false;
if ( symbolFromIndex(array[i-1]).n_value() == symbolFromIndex(array[i]).n_value() ) {
//fprintf(stderr, "overlapping symbols at 0x%08llX\n", symbolFromIndex(array[i-1]).n_value());
_overlappingSymbols = true;
+ break;
}
}
}
}
-
template <typename A>
void Parser<A>::makeSections()
{
// allocate raw storage for all section objects on stack
MachOSectionAndSectionClass<P>* machOSects = (MachOSectionAndSectionClass<P>*)machOSectsStorage;
unsigned int count = 0;
+ // local variable for bitcode parsing
+ const macho_section<P>* bitcodeSect = NULL;
+ const macho_section<P>* cmdlineSect = NULL;
+ const macho_section<P>* swiftCmdlineSect = NULL;
+ const macho_section<P>* bundleSect = NULL;
+ bool bitcodeAsm = false;
+
for (uint32_t i=0; i < _machOSectionsCount; ++i) {
const macho_section<P>* sect = &_sectionsStart[i];
if ( (sect->flags() & S_ATTR_DEBUG) != 0 ) {
}
}
}
+ if ( strcmp(sect->segname(), "__LLVM") == 0 ) {
+ if ( strncmp(sect->sectname(), "__bitcode", 9) == 0 ) {
+ bitcodeSect = sect;
+ } else if ( strncmp(sect->sectname(), "__cmdline", 9) == 0 ) {
+ cmdlineSect = sect;
+ } else if ( strncmp(sect->sectname(), "__swift_cmdline", 15) == 0 ) {
+ swiftCmdlineSect = sect;
+ } else if ( strncmp(sect->sectname(), "__bundle", 8) == 0 ) {
+ bundleSect = sect;
+ } else if ( strncmp(sect->sectname(), "__asm", 5) == 0 ) {
+ bitcodeAsm = true;
+ }
+ // If it is not single input for ld -r, don't count the section
+ // otherwise, fall through and add it to the sections.
+ if (_file->sourceKind() != ld::relocatable::File::kSourceSingle)
+ continue;
+ }
// ignore empty __OBJC sections
if ( (sect->size() == 0) && (strcmp(sect->segname(), "__OBJC") == 0) )
continue;
// };
// #define OBJC_IMAGE_SUPPORTS_GC 2
// #define OBJC_IMAGE_GC_ONLY 4
+ // #define OBJC_IMAGE_IS_SIMULATED 32
//
const uint32_t* contents = (uint32_t*)(_file->fileContent()+sect->offset());
if ( (sect->size() >= 8) && (contents[0] == 0) ) {
_file->_objConstraint = ld::File::objcConstraintGC;
else if ( (flags & 2) == 2 )
_file->_objConstraint = ld::File::objcConstraintRetainReleaseOrGC;
+ else if ( (flags & 32) == 32 )
+ _file->_objConstraint = ld::File::objcConstraintRetainReleaseForSimulator;
else
_file->_objConstraint = ld::File::objcConstraintRetainRelease;
- if ( (flags & 1) == 1 )
- _file->_ojcReplacmentClass = true;
+ _file->_swiftVersion = ((flags >> 8) & 0xFF);
if ( sect->size() > 8 ) {
warning("section %s/%s has unexpectedly large size %llu in %s",
sect->segname(), Section<A>::makeSectionName(sect), sect->size(), _file->path());
totalSectionsSize += sizeof(NonLazyPointerSection<A>);
machOSects[count++].type = sectionTypeNonLazy;
break;
+ case S_THREAD_LOCAL_VARIABLE_POINTERS:
+ totalSectionsSize += sizeof(TLVPointerSection<A>);
+ machOSects[count++].type = sectionTypeTLVPointers;
+ break;
case S_LITERAL_POINTERS:
if ( (strcmp(sect->segname(), "__OBJC") == 0) && (strcmp(sect->sectname(), "__cls_refs") == 0) ) {
totalSectionsSize += sizeof(Objc1ClassReferences<A>);
totalSectionsSize += sizeof(TLVDefsSection<A>);
machOSects[count++].type = sectionTypeTLVDefs;
break;
- case S_THREAD_LOCAL_VARIABLE_POINTERS:
default:
throwf("unknown section type %d", sect->flags() & SECTION_TYPE);
}
}
+
+ // Create bitcode
+ if ( bitcodeSect != NULL ) {
+ if ( cmdlineSect != NULL )
+ _file->_bitcode = std::unique_ptr<ld::Bitcode>(new ld::ClangBitcode(&_fileContent[bitcodeSect->offset()], bitcodeSect->size(),
+ &_fileContent[cmdlineSect->offset()], cmdlineSect->size()));
+ else if ( swiftCmdlineSect != NULL )
+ _file->_bitcode = std::unique_ptr<ld::Bitcode>(new ld::SwiftBitcode(&_fileContent[bitcodeSect->offset()], bitcodeSect->size(),
+ &_fileContent[swiftCmdlineSect->offset()], swiftCmdlineSect->size()));
+ else
+ throwf("Object file with bitcode missing cmdline options: %s", _file->path());
+ }
+ else if ( bundleSect != NULL )
+ _file->_bitcode = std::unique_ptr<ld::Bitcode>(new ld::BundleBitcode(&_fileContent[bundleSect->offset()], bundleSect->size()));
+ else if ( bitcodeAsm )
+ _file->_bitcode = std::unique_ptr<ld::Bitcode>(new ld::AsmBitcode(_fileContent, _fileLength));
// sort by address (mach-o object files don't aways have sections sorted)
::qsort(machOSects, count, sizeof(MachOSectionAndSectionClass<P>), MachOSectionAndSectionClass<P>::sorter);
*objects++ = new (space) NonLazyPointerSection<A>(*this, *_file, machOSects[i].sect);
space += sizeof(NonLazyPointerSection<A>);
break;
+ case sectionTypeTLVPointers:
+ *objects++ = new (space) TLVPointerSection<A>(*this, *_file, machOSects[i].sect);
+ space += sizeof(TLVPointerSection<A>);
+ break;
case sectionTypeCFI:
_EHFrameSection = new (space) CFISection<A>(*this, *_file, machOSects[i].sect);
*objects++ = _EHFrameSection;
continue;
// return with exact match
- if ( sym.n_value() == addr )
- return nameFromSymbol(sym);
+ if ( sym.n_value() == addr ) {
+ const char* name = nameFromSymbol(sym);
+ if ( strncmp(name, "ltmp", 4) != 0 )
+ return name;
+ // treat 'ltmp*' labels as close match
+ closestSymAddr = sym.n_value();
+ closestSymName = name;
+ }
// record closest seen so far
if ( (sym.n_value() < addr) && ((sym.n_value() > closestSymAddr) || (closestSymName == NULL)) )
case ld::Fixup::kindStoreThumbBranch22:
firstKind = ld::Fixup::kindStoreTargetAddressThumbBranch22;
break;
- case ld::Fixup::kindStorePPCBranch24:
- firstKind = ld::Fixup::kindStoreTargetAddressPPCBranch24;
+#if SUPPORT_ARCH_arm64
+ case ld::Fixup::kindStoreARM64Branch26:
+ firstKind = ld::Fixup::kindStoreTargetAddressARM64Branch26;
+ break;
+ case ld::Fixup::kindStoreARM64Page21:
+ firstKind = ld::Fixup::kindStoreTargetAddressARM64Page21;
+ break;
+ case ld::Fixup::kindStoreARM64PageOff12:
+ firstKind = ld::Fixup::kindStoreTargetAddressARM64PageOff12;
+ break;
+ case ld::Fixup::kindStoreARM64GOTLoadPage21:
+ firstKind = ld::Fixup::kindStoreTargetAddressARM64GOTLoadPage21;
break;
+ case ld::Fixup::kindStoreARM64GOTLoadPageOff12:
+ firstKind = ld::Fixup::kindStoreTargetAddressARM64GOTLoadPageOff12;
+ break;
+ case ld::Fixup::kindStoreARM64TLVPLoadPage21:
+ firstKind = ld::Fixup::kindStoreTargetAddressARM64TLVPLoadPage21;
+ break;
+ case ld::Fixup::kindStoreARM64TLVPLoadPageOff12:
+ firstKind = ld::Fixup::kindStoreTargetAddressARM64TLVPLoadPageOff12;
+ break;
+#endif
default:
combined = false;
cl = ld::Fixup::k1of2;
// backing string in CFStrings should always be direct
addFixup(src, cl, firstKind, target.atom);
}
+ else if ( (src.atom == target.atom) && (target.atom->combine() == ld::Atom::combineByName) ) {
+ // reference to self should always be direct
+ addFixup(src, cl, firstKind, target.atom);
+ }
else {
// change direct fixup to by-name fixup
addFixup(src, cl, firstKind, false, target.atom->name());
return ( sym.n_desc() & N_SYMBOL_RESOLVER );
}
+template <typename A>
+bool Parser<A>::altEntryFromSymbol(const macho_nlist<P>& sym)
+{
+ return ( sym.n_desc() & N_ALT_ENTRY );
+}
+
/* Skip over a LEB128 value (signed or unsigned). */
static void
sz = 4;
break;
+ case DW_FORM_sec_offset:
+ sz = sizeof(typename A::P::uint_t);
+ break;
+
+ case DW_FORM_exprloc:
+ sz = read_uleb128 (offset, end);
+ break;
+
+ case DW_FORM_flag_present:
+ sz = 0;
+ break;
+
+ case DW_FORM_ref_sig8:
+ sz = 8;
+ break;
+
default:
return false;
}
template <typename A>
-const char* Parser<A>::getDwarfString(uint64_t form, const uint8_t* p)
+const char* Parser<A>::getDwarfString(uint64_t form, const uint8_t*& di)
{
- if ( form == DW_FORM_string )
- return (const char*)p;
- else if ( form == DW_FORM_strp ) {
- uint32_t offset = E::get32(*((uint32_t*)p));
- const char* dwarfStrings = (char*)_file->fileContent() + _file->_dwarfDebugStringSect->offset();
- if ( offset > _file->_dwarfDebugStringSect->size() ) {
- warning("unknown dwarf DW_FORM_strp (offset=0x%08X) is too big in %s\n", offset, this->_path);
- return NULL;
- }
- return &dwarfStrings[offset];
+ uint32_t offset;
+ const char* dwarfStrings;
+ const char* result = NULL;
+ switch (form) {
+ case DW_FORM_string:
+ result = (const char*)di;
+ di += strlen(result) + 1;
+ break;
+ case DW_FORM_strp:
+ offset = E::get32(*((uint32_t*)di));
+ dwarfStrings = (char*)_file->fileContent() + _file->_dwarfDebugStringSect->offset();
+ if ( offset < _file->_dwarfDebugStringSect->size() )
+ result = &dwarfStrings[offset];
+ else
+ warning("dwarf DW_FORM_strp (offset=0x%08X) is too big in %s", offset, this->_path);
+ di += 4;
+ break;
+ default:
+ warning("unknown dwarf string encoding (form=%lld) in %s", form, this->_path);
+ break;
}
- warning("unknown dwarf string encoding (form=%lld) in %s\n", form, this->_path);
- return NULL;
+ return result;
+}
+
+template <typename A>
+uint64_t Parser<A>::getDwarfOffset(uint64_t form, const uint8_t*& di, bool dwarf64)
+{
+ if ( form == DW_FORM_sec_offset )
+ form = (dwarf64 ? DW_FORM_data8 : DW_FORM_data4);
+ uint64_t result = -1;
+ switch (form) {
+ case DW_FORM_data4:
+ result = A::P::E::get32(*(uint32_t*)di);
+ di += 4;
+ break;
+ case DW_FORM_data8:
+ result = A::P::E::get64(*(uint64_t*)di);
+ di += 8;
+ break;
+ default:
+ warning("unknown dwarf DW_FORM_ for DW_AT_stmt_list in %s", this->_path);
+ }
+ return result;
}
return;
uint64_t stmtList;
- if ( !read_comp_unit(&_file->_dwarfTranslationUnitFile, &_file->_dwarfTranslationUnitDir, &stmtList) ) {
+ const char* tuDir;
+ const char* tuName;
+ if ( !read_comp_unit(&tuName, &tuDir, &stmtList) ) {
// if can't parse dwarf, warn and give up
- _file->_dwarfTranslationUnitFile = NULL;
- _file->_dwarfTranslationUnitDir = NULL;
+ _file->_dwarfTranslationUnitPath = NULL;
warning("can't parse dwarf compilation unit info in %s", _path);
_file->_debugInfoKind = ld::relocatable::File::kDebugInfoNone;
return;
}
+ if ( (tuName != NULL) && (tuName[0] == '/') ) {
+ _file->_dwarfTranslationUnitPath = tuName;
+ }
+ else if ( (tuDir != NULL) && (tuName != NULL) ) {
+ asprintf((char**)&(_file->_dwarfTranslationUnitPath), "%s/%s", tuDir, tuName);
+ }
+ else if ( tuDir == NULL ) {
+ _file->_dwarfTranslationUnitPath = tuName;
+ }
+ else {
+ _file->_dwarfTranslationUnitPath = NULL;
+ }
// add line number info to atoms from dwarf
std::vector<AtomAndLineInfo<A> > entries;
p += sizeof(Atom<A>);
}
assert(liOffset == entries.size());
- _file->_lineInfos.reserve(liOffset);
+ _file->_lineInfos.resize(liOffset);
// copy each line info for each atom
for (typename std::vector<AtomAndLineInfo<A> >::iterator it = entries.begin(); it != entries.end(); ++it) {
case N_LSYM:
case N_RSYM:
case N_PSYM:
+ case N_AST:
// not associated with an atom, just copy
stab.string = symString;
break;
return false;
vers = A::P::E::get16(*(uint16_t*)di);
- if (vers < 2 || vers > 3)
+ if (vers < 2 || vers > 4)
/* DWARF version wrong for this code.
Chances are we could continue anyway, but we don't know for sure. */
return false;
return false;
else if (attr == 0)
return true;
-
if (form == DW_FORM_indirect)
form = read_uleb128 (&di, end);
- if (attr == DW_AT_name)
- *name = getDwarfString(form, di);
- else if (attr == DW_AT_comp_dir)
- *comp_dir = getDwarfString(form, di);
- else if (attr == DW_AT_stmt_list && form == DW_FORM_data4)
- *stmt_list = A::P::E::get32(*(uint32_t*)di);
- else if (attr == DW_AT_stmt_list && form == DW_FORM_data8)
- *stmt_list = A::P::E::get64(*(uint64_t*)di);
- if (! skip_form (&di, end, form, address_size, dwarf64))
- return false;
+ switch (attr) {
+ case DW_AT_name:
+ *name = getDwarfString(form, di);
+ break;
+ case DW_AT_comp_dir:
+ *comp_dir = getDwarfString(form, di);
+ break;
+ case DW_AT_stmt_list:
+ *stmt_list = getDwarfOffset(form, di, dwarf64);
+ break;
+ default:
+ if (! skip_form (&di, end, form, address_size, dwarf64))
+ return false;
+ }
}
}
}
template <typename A>
-bool File<A>::translationUnitSource(const char** dir, const char** name) const
+const char* File<A>::translationUnitSource() const
{
- if ( _debugInfoKind == ld::relocatable::File::kDebugInfoDwarf ) {
- *dir = _dwarfTranslationUnitDir;
- *name = _dwarfTranslationUnitFile;
- return (_dwarfTranslationUnitFile != NULL);
- }
- return false;
+ return _dwarfTranslationUnitPath;
}
-
-
template <typename A>
bool File<A>::forEachAtom(ld::File::AtomHandler& handler) const
{
handler.doAtom(*((Atom<A>*)p));
p += sizeof(Atom<A>);
}
- return (_atomsArrayCount != 0);
+ p = _aliasAtomsArray;
+ for(int i=_aliasAtomsArrayCount; i > 0; --i) {
+ handler.doAtom(*((AliasAtom*)p));
+ p += sizeof(AliasAtom);
+ }
+
+ return (_atomsArrayCount != 0) || (_aliasAtomsArrayCount != 0);
}
template <typename A>
return ld::Section::typeCode;
else if ( strcmp(sect->sectname(), "__StaticInit") == 0 )
return ld::Section::typeCode;
+ else if ( strcmp(sect->sectname(), "__constructor") == 0 )
+ return ld::Section::typeInitializerPointers;
}
else if ( strcmp(sect->segname(), "__DATA") == 0 ) {
if ( strcmp(sect->sectname(), "__cfstring") == 0 )
return ld::Section::typeTLVZeroFill;
case S_THREAD_LOCAL_VARIABLES:
return ld::Section::typeTLVDefs;
+ case S_THREAD_LOCAL_VARIABLE_POINTERS:
+ return ld::Section::typeTLVPointers;
case S_THREAD_LOCAL_INIT_FUNCTION_POINTERS:
return ld::Section::typeTLVInitializerPointers;
}
ld::Atom::Alignment Section<A>::alignmentForAddress(pint_t addr)
{
const uint32_t sectionAlignment = this->_machOSection->align();
- return ld::Atom::Alignment(sectionAlignment, (addr % (1 << sectionAlignment)));
+ uint32_t modulus = (addr % (1 << sectionAlignment));
+ if ( modulus > 0xFFFF )
+ warning("alignment for symbol at address 0x%08llX in %s exceeds 2^16", (uint64_t)addr, this->file().path());
+ return ld::Atom::Alignment(sectionAlignment, modulus);
}
template <typename A>
return 1 + (this->_machOSection - parser.firstMachOSection());
}
-// libunwind does not support ppc64
-template <> uint32_t CFISection<ppc64>::cfiCount() { return 0; }
// arm does not have zero cost exceptions
-template <> uint32_t CFISection<arm>::cfiCount() { return 0; }
+template <>
+uint32_t CFISection<arm>::cfiCount(Parser<arm>& parser)
+{
+ if ( parser.armUsesZeroCostExceptions() ) {
+ // create ObjectAddressSpace object for use by libunwind
+ OAS oas(*this, (uint8_t*)this->file().fileContent()+this->_machOSection->offset());
+ return libunwind::CFI_Parser<OAS>::getCFICount(oas,
+ this->_machOSection->addr(), this->_machOSection->size());
+ }
+ return 0;
+}
template <typename A>
-uint32_t CFISection<A>::cfiCount()
+uint32_t CFISection<A>::cfiCount(Parser<A>& parser)
{
// create ObjectAddressSpace object for use by libunwind
OAS oas(*this, (uint8_t*)this->file().fileContent()+this->_machOSection->offset());
void CFISection<A>::warnFunc(void* ref, uint64_t funcAddr, const char* msg)
{
Parser<A>* parser = (Parser<A>*)ref;
- if ( ! parser->convertUnwindInfo() )
+ if ( ! parser->warnUnwindConversionProblems() )
return;
if ( funcAddr != CFI_INVALID_ADDRESS ) {
// atoms are not constructed yet, so scan symbol table for labels
return true;
}
+template <>
+bool CFISection<arm64>::needsRelocating()
+{
+ return true;
+}
+
template <typename A>
bool CFISection<A>::needsRelocating()
{
}
template <>
-void CFISection<x86_64>::cfiParse(class Parser<x86_64>& parser, uint8_t* buffer,
+void CFISection<x86_64>::cfiParse(class Parser<x86_64>& parser, uint8_t* buffer,
libunwind::CFI_Atom_Info<CFISection<x86_64>::OAS>::CFI_Atom_Info cfiArray[],
- uint32_t count)
+ uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
// copy __eh_frame data to buffer
memcpy(buffer, file().fileContent() + this->_machOSection->offset(), this->_machOSection->size());
}
}
-
// create ObjectAddressSpace object for use by libunwind
OAS oas(*this, buffer);
const char* msg;
msg = libunwind::DwarfInstructions<OAS, libunwind::Registers_x86_64>::parseCFIs(
oas, this->_machOSection->addr(), this->_machOSection->size(),
+ cuStarts, cuCount, parser.keepDwarfUnwind(), parser.forceDwarfConversion(), parser.neverConvertDwarf(),
cfiArray, count, (void*)&parser, warnFunc);
if ( msg != NULL )
throwf("malformed __eh_frame section: %s", msg);
template <>
void CFISection<x86>::cfiParse(class Parser<x86>& parser, uint8_t* buffer,
libunwind::CFI_Atom_Info<CFISection<x86>::OAS>::CFI_Atom_Info cfiArray[],
- uint32_t count)
+ uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
// create ObjectAddressSpace object for use by libunwind
OAS oas(*this, (uint8_t*)this->file().fileContent()+this->_machOSection->offset());
const char* msg;
msg = libunwind::DwarfInstructions<OAS, libunwind::Registers_x86>::parseCFIs(
oas, this->_machOSection->addr(), this->_machOSection->size(),
+ cuStarts, cuCount, parser.keepDwarfUnwind(), parser.forceDwarfConversion(), parser.neverConvertDwarf(),
cfiArray, count, (void*)&parser, warnFunc);
if ( msg != NULL )
throwf("malformed __eh_frame section: %s", msg);
}
-// need to change libunwind parseCFIs() to work for ppc
+
+
template <>
-void CFISection<ppc>::cfiParse(class Parser<ppc>& parser, uint8_t* buffer,
- libunwind::CFI_Atom_Info<CFISection<ppc>::OAS>::CFI_Atom_Info cfiArray[],
- uint32_t count)
+void CFISection<arm>::cfiParse(class Parser<arm>& parser, uint8_t* buffer,
+ libunwind::CFI_Atom_Info<CFISection<arm>::OAS>::CFI_Atom_Info cfiArray[],
+ uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
+ if ( !parser.armUsesZeroCostExceptions() ) {
+ // most arm do not use zero cost exceptions
+ assert(count == 0);
+ return;
+ }
// create ObjectAddressSpace object for use by libunwind
OAS oas(*this, (uint8_t*)this->file().fileContent()+this->_machOSection->offset());
// use libuwind to parse __eh_frame data into array of CFI_Atom_Info
const char* msg;
- msg = libunwind::DwarfInstructions<OAS, libunwind::Registers_ppc>::parseCFIs(
+ msg = libunwind::DwarfInstructions<OAS, libunwind::Registers_arm>::parseCFIs(
oas, this->_machOSection->addr(), this->_machOSection->size(),
+ cuStarts, cuCount, parser.keepDwarfUnwind(), parser.forceDwarfConversion(), parser.neverConvertDwarf(),
cfiArray, count, (void*)&parser, warnFunc);
if ( msg != NULL )
throwf("malformed __eh_frame section: %s", msg);
}
-template <>
-void CFISection<ppc64>::cfiParse(class Parser<ppc64>& parser, uint8_t* buffer,
- libunwind::CFI_Atom_Info<CFISection<ppc64>::OAS>::CFI_Atom_Info cfiArray[],
- uint32_t count)
-{
- // libunwind does not support ppc64
- assert(count == 0);
-}
+
+
template <>
-void CFISection<arm>::cfiParse(class Parser<arm>& parser, uint8_t* buffer,
- libunwind::CFI_Atom_Info<CFISection<arm>::OAS>::CFI_Atom_Info cfiArray[],
- uint32_t count)
+void CFISection<arm64>::cfiParse(class Parser<arm64>& parser, uint8_t* buffer,
+ libunwind::CFI_Atom_Info<CFISection<arm64>::OAS>::CFI_Atom_Info cfiArray[],
+ uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
- // arm does not use zero cost exceptions
- assert(count == 0);
-}
+ // copy __eh_frame data to buffer
+ memcpy(buffer, file().fileContent() + this->_machOSection->offset(), this->_machOSection->size());
+ // and apply relocations
+ const macho_relocation_info<P>* relocs = (macho_relocation_info<P>*)(file().fileContent() + this->_machOSection->reloff());
+ const macho_relocation_info<P>* relocsEnd = &relocs[this->_machOSection->nreloc()];
+ for (const macho_relocation_info<P>* reloc = relocs; reloc < relocsEnd; ++reloc) {
+ uint64_t* p64 = (uint64_t*)&buffer[reloc->r_address()];
+ uint32_t* p32 = (uint32_t*)&buffer[reloc->r_address()];
+ uint32_t addend32 = E::get32(*p32);
+ uint64_t addend64 = E::get64(*p64);
+ uint64_t value = 0;
+ switch ( reloc->r_type() ) {
+ case ARM64_RELOC_SUBTRACTOR:
+ value = 0 - parser.symbolFromIndex(reloc->r_symbolnum()).n_value();
+ ++reloc;
+ if ( reloc->r_extern() )
+ value += parser.symbolFromIndex(reloc->r_symbolnum()).n_value();
+ break;
+ case ARM64_RELOC_UNSIGNED:
+ value = parser.symbolFromIndex(reloc->r_symbolnum()).n_value();
+ break;
+ case ARM64_RELOC_POINTER_TO_GOT:
+ // this is used for the reference to the personality function in CIEs
+ // store the symbol number of the personality function for later use as a Fixup
+ value = reloc->r_symbolnum();
+ addend32 = 0;
+ addend64 = 0;
+ break;
+ default:
+ fprintf(stderr, "CFISection::cfiParse() unexpected relocation type at r_address=0x%08X\n", reloc->r_address());
+ break;
+ }
+ switch ( reloc->r_length() ) {
+ case 3:
+ E::set64(*p64, value + addend64);
+ break;
+ case 2:
+ E::set32(*p32, value + addend32);
+ break;
+ default:
+ fprintf(stderr, "CFISection::cfiParse() unexpected relocation size at r_address=0x%08X\n", reloc->r_address());
+ break;
+ }
+ }
+
+
+ // create ObjectAddressSpace object for use by libunwind
+ OAS oas(*this, buffer);
+
+ // use libuwind to parse __eh_frame data into array of CFI_Atom_Info
+ const char* msg;
+ msg = libunwind::DwarfInstructions<OAS, libunwind::Registers_arm64>::parseCFIs(
+ oas, this->_machOSection->addr(), this->_machOSection->size(),
+ cuStarts, cuCount, parser.keepDwarfUnwind(), parser.forceDwarfConversion(), parser.neverConvertDwarf(),
+ cfiArray, count, (void*)&parser, warnFunc);
+ if ( msg != NULL )
+ throwf("malformed __eh_frame section: %s", msg);
+}
template <typename A>
template <> bool CFISection<x86_64>::bigEndian() { return false; }
template <> bool CFISection<x86>::bigEndian() { return false; }
template <> bool CFISection<arm>::bigEndian() { return false; }
-template <> bool CFISection<ppc>::bigEndian() { return true; }
-template <> bool CFISection<ppc64>::bigEndian() { return true; }
+template <> bool CFISection<arm64>::bigEndian() { return false; }
template <>
}
}
+#if SUPPORT_ARCH_arm64
+template <>
+void CFISection<arm64>::addCiePersonalityFixups(class Parser<arm64>& parser, const CFI_Atom_Info* cieInfo)
+{
+ uint8_t personalityEncoding = cieInfo->u.cieInfo.personality.encodingOfTargetAddress;
+ if ( personalityEncoding == 0x9B ) {
+ // compiler always produces ARM64_RELOC_GOT r_pcrel=1 to personality function
+ // CFISection<arm64>::cfiParse() set targetAddress to be symbolIndex + addressInCIE
+ uint32_t symbolIndex = cieInfo->u.cieInfo.personality.targetAddress
+ - cieInfo->address - cieInfo->u.cieInfo.personality.offsetInCFI;
+ const macho_nlist<P>& sym = parser.symbolFromIndex(symbolIndex);
+ const char* personalityName = parser.nameFromSymbol(sym);
+
+ Atom<arm64>* cieAtom = this->findAtomByAddress(cieInfo->address);
+ Parser<arm64>::SourceLocation src(cieAtom, cieInfo->u.cieInfo.personality.offsetInCFI);
+ parser.addFixup(src, ld::Fixup::k1of2, ld::Fixup::kindSetTargetAddress, false, personalityName);
+ parser.addFixup(src, ld::Fixup::k2of2, ld::Fixup::kindStoreARM64PCRelToGOT);
+ }
+ else if ( personalityEncoding != 0 ) {
+ throwf("unsupported address encoding (%02X) of personality function in CIE",
+ personalityEncoding);
+ }
+}
+#endif
template <>
-void CFISection<ppc>::addCiePersonalityFixups(class Parser<ppc>& parser, const CFI_Atom_Info* cieInfo)
+void CFISection<arm>::addCiePersonalityFixups(class Parser<arm>& parser, const CFI_Atom_Info* cieInfo)
{
uint8_t personalityEncoding = cieInfo->u.cieInfo.personality.encodingOfTargetAddress;
if ( (personalityEncoding == 0x9B) || (personalityEncoding == 0x90) ) {
uint32_t offsetInCFI = cieInfo->u.cieInfo.personality.offsetInCFI;
uint32_t nlpAddr = cieInfo->u.cieInfo.personality.targetAddress;
- Atom<ppc>* cieAtom = this->findAtomByAddress(cieInfo->address);
- Atom<ppc>* nlpAtom = parser.findAtomByAddress(nlpAddr);
+ Atom<arm>* cieAtom = this->findAtomByAddress(cieInfo->address);
+ Atom<arm>* nlpAtom = parser.findAtomByAddress(nlpAddr);
assert(nlpAtom->contentType() == ld::Atom::typeNonLazyPointer);
- Parser<ppc>::SourceLocation src(cieAtom, cieInfo->u.cieInfo.personality.offsetInCFI);
+ Parser<arm>::SourceLocation src(cieAtom, cieInfo->u.cieInfo.personality.offsetInCFI);
parser.addFixup(src, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, ld::Fixup::bindingByContentBound, nlpAtom);
parser.addFixup(src, ld::Fixup::k2of4, ld::Fixup::kindSubtractTargetAddress, cieAtom);
parser.addFixup(src, ld::Fixup::k3of4, ld::Fixup::kindSubtractAddend, offsetInCFI);
- parser.addFixup(src, ld::Fixup::k4of4, ld::Fixup::kindStoreBigEndian32);
+ parser.addFixup(src, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian32);
}
else if ( personalityEncoding != 0 ) {
- throwf("unsupported address encoding (%02X) of personality function in CIE",
- personalityEncoding);
+ throwf("unsupported address encoding (%02X) of personality function in CIE", personalityEncoding);
}
}
+
template <typename A>
void CFISection<A>::addCiePersonalityFixups(class Parser<A>& parser, const CFI_Atom_Info* cieInfo)
{
- // FIX ME
- assert(0);
+ assert(0 && "addCiePersonalityFixups() not implemented for arch");
}
template <typename A>
template <>
const char* CUSection<x86_64>::personalityName(class Parser<x86_64>& parser, const macho_relocation_info<x86_64::P>* reloc)
{
- assert(reloc->r_extern() && "reloc not extern on personality column in __compact_unwind section");
- assert((reloc->r_type() == X86_64_RELOC_UNSIGNED) && "wrong reloc type on personality column in __compact_unwind section");
- const macho_nlist<P>& sym = parser.symbolFromIndex(reloc->r_symbolnum());
- return parser.nameFromSymbol(sym);
+ if ( reloc->r_extern() ) {
+ assert((reloc->r_type() == X86_64_RELOC_UNSIGNED) && "wrong reloc type on personality column in __compact_unwind section");
+ const macho_nlist<P>& sym = parser.symbolFromIndex(reloc->r_symbolnum());
+ return parser.nameFromSymbol(sym);
+ }
+ else {
+ const pint_t* content = (pint_t*)(this->file().fileContent() + this->_machOSection->offset() + reloc->r_address());
+ pint_t personalityAddr = *content;
+ assert((parser.sectionForAddress(personalityAddr)->type() == ld::Section::typeCode) && "personality column in __compact_unwind section is not pointer to function");
+ // atoms may not be constructed yet, so scan symbol table for labels
+ const char* name = parser.scanSymbolTableForAddress(personalityAddr);
+ return name;
+ }
}
template <>
const char* CUSection<x86>::personalityName(class Parser<x86>& parser, const macho_relocation_info<x86::P>* reloc)
{
- assert(reloc->r_extern() && "reloc not extern on personality column in __compact_unwind section");
- assert((reloc->r_type() == GENERIC_RELOC_VANILLA) && "wrong reloc type on personality column in __compact_unwind section");
- const macho_nlist<P>& sym = parser.symbolFromIndex(reloc->r_symbolnum());
- return parser.nameFromSymbol(sym);
+ if ( reloc->r_extern() ) {
+ assert((reloc->r_type() == GENERIC_RELOC_VANILLA) && "wrong reloc type on personality column in __compact_unwind section");
+ const macho_nlist<P>& sym = parser.symbolFromIndex(reloc->r_symbolnum());
+ return parser.nameFromSymbol(sym);
+ }
+ else {
+ // support __LD, __compact_unwind personality entries which are pointer to personality non-lazy pointer
+ const pint_t* content = (pint_t*)(this->file().fileContent() + this->_machOSection->offset() + reloc->r_address());
+ pint_t nlPointerAddr = *content;
+ Section<x86>* nlSection = parser.sectionForAddress(nlPointerAddr);
+ if ( nlSection->type() == ld::Section::typeCode ) {
+ // personality function is defined in this .o file, so this is a direct reference to it
+ // atoms may not be constructed yet, so scan symbol table for labels
+ const char* name = parser.scanSymbolTableForAddress(nlPointerAddr);
+ return name;
+ }
+ else {
+ uint32_t symIndex = parser.symbolIndexFromIndirectSectionAddress(nlPointerAddr, nlSection->machoSection());
+ const macho_nlist<P>& nlSymbol = parser.symbolFromIndex(symIndex);
+ return parser.nameFromSymbol(nlSymbol);
+ }
+ }
+}
+
+#if SUPPORT_ARCH_arm64
+template <>
+const char* CUSection<arm64>::personalityName(class Parser<arm64>& parser, const macho_relocation_info<arm64::P>* reloc)
+{
+ if ( reloc->r_extern() ) {
+ assert((reloc->r_type() == ARM64_RELOC_UNSIGNED) && "wrong reloc type on personality column in __compact_unwind section");
+ const macho_nlist<P>& sym = parser.symbolFromIndex(reloc->r_symbolnum());
+ return parser.nameFromSymbol(sym);
+ }
+ else {
+ const pint_t* content = (pint_t*)(this->file().fileContent() + this->_machOSection->offset() + reloc->r_address());
+ pint_t personalityAddr = *content;
+ Section<arm64>* personalitySection = parser.sectionForAddress(personalityAddr);
+ (void)personalitySection;
+ assert((personalitySection->type() == ld::Section::typeCode) && "personality column in __compact_unwind section is not pointer to function");
+ // atoms may not be constructed yet, so scan symbol table for labels
+ const char* name = parser.scanSymbolTableForAddress(personalityAddr);
+ return name;
+ }
+}
+#endif
+
+#if SUPPORT_ARCH_arm_any
+template <>
+const char* CUSection<arm>::personalityName(class Parser<arm>& parser, const macho_relocation_info<arm::P>* reloc)
+{
+ if ( reloc->r_extern() ) {
+ assert((reloc->r_type() == ARM_RELOC_VANILLA) && "wrong reloc type on personality column in __compact_unwind section");
+ const macho_nlist<P>& sym = parser.symbolFromIndex(reloc->r_symbolnum());
+ return parser.nameFromSymbol(sym);
+ }
+ else {
+ // support __LD, __compact_unwind personality entries which are pointer to personality non-lazy pointer
+ const pint_t* content = (pint_t*)(this->file().fileContent() + this->_machOSection->offset() + reloc->r_address());
+ pint_t nlPointerAddr = *content;
+ Section<arm>* nlSection = parser.sectionForAddress(nlPointerAddr);
+ if ( nlSection->type() == ld::Section::typeCode ) {
+ // personality function is defined in this .o file, so this is a direct reference to it
+ // atoms may not be constructed yet, so scan symbol table for labels
+ const char* name = parser.scanSymbolTableForAddress(nlPointerAddr);
+ return name;
+ }
+ else {
+ uint32_t symIndex = parser.symbolIndexFromIndirectSectionAddress(nlPointerAddr, nlSection->machoSection());
+ const macho_nlist<P>& nlSymbol = parser.symbolFromIndex(symIndex);
+ return parser.nameFromSymbol(nlSymbol);
+ }
+ }
}
+#endif
+
template <typename A>
const char* CUSection<A>::personalityName(class Parser<A>& parser, const macho_relocation_info<P>* reloc)
return NULL;
}
+template <>
+bool CUSection<x86>::encodingMeansUseDwarf(compact_unwind_encoding_t enc)
+{
+ return ((enc & UNWIND_X86_MODE_MASK) == UNWIND_X86_MODE_DWARF);
+}
+
+template <>
+bool CUSection<x86_64>::encodingMeansUseDwarf(compact_unwind_encoding_t enc)
+{
+ return ((enc & UNWIND_X86_64_MODE_MASK) == UNWIND_X86_64_MODE_DWARF);
+}
+
+#if SUPPORT_ARCH_arm_any
+template <>
+bool CUSection<arm>::encodingMeansUseDwarf(compact_unwind_encoding_t enc)
+{
+ return ((enc & UNWIND_ARM_MODE_MASK) == UNWIND_ARM_MODE_DWARF);
+}
+#endif
+
+#if SUPPORT_ARCH_arm64
+template <>
+bool CUSection<arm64>::encodingMeansUseDwarf(compact_unwind_encoding_t enc)
+{
+ return ((enc & UNWIND_ARM64_MODE_MASK) == UNWIND_ARM64_MODE_DWARF);
+}
+#endif
template <typename A>
int CUSection<A>::infoSorter(const void* l, const void* r)
}
}
- // scan relocs, local relocs are useless - ignore them
- // extern relocs are needed for personality references (possibly for function/lsda refs??)
+ // scan relocs, extern relocs are needed for personality references (possibly for function/lsda refs??)
const macho_relocation_info<P>* relocs = (macho_relocation_info<P>*)(this->file().fileContent() + this->_machOSection->reloff());
const macho_relocation_info<P>* relocsEnd = &relocs[this->_machOSection->nreloc()];
for (const macho_relocation_info<P>* reloc = relocs; reloc < relocsEnd; ++reloc) {
else if ( (reloc->r_address() % sizeof(macho_compact_unwind_entry<P>)) == macho_compact_unwind_entry<P>::codeStartFieldOffset() ) {
uint32_t entryIndex = reloc->r_address() / sizeof(macho_compact_unwind_entry<P>);
array[entryIndex].functionSymbolIndex = reloc->r_symbolnum();
+ array[entryIndex].functionStartAddress += parser.symbolFromIndex(reloc->r_symbolnum()).n_value();
}
else {
warning("unexpected extern relocation in __compact_unwind section");
}
}
+ else {
+ if ( (reloc->r_address() % sizeof(macho_compact_unwind_entry<P>)) == macho_compact_unwind_entry<P>::personalityFieldOffset() ) {
+ uint32_t entryIndex = reloc->r_address() / sizeof(macho_compact_unwind_entry<P>);
+ array[entryIndex].personality = this->personalityName(parser, reloc);
+ }
+ }
}
// sort array by function start address so unwind infos will be contiguous for a given function
Info* const arrayStart = cus.cuArray;
Info* const arrayEnd = &cus.cuArray[cus.cuCount];
for (Info* info=arrayStart; info < arrayEnd; ++info) {
- // if external reloc was used, real address is symbol n_value + addend
- if ( info->functionSymbolIndex != 0xFFFFFFFF )
- info->functionStartAddress += parser.symbolFromIndex(info->functionSymbolIndex).n_value();
// find function atom from address
info->function = parser.findAtomByAddress(info->functionStartAddress);
// find lsda atom from address
case S_REGULAR:
if ( strncmp(s->sectname(), "__gcc_except_tab", 16) == 0 )
_type = ld::Atom::typeLSDA;
+ else if ( this->type() == ld::Section::typeInitializerPointers )
+ _type = ld::Atom::typeInitializerPointers;
break;
}
}
pint_t addr;
pint_t size;
const macho_nlist<P>* sym;
- while ( it.next(parser, sectNum, startAddr, endAddr, &addr, &size, &sym) ) {
+ while ( it.next(parser, *this, sectNum, startAddr, endAddr, &addr, &size, &sym) ) {
++count;
}
//fprintf(stderr, "computeAtomCount(%s,%s) => %d\n", this->segmentName(), this->sectionName(), count);
template <typename A>
uint32_t SymboledSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p,
- struct Parser<A>::LabelAndCFIBreakIterator& it,
+ struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&)
{
this->_beginAtoms = (Atom<A>*)p;
pint_t addr;
pint_t size;
const macho_nlist<P>* label;
- while ( it.next(parser, sectNum, startAddr, endAddr, &addr, &size, &label) ) {
+ while ( it.next(parser, *this, sectNum, startAddr, endAddr, &addr, &size, &label) ) {
Atom<A>* allocatedSpace = (Atom<A>*)p;
// is break because of label or CFI?
if ( label != NULL ) {
new (allocatedSpace) Atom<A>(*this, parser, *label, size, isAlias);
if ( isAlias )
this->_hasAliases = true;
+ if ( parser.altEntryFromSymbol(*label) )
+ this->_altEntries.insert(allocatedSpace);
}
else {
ld::Atom::SymbolTableInclusion inclusion = ld::Atom::symbolTableNotIn;
ld::Atom::ContentType ctype = this->contentType();
if ( ctype == ld::Atom::typeLSDA )
inclusion = ld::Atom::symbolTableInWithRandomAutoStripLabel;
- new (allocatedSpace) Atom<A>(*this, "anon", addr, size, ld::Atom::definitionRegular, ld::Atom::combineNever,
+ new (allocatedSpace) Atom<A>(*this, "anon", addr, size, ld::Atom::definitionRegular, ld::Atom::combineNever,
ld::Atom::scopeTranslationUnit, ctype, inclusion,
this->dontDeadStrip(), false, false, this->alignmentForAddress(addr));
}
}
+template <>
+ld::Atom::SymbolTableInclusion ImplicitSizeSection<arm64>::symbolTableInclusion()
+{
+ return ld::Atom::symbolTableInWithRandomAutoStripLabel;
+}
+
+template <typename A>
+ld::Atom::SymbolTableInclusion ImplicitSizeSection<A>::symbolTableInclusion()
+{
+ return ld::Atom::symbolTableNotIn;
+}
+
+
template <typename A>
uint32_t ImplicitSizeSection<A>::computeAtomCount(class Parser<A>& parser,
struct Parser<A>::LabelAndCFIBreakIterator& it,
// if there are multiple labels in this section for the same address, then clone them into multi atoms
pint_t prevSymbolAddr = (pint_t)(-1);
uint8_t prevSymbolSectNum = 0;
+ bool prevIgnore = false;
for(uint32_t i=0; i < it.sortedSymbolCount; ++i) {
const macho_nlist<P>& sym = parser.symbolFromIndex(it.sortedSymbolIndexes[i]);
const pint_t symbolAddr = sym.n_value();
- const pint_t symbolSectNum = sym.n_sect();
- if ( (symbolAddr == prevSymbolAddr) && (prevSymbolSectNum == symbolSectNum) && (symbolSectNum == this->sectionNum(parser)) ) {
+ const uint8_t symbolSectNum = sym.n_sect();
+ const bool ignore = this->ignoreLabel(parser.nameFromSymbol(sym));
+ if ( !ignore && !prevIgnore && (symbolAddr == prevSymbolAddr) && (prevSymbolSectNum == symbolSectNum) && (symbolSectNum == this->sectionNum(parser)) ) {
++count;
}
prevSymbolAddr = symbolAddr;
prevSymbolSectNum = symbolSectNum;
+ prevIgnore = ignore;
}
}
return count;
pint_t size;
const macho_nlist<P>* foundLabel;
Atom<A>* allocatedSpace;
- while ( it.next(parser, sectNum, startAddr, endAddr, &foundAddr, &size, &foundLabel) ) {
+ while ( it.next(parser, *this, sectNum, startAddr, endAddr, &foundAddr, &size, &foundLabel) ) {
if ( foundLabel != NULL ) {
+ bool skip = false;
pint_t labeledAtomSize = this->elementSizeAtAddress(foundAddr);
allocatedSpace = (Atom<A>*)p;
if ( this->ignoreLabel(parser.nameFromSymbol(*foundLabel)) ) {
- //fprintf(stderr, " 0x%08llX make annon\n", (uint64_t)foundAddr);
- new (allocatedSpace) Atom<A>(*this, this->unlabeledAtomName(parser, foundAddr), foundAddr,
+ if ( size == 0 ) {
+ // <rdar://problem/10018737>
+ // a size of zero means there is another label at same location
+ // and we are supposed to ignore this label
+ skip = true;
+ }
+ else {
+ //fprintf(stderr, " 0x%08llX make annon, size=%lld\n", (uint64_t)foundAddr, (uint64_t)size);
+ new (allocatedSpace) Atom<A>(*this, this->unlabeledAtomName(parser, foundAddr), foundAddr,
this->elementSizeAtAddress(foundAddr), this->definition(),
this->combine(parser, foundAddr), this->scopeAtAddress(parser, foundAddr),
this->contentType(), this->symbolTableInclusion(),
this->dontDeadStrip(), false, false, this->alignmentForAddress(foundAddr));
+ }
}
else {
// make named atom for label
//fprintf(stderr, " 0x%08llX make labeled\n", (uint64_t)foundAddr);
new (allocatedSpace) Atom<A>(*this, parser, *foundLabel, labeledAtomSize);
}
- ++count;
- p += sizeof(Atom<A>);
- foundAddr += labeledAtomSize;
- size -= labeledAtomSize;
+ if ( !skip ) {
+ ++count;
+ p += sizeof(Atom<A>);
+ foundAddr += labeledAtomSize;
+ size -= labeledAtomSize;
+ }
}
// some number of anonymous atoms
for (pint_t addr = foundAddr; addr < (foundAddr+size); addr += elementSizeAtAddress(addr) ) {
// make anon atoms for area before label
if ( this->useElementAt(parser, it, addr) ) {
- //fprintf(stderr, " 0x%08llX make annon\n", (uint64_t)addr);
+ //fprintf(stderr, " 0x%08llX make annon, size=%lld\n", (uint64_t)addr, (uint64_t)elementSizeAtAddress(addr));
allocatedSpace = (Atom<A>*)p;
new (allocatedSpace) Atom<A>(*this, this->unlabeledAtomName(parser, addr), addr, this->elementSizeAtAddress(addr),
this->definition(), this->combine(parser, addr), this->scopeAtAddress(parser, addr),
return count;
}
+template <typename A>
+bool Literal4Section<A>::ignoreLabel(const char* label) const
+{
+ return (label[0] == 'L') || (label[0] == 'l');
+}
template <typename A>
unsigned long Literal4Section<A>::contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const
}
+template <typename A>
+bool Literal8Section<A>::ignoreLabel(const char* label) const
+{
+ return (label[0] == 'L') || (label[0] == 'l');
+}
+
template <typename A>
unsigned long Literal8Section<A>::contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const
{
return false;
}
+template <typename A>
+bool Literal16Section<A>::ignoreLabel(const char* label) const
+{
+ return (label[0] == 'L') || (label[0] == 'l');
+}
template <typename A>
unsigned long Literal16Section<A>::contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const
}
template <typename A>
-bool CStringSection<A>::ignoreLabel(const char* label)
+bool CStringSection<A>::ignoreLabel(const char* label) const
{
return (label[0] == 'L') || (label[0] == 'l');
}
+
template <typename A>
Atom<A>* CStringSection<A>::findAtomByAddress(pint_t addr)
{
}
template <>
-ld::Fixup::Kind NonLazyPointerSection<ppc>::fixupKind()
+ld::Fixup::Kind NonLazyPointerSection<arm64>::fixupKind()
{
- return ld::Fixup::kindStoreBigEndian32;
+ return ld::Fixup::kindStoreLittleEndian64;
}
-template <>
-ld::Fixup::Kind NonLazyPointerSection<ppc64>::fixupKind()
-{
- return ld::Fixup::kindStoreBigEndian64;
-}
template <>
void NonLazyPointerSection<x86_64>::makeFixups(class Parser<x86_64>& parser, const struct Parser<x86_64>::CFI_CU_InfoArrays&)
}
+
template <typename A>
-const uint8_t* CFStringSection<A>::targetContent(const class Atom<A>* atom, const ld::IndirectBindingTable& ind,
- ContentType* ct, unsigned int* count)
+ld::Atom::Combine TLVPointerSection<A>::combine(Parser<A>& parser, pint_t addr)
{
- *ct = contentUnknown;
- for (ld::Fixup::iterator fit=atom->fixupsBegin(), end=atom->fixupsEnd(); fit != end; ++fit) {
+ return ld::Atom::combineByNameAndReferences;
+}
+
+
+template <typename A>
+const char* TLVPointerSection<A>::targetName(const class Atom<A>* atom, const ld::IndirectBindingTable& ind, bool* isStatic)
+{
+ assert(atom->combine() == ld::Atom::combineByNameAndReferences);
+ assert(atom->fixupCount() == 1);
+ *isStatic = false;
+ ld::Fixup::iterator fit = atom->fixupsBegin();
+ const char* name = NULL;
+ switch ( fit->binding ) {
+ case ld::Fixup::bindingByNameUnbound:
+ name = fit->u.name;
+ break;
+ case ld::Fixup::bindingByContentBound:
+ name = fit->u.target->name();
+ break;
+ case ld::Fixup::bindingsIndirectlyBound:
+ name = ind.indirectName(fit->u.bindingIndex);
+ break;
+ case ld::Fixup::bindingDirectlyBound:
+ name = fit->u.target->name();
+ *isStatic = (fit->u.target->scope() == ld::Atom::scopeTranslationUnit);
+ break;
+ default:
+ assert(0);
+ }
+ assert(name != NULL);
+ return name;
+}
+
+template <typename A>
+unsigned long TLVPointerSection<A>::contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const
+{
+ assert(atom->combine() == ld::Atom::combineByNameAndReferences);
+ unsigned long hash = 9508;
+ bool isStatic;
+ for (const char* s = this->targetName(atom, ind, &isStatic); *s != '\0'; ++s) {
+ hash = hash * 33 + *s;
+ }
+ return hash;
+}
+
+template <typename A>
+bool TLVPointerSection<A>::canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
+ const ld::IndirectBindingTable& indirectBindingTable) const
+{
+ if ( rhs.section().type() != ld::Section::typeTLVPointers )
+ return false;
+ assert(this->type() == rhs.section().type());
+ const Atom<A>* rhsAtom = dynamic_cast<const Atom<A>*>(&rhs);
+ assert(rhsAtom != NULL);
+ bool thisIsStatic;
+ bool rhsIsStatic;
+ const char* thisName = this->targetName(atom, indirectBindingTable, &thisIsStatic);
+ const char* rhsName = this->targetName(rhsAtom, indirectBindingTable, &rhsIsStatic);
+ return !thisIsStatic && !rhsIsStatic && (strcmp(thisName, rhsName) == 0);
+}
+
+
+template <typename A>
+const uint8_t* CFStringSection<A>::targetContent(const class Atom<A>* atom, const ld::IndirectBindingTable& ind,
+ ContentType* ct, unsigned int* count)
+{
+ *ct = contentUnknown;
+ for (ld::Fixup::iterator fit=atom->fixupsBegin(), end=atom->fixupsEnd(); fit != end; ++fit) {
const ld::Atom* targetAtom = NULL;
switch ( fit->binding ) {
case ld::Fixup::bindingByNameUnbound:
*ct = contentUTF16;
*count = (targetAtom->size()+1)/2; // round up incase of buggy compiler that has only one trailing zero byte
}
- assert(target != NULL);
+ else {
+ *ct = contentUnknown;
+ *count = 0;
+ return NULL;
+ }
return target->contentPointer();
}
assert(0);
}
return hash;
case contentUnknown:
- return 0;
+ // <rdar://problem/14134211> For malformed CFStrings, hash to address of atom so they have unique hashes
+ return ULONG_MAX - (unsigned long)(atom);
}
return 0;
}
if ( thisType != rhsType )
return false;
+ if ( thisType == contentUnknown )
+ return false;
+
+ if ( rhsType == contentUnknown )
+ return false;
+
// no need to compare content of pointers are already the same
if ( cstringContent == rhsStringContent )
return true;
case ld::Fixup::bindingsIndirectlyBound:
targetAtom = ind.indirectAtom(fit->u.bindingIndex);
break;
+ case ld::Fixup::bindingDirectlyBound:
+ targetAtom = fit->u.target;
+ break;
default:
- assert(0);
+ assert(0 && "unsupported reference to selector");
}
assert(targetAtom != NULL);
const Atom<A>* target = dynamic_cast<const Atom<A>*>(targetAtom);
- assert(target != NULL);
+ assert(target != NULL);
+ assert(target->contentType() == ld::Atom::typeCString);
return (char*)target->contentPointer();
}
-//
-// ppc and ppc64 both use the same relocations, so process them in one common routine
-//
-template <typename A>
-bool Section<A>::addRelocFixup_powerpc(class Parser<A>& parser,
- const macho_relocation_info<typename A::P>* reloc)
+
+
+#if SUPPORT_ARCH_arm_any
+template <>
+bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocation_info<P>* reloc)
{
const macho_section<P>* sect = this->machoSection();
bool result = false;
uint32_t* fixUpPtr;
int32_t displacement = 0;
uint32_t instruction = 0;
- int16_t lowBits;
pint_t contentValue = 0;
- typename Parser<A>::SourceLocation src;
- typename Parser<A>::TargetDesc target;
+ Parser<arm>::SourceLocation src;
+ Parser<arm>::TargetDesc target;
+ const macho_relocation_info<P>* nextReloc;
if ( (reloc->r_address() & R_SCATTERED) == 0 ) {
+ bool externSymbolIsThumbDef = false;
srcAddr = sect->addr() + reloc->r_address();
src.atom = this->findAtomByAddress(srcAddr);
src.offsetInAtom = srcAddr - src.atom->_objAddress;
- const macho_relocation_info<P>* nextReloc = &reloc[1];
fixUpPtr = (uint32_t*)(file().fileContent() + sect->offset() + reloc->r_address());
- if ( reloc->r_type() != PPC_RELOC_PAIR )
- instruction = BigEndian::get32(*fixUpPtr);
+ if ( reloc->r_type() != ARM_RELOC_PAIR )
+ instruction = LittleEndian::get32(*fixUpPtr);
if ( reloc->r_extern() ) {
- target.atom = NULL;
const macho_nlist<P>& targetSymbol = parser.symbolFromIndex(reloc->r_symbolnum());
- target.name = parser.nameFromSymbol(targetSymbol);
- target.weakImport = parser.weakImportFromSymbol(targetSymbol);
+ // use direct reference for local symbols
+ if ( ((targetSymbol.n_type() & N_TYPE) == N_SECT) && (((targetSymbol.n_type() & N_EXT) == 0) || (parser.nameFromSymbol(targetSymbol)[0] == 'L')) ) {
+ parser.findTargetFromAddressAndSectionNum(targetSymbol.n_value(), targetSymbol.n_sect(), target);
+ }
+ else {
+ target.atom = NULL;
+ target.name = parser.nameFromSymbol(targetSymbol);
+ target.weakImport = parser.weakImportFromSymbol(targetSymbol);
+ if ( ((targetSymbol.n_type() & N_TYPE) == N_SECT) && (targetSymbol.n_desc() & N_ARM_THUMB_DEF) )
+ externSymbolIsThumbDef = true;
+ }
}
switch ( reloc->r_type() ) {
- case PPC_RELOC_BR24:
- assert((instruction & 0x4C000000) == 0x48000000);
- displacement = (instruction & 0x03FFFFFC);
+ case ARM_RELOC_BR24:
+ // Sign-extend displacement
+ displacement = (instruction & 0x00FFFFFF) << 2;
if ( (displacement & 0x02000000) != 0 )
displacement |= 0xFC000000;
+ // The pc added will be +8 from the pc
+ displacement += 8;
+ // If this is BLX add H << 1
+ if ((instruction & 0xFE000000) == 0xFA000000)
+ displacement += ((instruction & 0x01000000) >> 23);
if ( reloc->r_extern() ) {
- target.addend = srcAddr + displacement;
+ dstAddr = srcAddr + displacement;
+ // <rdar://problem/16652542> support large .o files
+ if ( srcAddr > 0x2000000 ) {
+ dstAddr -= ((srcAddr + 0x1FFFFFF) & 0xFC000000);
+ }
+ target.addend = dstAddr;
+ if ( externSymbolIsThumbDef )
+ target.addend &= -2; // remove thumb bit
}
else {
dstAddr = srcAddr + displacement;
// special case "calls" for dtrace
if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_probe$", 16) == 0) ) {
parser.addFixup(src, ld::Fixup::k1of1,
- ld::Fixup::kindStorePPCDtraceCallSiteNop, false, target.name);
+ ld::Fixup::kindStoreARMDtraceCallSiteNop, false, target.name);
parser.addDtraceExtraInfos(src, &target.name[16]);
}
else if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_isenabled$", 20) == 0) ) {
parser.addFixup(src, ld::Fixup::k1of1,
- ld::Fixup::kindStorePPCDtraceIsEnableSiteClear, false, target.name);
+ ld::Fixup::kindStoreARMDtraceIsEnableSiteClear, false, target.name);
parser.addDtraceExtraInfos(src, &target.name[20]);
}
else {
- parser.addFixups(src, ld::Fixup::kindStorePPCBranch24, target);
- }
- break;
- case PPC_RELOC_BR14:
- displacement = (instruction & 0x0000FFFC);
- if ( (displacement & 0x00008000) != 0 )
- displacement |= 0xFFFF0000;
- if ( reloc->r_extern() ) {
- target.addend = srcAddr + displacement;
- }
- else {
- dstAddr = srcAddr + displacement;
- parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
+ parser.addFixups(src, ld::Fixup::kindStoreARMBranch24, target);
}
- parser.addFixups(src, ld::Fixup::kindStorePPCBranch14, target);
break;
- case PPC_RELOC_PAIR:
- // skip, processed by a previous look ahead
- break;
- case PPC_RELOC_LO16:
- if ( nextReloc->r_type() != PPC_RELOC_PAIR )
- throw "PPC_RELOC_LO16 missing following pair";
- result = true;
- lowBits = (instruction & 0x0000FFFF);
- dstAddr = (nextReloc->r_address() << 16) + ((uint32_t)lowBits & 0x0000FFFF);
- if ( reloc->r_extern() ) {
- target.addend = dstAddr;
- }
- else {
- parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
+ case ARM_THUMB_RELOC_BR22:
+ // thumb2 added two more bits to displacement, complicating the displacement decoding
+ {
+ uint32_t s = (instruction >> 10) & 0x1;
+ uint32_t j1 = (instruction >> 29) & 0x1;
+ uint32_t j2 = (instruction >> 27) & 0x1;
+ uint32_t imm10 = instruction & 0x3FF;
+ uint32_t imm11 = (instruction >> 16) & 0x7FF;
+ uint32_t i1 = (j1 == s);
+ uint32_t i2 = (j2 == s);
+ uint32_t dis = (s << 24) | (i1 << 23) | (i2 << 22) | (imm10 << 12) | (imm11 << 1);
+ int32_t sdis = dis;
+ if ( s )
+ sdis |= 0xFE000000;
+ displacement = sdis;
}
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsLow16, target);
- break;
- case PPC_RELOC_LO14:
- if ( nextReloc->r_type() != PPC_RELOC_PAIR )
- throw "PPC_RELOC_LO14 missing following pair";
- result = true;
- lowBits = (instruction & 0xFFFC);
- dstAddr = (nextReloc->r_address() << 16) + ((uint32_t)lowBits & 0x0000FFFF);
+ // The pc added will be +4 from the pc
+ displacement += 4;
+ // If the instruction was blx, force the low 2 bits to be clear
+ dstAddr = srcAddr + displacement;
+ if ((instruction & 0xD0000000) == 0xC0000000)
+ dstAddr &= 0xFFFFFFFC;
+
if ( reloc->r_extern() ) {
- target.addend = dstAddr;
+ // <rdar://problem/16652542> support large .o files
+ if ( srcAddr > 0x1000000 ) {
+ dstAddr -= ((srcAddr + 0xFFFFFF) & 0xFE000000);
+ }
+ target.addend = (int64_t)(int32_t)dstAddr;
}
else {
parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
}
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsLow14, target);
- break;
- case PPC_RELOC_HI16:
- if ( nextReloc->r_type() != PPC_RELOC_PAIR )
- throw "PPC_RELOC_HI16 missing following pair";
- result = true;
- lowBits = (nextReloc->r_address() & 0xFFFF);
- dstAddr = ((instruction & 0xFFFF) << 16) | (lowBits & 0x0000FFFF);
- if ( reloc->r_extern() ) {
- target.addend = dstAddr;
- }
- else {
- parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
+ // special case "calls" for dtrace
+ if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_probe$", 16) == 0) ) {
+ parser.addFixup(src, ld::Fixup::k1of1,
+ ld::Fixup::kindStoreThumbDtraceCallSiteNop, false, target.name);
+ parser.addDtraceExtraInfos(src, &target.name[16]);
}
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsHigh16, target);
- break;
- case PPC_RELOC_HA16:
- if ( nextReloc->r_type() != PPC_RELOC_PAIR )
- throw "PPC_RELOC_HA16 missing following pair";
- result = true;
- lowBits = (nextReloc->r_address() & 0x0000FFFF);
- dstAddr = ((instruction & 0xFFFF) << 16) + (int32_t)lowBits;
- if ( reloc->r_extern() ) {
- target.addend = dstAddr;
+ else if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_isenabled$", 20) == 0) ) {
+ parser.addFixup(src, ld::Fixup::k1of1,
+ ld::Fixup::kindStoreThumbDtraceIsEnableSiteClear, false, target.name);
+ parser.addDtraceExtraInfos(src, &target.name[20]);
}
else {
- parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
+ parser.addFixups(src, ld::Fixup::kindStoreThumbBranch22, target);
}
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsHigh16AddLow, target);
break;
- case PPC_RELOC_VANILLA:
- contentValue = P::getP(*((pint_t*)fixUpPtr));
+ case ARM_RELOC_VANILLA:
+ if ( reloc->r_length() != 2 )
+ throw "bad length for ARM_RELOC_VANILLA";
+ contentValue = LittleEndian::get32(*fixUpPtr);
if ( reloc->r_extern() ) {
- target.addend = contentValue;
+ target.addend = (int32_t)contentValue;
+ if ( externSymbolIsThumbDef )
+ target.addend &= -2; // remove thumb bit
}
else {
parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), target);
+ // possible non-extern relocation turned into by-name ref because target is a weak-def
+ if ( target.atom != NULL ) {
+ if ( target.atom->isThumb() )
+ target.addend &= -2; // remove thumb bit
+ // if reference to LSDA, add group subordinate fixup
+ if ( target.atom->contentType() == ld::Atom::typeLSDA ) {
+ Parser<arm>::SourceLocation src2;
+ src2.atom = src.atom;
+ src2.offsetInAtom = 0;
+ parser.addFixup(src2, ld::Fixup::k1of1, ld::Fixup::kindNoneGroupSubordinateLSDA, target.atom);
+ }
+ }
}
- switch ( reloc->r_length() ) {
- case 0:
- case 1:
- throw "bad r_length in PPC_RELOC_VANILLA";
- case 2:
- parser.addFixups(src, ld::Fixup::kindStoreBigEndian32, target);
- break;
- case 3:
- parser.addFixups(src, ld::Fixup::kindStoreBigEndian64, target);
- break;
- }
+ parser.addFixups(src, ld::Fixup::kindStoreLittleEndian32, target);
break;
- case PPC_RELOC_JBSR:
- // this is from -mlong-branch codegen. We ignore the jump island and make reference to the real target
- if ( nextReloc->r_type() != PPC_RELOC_PAIR )
- throw "PPC_RELOC_JBSR missing following pair";
- if ( !parser._hasLongBranchStubs )
- warning("object file compiled with -mlong-branch which is no longer needed. "
- "To remove this warning, recompile without -mlong-branch: %s", parser._path);
- parser._hasLongBranchStubs = true;
- result = true;
- if ( reloc->r_extern() ) {
- throw "PPC_RELOC_JBSR should not be using an external relocation";
+ case ARM_THUMB_32BIT_BRANCH:
+ // silently ignore old unnecessary reloc
+ break;
+ case ARM_RELOC_HALF:
+ nextReloc = &reloc[1];
+ if ( nextReloc->r_type() == ARM_RELOC_PAIR ) {
+ uint32_t instruction16;
+ uint32_t other16 = (nextReloc->r_address() & 0xFFFF);
+ bool isThumb;
+ if ( reloc->r_length() & 2 ) {
+ isThumb = true;
+ uint32_t i = ((instruction & 0x00000400) >> 10);
+ uint32_t imm4 = (instruction & 0x0000000F);
+ uint32_t imm3 = ((instruction & 0x70000000) >> 28);
+ uint32_t imm8 = ((instruction & 0x00FF0000) >> 16);
+ instruction16 = (imm4 << 12) | (i << 11) | (imm3 << 8) | imm8;
+ }
+ else {
+ isThumb = false;
+ uint32_t imm4 = ((instruction & 0x000F0000) >> 16);
+ uint32_t imm12 = (instruction & 0x00000FFF);
+ instruction16 = (imm4 << 12) | imm12;
+ }
+ if ( reloc->r_length() & 1 ) {
+ // high 16
+ dstAddr = ((instruction16 << 16) | other16);
+ if ( reloc->r_extern() ) {
+ target.addend = dstAddr;
+ if ( externSymbolIsThumbDef )
+ target.addend &= -2; // remove thumb bit
+ }
+ else {
+ parser.findTargetFromAddress(dstAddr, target);
+ if ( target.atom->isThumb() )
+ target.addend &= (-2); // remove thumb bit
+ }
+ parser.addFixups(src, (isThumb ? ld::Fixup::kindStoreThumbHigh16 : ld::Fixup::kindStoreARMHigh16), target);
+ }
+ else {
+ // low 16
+ dstAddr = (other16 << 16) | instruction16;
+ if ( reloc->r_extern() ) {
+ target.addend = dstAddr;
+ if ( externSymbolIsThumbDef )
+ target.addend &= -2; // remove thumb bit
+ }
+ else {
+ parser.findTargetFromAddress(dstAddr, target);
+ if ( target.atom->isThumb() )
+ target.addend &= (-2); // remove thumb bit
+ }
+ parser.addFixups(src, (isThumb ? ld::Fixup::kindStoreThumbLow16 : ld::Fixup::kindStoreARMLow16), target);
+ }
+ result = true;
}
- parser.findTargetFromAddressAndSectionNum(nextReloc->r_address(), reloc->r_symbolnum(), target);
- parser.addFixups(src, ld::Fixup::kindStorePPCBranch24, target);
+ else
+ throw "for ARM_RELOC_HALF, next reloc is not ARM_RELOC_PAIR";
break;
default:
- warning("unknown relocation type %d", reloc->r_type());
+ throwf("unknown relocation type %d", reloc->r_type());
+ break;
}
}
else {
const macho_scattered_relocation_info<P>* sreloc = (macho_scattered_relocation_info<P>*)reloc;
// file format allows pair to be scattered or not
const macho_scattered_relocation_info<P>* nextSReloc = &sreloc[1];
- const macho_relocation_info<P>* nextReloc = &reloc[1];
+ nextReloc = &reloc[1];
srcAddr = sect->addr() + sreloc->r_address();
dstAddr = sreloc->r_value();
fixUpPtr = (uint32_t*)(file().fileContent() + sect->offset() + sreloc->r_address());
- instruction = BigEndian::get32(*fixUpPtr);
+ instruction = LittleEndian::get32(*fixUpPtr);
src.atom = this->findAtomByAddress(srcAddr);
src.offsetInAtom = srcAddr - src.atom->_objAddress;
- typename Parser<A>::TargetDesc picBase;
bool nextRelocIsPair = false;
uint32_t nextRelocAddress = 0;
uint32_t nextRelocValue = 0;
if ( (nextReloc->r_address() & R_SCATTERED) == 0 ) {
- if ( nextReloc->r_type() == PPC_RELOC_PAIR ) {
+ if ( nextReloc->r_type() == ARM_RELOC_PAIR ) {
nextRelocIsPair = true;
nextRelocAddress = nextReloc->r_address();
result = true;
}
}
else {
- if ( nextSReloc->r_type() == PPC_RELOC_PAIR ) {
+ if ( nextSReloc->r_type() == ARM_RELOC_PAIR ) {
nextRelocIsPair = true;
nextRelocAddress = nextSReloc->r_address();
nextRelocValue = nextSReloc->r_value();
}
}
switch ( sreloc->r_type() ) {
- case PPC_RELOC_VANILLA:
- // with a scattered relocation we get both the target (sreloc->r_value()) and the target+offset (*fixUpPtr)
- target.atom = parser.findAtomByAddress(sreloc->r_value());
- switch ( sreloc->r_length() ) {
- case 0:
- case 1:
- throw "unsuppored r_length < 2 for scattered PPC_RELOC_VANILLA";
- case 2:
- contentValue = BigEndian::get32(*(uint32_t*)fixUpPtr);
- target.addend = contentValue - target.atom->_objAddress;
- parser.addFixups(src, ld::Fixup::kindStoreBigEndian32, target);
- break;
- case 3:
- contentValue = BigEndian::get64(*(uint64_t*)fixUpPtr);
- target.addend = contentValue - target.atom->_objAddress;
- parser.addFixups(src, ld::Fixup::kindStoreBigEndian64, target);
- break;
- }
- break;
- case PPC_RELOC_BR14:
- displacement = (instruction & 0x0000FFFC);
- if ( (displacement & 0x00008000) != 0 )
- displacement |= 0xFFFF0000;
- target.atom = parser.findAtomByAddress(sreloc->r_value());
- target.addend = (srcAddr + displacement) - target.atom->_objAddress;
- parser.addFixups(src, ld::Fixup::kindStorePPCBranch14, target);
- break;
- case PPC_RELOC_BR24:
- assert((instruction & 0x4C000000) == 0x48000000);
- displacement = (instruction & 0x03FFFFFC);
- if ( (displacement & 0x02000000) != 0 )
- displacement |= 0xFC000000;
- target.atom = parser.findAtomByAddress(sreloc->r_value());
- target.addend = (srcAddr + displacement) - target.atom->_objAddress;
- parser.addFixups(src, ld::Fixup::kindStorePPCBranch24, target);
- break;
- case PPC_RELOC_LO16_SECTDIFF:
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_LO16_SECTDIFF missing following pair";
- lowBits = (instruction & 0xFFFF);
- dstAddr = nextRelocValue + ((nextRelocAddress << 16) | ((uint32_t)lowBits & 0x0000FFFF));
- parser.findTargetFromAddress(sreloc->r_value(), target);
- if ( target.atom != NULL )
- target.addend = dstAddr - target.atom->_objAddress;
- picBase.atom = parser.findAtomByAddress(nextRelocValue);
- picBase.addend = nextRelocValue - picBase.atom->_objAddress;
- picBase.weakImport = false;
- picBase.name = NULL;
- parser.addFixups(src, ld::Fixup::kindStorePPCPicLow16, target, picBase);
- break;
- case PPC_RELOC_LO14_SECTDIFF:
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_LO14_SECTDIFF missing following pair";
- lowBits = (instruction & 0xFFFC);
- dstAddr = nextRelocValue + ((nextRelocAddress << 16) | ((uint32_t)lowBits & 0x0000FFFF));
- parser.findTargetFromAddress(sreloc->r_value(), target);
- if ( target.atom != NULL )
- target.addend = dstAddr - target.atom->_objAddress;
- picBase.atom = parser.findAtomByAddress(nextRelocValue);
- picBase.addend = nextRelocValue - picBase.atom->_objAddress;
- picBase.weakImport = false;
- picBase.name = NULL;
- parser.addFixups(src, ld::Fixup::kindStorePPCPicLow14, target, picBase);
- break;
- case PPC_RELOC_HA16_SECTDIFF:
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_HA16_SECTDIFF missing following pair";
- lowBits = (nextRelocAddress & 0x0000FFFF);
- dstAddr = nextRelocValue + (((instruction & 0x0000FFFF) << 16) + (int32_t)lowBits);
- parser.findTargetFromAddress(sreloc->r_value(), target);
- if ( target.atom != NULL )
- target.addend = dstAddr - target.atom->_objAddress;
- picBase.atom = parser.findAtomByAddress(nextRelocValue);
- picBase.addend = nextRelocValue - picBase.atom->_objAddress;
- picBase.weakImport = false;
- picBase.name = NULL;
- parser.addFixups(src, ld::Fixup::kindStorePPCPicHigh16AddLow, target, picBase);
- break;
- case PPC_RELOC_LO14:
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_LO14 missing following pair";
- lowBits = (instruction & 0xFFFC);
- dstAddr = ((nextRelocAddress << 16) + ((uint32_t)lowBits & 0x0000FFFF));
- parser.findTargetFromAddress(sreloc->r_value(), dstAddr, target);
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsLow14, target);
- break;
- case PPC_RELOC_LO16:
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_LO16 missing following pair";
- lowBits = (instruction & 0xFFFF);
- dstAddr = ((nextRelocAddress << 16) + ((uint32_t)lowBits & 0x0000FFFF));
- parser.findTargetFromAddress(sreloc->r_value(), dstAddr, target);
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsLow16, target);
- break;
- case PPC_RELOC_HA16:
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_HA16 missing following pair";
- lowBits = (nextRelocAddress & 0xFFFF);
- dstAddr = (((instruction & 0xFFFF) << 16) + (int32_t)lowBits);
- parser.findTargetFromAddress(sreloc->r_value(), dstAddr, target);
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsHigh16AddLow, target);
- break;
- case PPC_RELOC_HI16:
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_HI16 missing following pair";
- lowBits = (nextRelocAddress & 0xFFFF);
- dstAddr = ((instruction & 0xFFFF) << 16) | (lowBits & 0x0000FFFF);
- parser.findTargetFromAddress(sreloc->r_value(), dstAddr, target);
- parser.addFixups(src, ld::Fixup::kindStorePPCAbsHigh16, target);
- break;
- case PPC_RELOC_SECTDIFF:
- case PPC_RELOC_LOCAL_SECTDIFF:
- {
- if ( ! nextRelocIsPair )
- throw "PPC_RELOC_SECTDIFF missing following pair";
- ld::Fixup::Kind kind = ld::Fixup::kindNone;
- switch ( sreloc->r_length() ) {
- case 0:
- throw "bad length for PPC_RELOC_SECTDIFF";
- case 1:
- contentValue = (int32_t)(int16_t)BigEndian::get16(*((uint16_t*)fixUpPtr));
- kind = ld::Fixup::kindStoreBigEndian16;
- break;
- case 2:
- contentValue = BigEndian::get32(*((uint32_t*)fixUpPtr));
- kind = ld::Fixup::kindStoreBigEndian32;
- break;
- case 3:
- contentValue = BigEndian::get64(*((uint64_t*)fixUpPtr));
- kind = ld::Fixup::kindStoreBigEndian64;
- break;
- break;
- }
- Atom<A>* fromAtom = parser.findAtomByAddress(nextRelocValue);
- Atom<A>* targetAtom = parser.findAtomByAddress(sreloc->r_value());
- uint32_t offsetInFrom = nextRelocValue - fromAtom->_objAddress;
- uint32_t offsetInTarget = sreloc->r_value() - targetAtom->_objAddress;
- // check for addend encoded in the section content
- int32_t addend = contentValue - (sreloc->r_value() - nextRelocValue);
- if ( addend < 0 ) {
- if ( targetAtom->scope() == ld::Atom::scopeTranslationUnit ) {
- parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, targetAtom);
- }
- else if ( (targetAtom->combine() == ld::Atom::combineByNameAndContent) || (targetAtom->combine() == ld::Atom::combineByNameAndReferences) ) {
- parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, ld::Fixup::bindingByContentBound, targetAtom);
- }
- else {
- parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, false, targetAtom->name());
- }
- parser.addFixup(src, ld::Fixup::k2of5, ld::Fixup::kindAddAddend, offsetInTarget);
- parser.addFixup(src, ld::Fixup::k3of5, ld::Fixup::kindSubtractTargetAddress, fromAtom);
- parser.addFixup(src, ld::Fixup::k4of5, ld::Fixup::kindSubtractAddend, offsetInFrom-addend);
- parser.addFixup(src, ld::Fixup::k5of5, kind);
- }
- else {
- if ( targetAtom->scope() == ld::Atom::scopeTranslationUnit ) {
- parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, targetAtom);
- }
- else if ( (targetAtom->combine() == ld::Atom::combineByNameAndContent) || (targetAtom->combine() == ld::Atom::combineByNameAndReferences) ) {
- parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, ld::Fixup::bindingByContentBound, targetAtom);
- }
- else {
- parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, false, targetAtom->name());
- }
- parser.addFixup(src, ld::Fixup::k2of5, ld::Fixup::kindAddAddend, offsetInTarget+addend);
- parser.addFixup(src, ld::Fixup::k3of5, ld::Fixup::kindSubtractTargetAddress, fromAtom);
- parser.addFixup(src, ld::Fixup::k4of5, ld::Fixup::kindSubtractAddend, offsetInFrom);
- parser.addFixup(src, ld::Fixup::k5of5, kind);
- }
- }
- break;
- case PPC_RELOC_PAIR:
- break;
- case PPC_RELOC_HI16_SECTDIFF:
- warning("unexpected scattered relocation type PPC_RELOC_HI16_SECTDIFF");
- break;
- default:
- warning("unknown scattered relocation type %d", sreloc->r_type());
- }
- }
- return result;
-}
-
-
-template <>
-bool Section<ppc>::addRelocFixup(class Parser<ppc>& parser, const macho_relocation_info<P>* reloc)
-{
- return addRelocFixup_powerpc(parser, reloc);
-}
-
-
-template <>
-bool Section<ppc64>::addRelocFixup(class Parser<ppc64>& parser, const macho_relocation_info<P>* reloc)
-{
- return addRelocFixup_powerpc(parser, reloc);
-}
-
-
-
-template <>
-bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocation_info<P>* reloc)
-{
- const macho_section<P>* sect = this->machoSection();
- bool result = false;
- uint32_t srcAddr;
- uint32_t dstAddr;
- uint32_t* fixUpPtr;
- int32_t displacement = 0;
- uint32_t instruction = 0;
- pint_t contentValue = 0;
- Parser<arm>::SourceLocation src;
- Parser<arm>::TargetDesc target;
- const macho_relocation_info<P>* nextReloc;
-
- if ( (reloc->r_address() & R_SCATTERED) == 0 ) {
- bool externSymbolIsThumbDef = false;
- srcAddr = sect->addr() + reloc->r_address();
- src.atom = this->findAtomByAddress(srcAddr);
- src.offsetInAtom = srcAddr - src.atom->_objAddress;
- fixUpPtr = (uint32_t*)(file().fileContent() + sect->offset() + reloc->r_address());
- if ( reloc->r_type() != ARM_RELOC_PAIR )
- instruction = LittleEndian::get32(*fixUpPtr);
- if ( reloc->r_extern() ) {
- const macho_nlist<P>& targetSymbol = parser.symbolFromIndex(reloc->r_symbolnum());
- // use direct reference for local symbols
- if ( ((targetSymbol.n_type() & N_TYPE) == N_SECT) && (((targetSymbol.n_type() & N_EXT) == 0) || (parser.nameFromSymbol(targetSymbol)[0] == 'L')) ) {
- parser.findTargetFromAddressAndSectionNum(targetSymbol.n_value(), targetSymbol.n_sect(), target);
- }
- else {
- target.atom = NULL;
- target.name = parser.nameFromSymbol(targetSymbol);
- target.weakImport = parser.weakImportFromSymbol(targetSymbol);
- if ( ((targetSymbol.n_type() & N_TYPE) == N_SECT) && (targetSymbol.n_desc() & N_ARM_THUMB_DEF) )
- externSymbolIsThumbDef = true;
- }
- }
- switch ( reloc->r_type() ) {
- case ARM_RELOC_BR24:
- // Sign-extend displacement
- displacement = (instruction & 0x00FFFFFF) << 2;
- if ( (displacement & 0x02000000) != 0 )
- displacement |= 0xFC000000;
- // The pc added will be +8 from the pc
- displacement += 8;
- // If this is BLX add H << 1
- if ((instruction & 0xFE000000) == 0xFA000000)
- displacement += ((instruction & 0x01000000) >> 23);
- if ( reloc->r_extern() ) {
- target.addend = srcAddr + displacement;
- if ( externSymbolIsThumbDef )
- target.addend &= -2; // remove thumb bit
- }
- else {
- dstAddr = srcAddr + displacement;
- parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
- }
- // special case "calls" for dtrace
- if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_probe$", 16) == 0) ) {
- parser.addFixup(src, ld::Fixup::k1of1,
- ld::Fixup::kindStoreARMDtraceCallSiteNop, false, target.name);
- parser.addDtraceExtraInfos(src, &target.name[16]);
- }
- else if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_isenabled$", 20) == 0) ) {
- parser.addFixup(src, ld::Fixup::k1of1,
- ld::Fixup::kindStoreARMDtraceIsEnableSiteClear, false, target.name);
- parser.addDtraceExtraInfos(src, &target.name[20]);
- }
- else {
- parser.addFixups(src, ld::Fixup::kindStoreARMBranch24, target);
- }
- break;
- case ARM_THUMB_RELOC_BR22:
- // thumb2 added two more bits to displacement, complicating the displacement decoding
- {
- uint32_t s = (instruction >> 10) & 0x1;
- uint32_t j1 = (instruction >> 29) & 0x1;
- uint32_t j2 = (instruction >> 27) & 0x1;
- uint32_t imm10 = instruction & 0x3FF;
- uint32_t imm11 = (instruction >> 16) & 0x7FF;
- uint32_t i1 = (j1 == s);
- uint32_t i2 = (j2 == s);
- uint32_t dis = (s << 24) | (i1 << 23) | (i2 << 22) | (imm10 << 12) | (imm11 << 1);
- int32_t sdis = dis;
- if ( s )
- sdis |= 0xFE000000;
- displacement = sdis;
- }
- // The pc added will be +4 from the pc
- displacement += 4;
- // If the instruction was blx, force the low 2 bits to be clear
- dstAddr = srcAddr + displacement;
- if ((instruction & 0xF8000000) == 0xE8000000)
- dstAddr &= 0xFFFFFFFC;
-
- if ( reloc->r_extern() ) {
- target.addend = dstAddr;
- }
- else {
- parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
- }
- // special case "calls" for dtrace
- if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_probe$", 16) == 0) ) {
- parser.addFixup(src, ld::Fixup::k1of1,
- ld::Fixup::kindStoreThumbDtraceCallSiteNop, false, target.name);
- parser.addDtraceExtraInfos(src, &target.name[16]);
- }
- else if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_isenabled$", 20) == 0) ) {
- parser.addFixup(src, ld::Fixup::k1of1,
- ld::Fixup::kindStoreThumbDtraceIsEnableSiteClear, false, target.name);
- parser.addDtraceExtraInfos(src, &target.name[20]);
- }
- else {
- parser.addFixups(src, ld::Fixup::kindStoreThumbBranch22, target);
- }
- break;
- case ARM_RELOC_VANILLA:
- if ( reloc->r_length() != 2 )
- throw "bad length for ARM_RELOC_VANILLA";
- contentValue = LittleEndian::get32(*fixUpPtr);
- if ( reloc->r_extern() ) {
- target.addend = (int32_t)contentValue;
- if ( externSymbolIsThumbDef )
- target.addend &= -2; // remove thumb bit
- }
- else {
- parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), target);
- // possible non-extern relocation turned into by-name ref because target is a weak-def
- if ( target.atom != NULL ) {
- if ( target.atom->isThumb() )
- target.addend &= -2; // remove thumb bit
- // if reference to LSDA, add group subordinate fixup
- if ( target.atom->contentType() == ld::Atom::typeLSDA ) {
- Parser<arm>::SourceLocation src2;
- src2.atom = src.atom;
- src2.offsetInAtom = 0;
- parser.addFixup(src2, ld::Fixup::k1of1, ld::Fixup::kindNoneGroupSubordinateLSDA, target.atom);
- }
- }
- }
- parser.addFixups(src, ld::Fixup::kindStoreLittleEndian32, target);
- break;
- case ARM_THUMB_32BIT_BRANCH:
- // silently ignore old unnecessary reloc
- break;
- case ARM_RELOC_HALF:
- nextReloc = &reloc[1];
- if ( nextReloc->r_type() == ARM_RELOC_PAIR ) {
- uint32_t instruction16;
- uint32_t other16 = (nextReloc->r_address() & 0xFFFF);
- bool isThumb;
- if ( reloc->r_length() & 2 ) {
- isThumb = true;
- uint32_t i = ((instruction & 0x00000400) >> 10);
- uint32_t imm4 = (instruction & 0x0000000F);
- uint32_t imm3 = ((instruction & 0x70000000) >> 28);
- uint32_t imm8 = ((instruction & 0x00FF0000) >> 16);
- instruction16 = (imm4 << 12) | (i << 11) | (imm3 << 8) | imm8;
- }
- else {
- isThumb = false;
- uint32_t imm4 = ((instruction & 0x000F0000) >> 16);
- uint32_t imm12 = (instruction & 0x00000FFF);
- instruction16 = (imm4 << 12) | imm12;
- }
- if ( reloc->r_length() & 1 ) {
- // high 16
- dstAddr = ((instruction16 << 16) | other16);
- if ( reloc->r_extern() ) {
- target.addend = dstAddr;
- }
- else {
- parser.findTargetFromAddress(dstAddr, target);
- if ( target.atom->isThumb() )
- target.addend &= (-2); // remove thumb bit
- }
- parser.addFixups(src, (isThumb ? ld::Fixup::kindStoreThumbHigh16 : ld::Fixup::kindStoreARMHigh16), target);
- }
- else {
- // low 16
- dstAddr = (other16 << 16) | instruction16;
- if ( reloc->r_extern() ) {
- target.addend = dstAddr;
- }
- else {
- parser.findTargetFromAddress(dstAddr, target);
- if ( target.atom->isThumb() )
- target.addend &= (-2); // remove thumb bit
- }
- parser.addFixups(src, (isThumb ? ld::Fixup::kindStoreThumbLow16 : ld::Fixup::kindStoreARMLow16), target);
- }
- result = true;
- }
- else
- throw "for ARM_RELOC_HALF, next reloc is not ARM_RELOC_PAIR";
- break;
- default:
- throwf("unknown relocation type %d", reloc->r_type());
- break;
- }
- }
- else {
- const macho_scattered_relocation_info<P>* sreloc = (macho_scattered_relocation_info<P>*)reloc;
- // file format allows pair to be scattered or not
- const macho_scattered_relocation_info<P>* nextSReloc = &sreloc[1];
- nextReloc = &reloc[1];
- srcAddr = sect->addr() + sreloc->r_address();
- dstAddr = sreloc->r_value();
- fixUpPtr = (uint32_t*)(file().fileContent() + sect->offset() + sreloc->r_address());
- instruction = LittleEndian::get32(*fixUpPtr);
- src.atom = this->findAtomByAddress(srcAddr);
- src.offsetInAtom = srcAddr - src.atom->_objAddress;
- bool nextRelocIsPair = false;
- uint32_t nextRelocAddress = 0;
- uint32_t nextRelocValue = 0;
- if ( (nextReloc->r_address() & R_SCATTERED) == 0 ) {
- if ( nextReloc->r_type() == ARM_RELOC_PAIR ) {
- nextRelocIsPair = true;
- nextRelocAddress = nextReloc->r_address();
- result = true;
- }
- }
- else {
- if ( nextSReloc->r_type() == ARM_RELOC_PAIR ) {
- nextRelocIsPair = true;
- nextRelocAddress = nextSReloc->r_address();
- nextRelocValue = nextSReloc->r_value();
- result = true;
- }
- }
- switch ( sreloc->r_type() ) {
- case ARM_RELOC_VANILLA:
+ case ARM_RELOC_VANILLA:
// with a scattered relocation we get both the target (sreloc->r_value()) and the target+offset (*fixUpPtr)
if ( sreloc->r_length() != 2 )
throw "bad length for ARM_RELOC_VANILLA";
target.atom = parser.findAtomByAddress(sreloc->r_value());
+ if ( target.atom == NULL )
+ throwf("bad r_value (0x%08X) for ARM_RELOC_VANILLA\n", sreloc->r_value());
contentValue = LittleEndian::get32(*fixUpPtr);
target.addend = contentValue - target.atom->_objAddress;
if ( target.atom->isThumb() )
parser.addFixup(src, ld::Fixup::k3of3, (isThumb ? ld::Fixup::kindStoreThumbHigh16 : ld::Fixup::kindStoreARMHigh16));
}
else {
- // low 16
- parser.addFixup(src, ld::Fixup::k3of3, (isThumb ? ld::Fixup::kindStoreThumbLow16 : ld::Fixup::kindStoreARMLow16));
+ // low 16
+ parser.addFixup(src, ld::Fixup::k3of3, (isThumb ? ld::Fixup::kindStoreThumbLow16 : ld::Fixup::kindStoreARMLow16));
+ }
+ result = true;
+ }
+ else
+ throw "scattered ARM_RELOC_HALF reloc missing following pair";
+ break;
+ default:
+ throwf("unknown ARM scattered relocation type %d", sreloc->r_type());
+ }
+ }
+ return result;
+}
+#endif
+
+
+#if SUPPORT_ARCH_arm64
+template <>
+bool Section<arm64>::addRelocFixup(class Parser<arm64>& parser, const macho_relocation_info<P>* reloc)
+{
+ bool result = false;
+ Parser<arm64>::SourceLocation src;
+ Parser<arm64>::TargetDesc target = { NULL, NULL, false, 0 };
+ Parser<arm64>::TargetDesc toTarget;
+ int32_t prefixRelocAddend = 0;
+ if ( reloc->r_type() == ARM64_RELOC_ADDEND ) {
+ uint32_t rawAddend = reloc->r_symbolnum();
+ prefixRelocAddend = rawAddend;
+ if ( rawAddend & 0x00800000 )
+ prefixRelocAddend |= 0xFF000000; // sign extend 24-bit signed int to 32-bits
+ uint32_t addendAddress = reloc->r_address();
+ ++reloc; //advance to next reloc record
+ result = true;
+ if ( reloc->r_address() != addendAddress )
+ throw "ARM64_RELOC_ADDEND r_address does not match next reloc's r_address";
+ }
+ const macho_section<P>* sect = this->machoSection();
+ uint64_t srcAddr = sect->addr() + reloc->r_address();
+ src.atom = this->findAtomByAddress(srcAddr);
+ src.offsetInAtom = srcAddr - src.atom->_objAddress;
+ const uint8_t* fixUpPtr = file().fileContent() + sect->offset() + reloc->r_address();
+ uint64_t contentValue = 0;
+ const macho_relocation_info<arm64::P>* nextReloc = &reloc[1];
+ bool useDirectBinding;
+ uint32_t instruction;
+ uint32_t encodedAddend;
+ switch ( reloc->r_length() ) {
+ case 0:
+ contentValue = *fixUpPtr;
+ break;
+ case 1:
+ contentValue = (int64_t)(int16_t)E::get16(*((uint16_t*)fixUpPtr));
+ break;
+ case 2:
+ contentValue = (int64_t)(int32_t)E::get32(*((uint32_t*)fixUpPtr));
+ break;
+ case 3:
+ contentValue = E::get64(*((uint64_t*)fixUpPtr));
+ break;
+ }
+ if ( reloc->r_extern() ) {
+ const macho_nlist<P>& sym = parser.symbolFromIndex(reloc->r_symbolnum());
+ const char* symbolName = parser.nameFromSymbol(sym);
+ if ( ((sym.n_type() & N_TYPE) == N_SECT) && (((sym.n_type() & N_EXT) == 0) || (symbolName[0] == 'L') || (symbolName[0] == 'l')) ) {
+ // use direct reference for local symbols
+ parser.findTargetFromAddressAndSectionNum(sym.n_value(), sym.n_sect(), target);
+ //target.addend += contentValue;
+ }
+ else if ( ((sym.n_type() & N_TYPE) == N_SECT) && (src.atom->_objAddress <= sym.n_value()) && (sym.n_value() < (src.atom->_objAddress+src.atom->size())) ) {
+ // <rdar://problem/13700961> spurious warning when weak function has reference to itself
+ // use direct reference when atom targets itself
+ target.atom = src.atom;
+ target.name = NULL;
+ }
+ else {
+ target.name = symbolName;
+ target.weakImport = parser.weakImportFromSymbol(sym);
+ //target.addend = contentValue;
+ }
+ // cfstrings should always use direct reference to backing store
+ if ( (this->type() == ld::Section::typeCFString) && (src.offsetInAtom != 0) ) {
+ parser.findTargetFromAddressAndSectionNum(sym.n_value(), sym.n_sect(), target);
+ //target.addend = contentValue;
+ }
+ }
+ else {
+ if ( reloc->r_pcrel() )
+ contentValue += srcAddr;
+ parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), target);
+ }
+ switch ( reloc->r_type() ) {
+ case ARM64_RELOC_UNSIGNED:
+ if ( reloc->r_pcrel() )
+ throw "pcrel and ARM64_RELOC_UNSIGNED not supported";
+ if ( reloc->r_extern() )
+ target.addend = contentValue;
+ switch ( reloc->r_length() ) {
+ case 0:
+ case 1:
+ throw "length < 2 and ARM64_RELOC_UNSIGNED not supported";
+ case 2:
+ parser.addFixups(src, ld::Fixup::kindStoreLittleEndian32, target);
+ break;
+ case 3:
+ parser.addFixups(src, ld::Fixup::kindStoreLittleEndian64, target);
+ break;
+ }
+ break;
+ case ARM64_RELOC_BRANCH26:
+ if ( ! reloc->r_pcrel() )
+ throw "not pcrel and ARM64_RELOC_BRANCH26 not supported";
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_BRANCH26 not supported";
+ if ( reloc->r_length() != 2 )
+ throw "r_length != 2 and ARM64_RELOC_BRANCH26 not supported";
+ if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_probe$", 16) == 0) ) {
+ parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindStoreARM64DtraceCallSiteNop, false, target.name);
+ parser.addDtraceExtraInfos(src, &target.name[16]);
+ }
+ else if ( (target.name != NULL) && (strncmp(target.name, "___dtrace_isenabled$", 20) == 0) ) {
+ parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindStoreARM64DtraceIsEnableSiteClear, false, target.name);
+ parser.addDtraceExtraInfos(src, &target.name[20]);
+ }
+ else {
+ target.addend = prefixRelocAddend;
+ instruction = contentValue;
+ encodedAddend = (instruction & 0x03FFFFFF) << 2;
+ if ( encodedAddend != 0 ) {
+ if ( prefixRelocAddend == 0 ) {
+ warning("branch26 instruction at 0x%08X has embedded addend. ARM64_RELOC_ADDEND should be used instead", reloc->r_address());
+ target.addend = encodedAddend;
+ }
+ else {
+ throwf("branch26 instruction at 0x%08X has embedded addend and ARM64_RELOC_ADDEND also used", reloc->r_address());
}
- result = true;
}
- else
- throw "scattered ARM_RELOC_HALF reloc missing following pair";
- break;
- default:
- throwf("unknown ARM scattered relocation type %d", sreloc->r_type());
- }
+ parser.addFixups(src, ld::Fixup::kindStoreARM64Branch26, target);
+ }
+ break;
+ case ARM64_RELOC_PAGE21:
+ if ( ! reloc->r_pcrel() )
+ throw "not pcrel and ARM64_RELOC_PAGE21 not supported";
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_PAGE21 not supported";
+ if ( reloc->r_length() != 2 )
+ throw "length != 2 and ARM64_RELOC_PAGE21 not supported";
+ target.addend = prefixRelocAddend;
+ instruction = contentValue;
+ encodedAddend = ((instruction & 0x60000000) >> 29) | ((instruction & 0x01FFFFE0) >> 3);
+ encodedAddend *= 4096; // internally addend is in bytes, so scale
+ if ( encodedAddend != 0 ) {
+ if ( prefixRelocAddend == 0 ) {
+ warning("adrp instruction at 0x%08X has embedded addend. ARM64_RELOC_ADDEND should be used instead", reloc->r_address());
+ target.addend = encodedAddend;
+ }
+ else {
+ throwf("adrp instruction at 0x%08X has embedded addend and ARM64_RELOC_ADDEND also used", reloc->r_address());
+ }
+ }
+ parser.addFixups(src, ld::Fixup::kindStoreARM64Page21, target);
+ break;
+ case ARM64_RELOC_PAGEOFF12:
+ if ( reloc->r_pcrel() )
+ throw "pcrel and ARM64_RELOC_PAGEOFF12 not supported";
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_PAGEOFF12 not supported";
+ if ( reloc->r_length() != 2 )
+ throw "length != 2 and ARM64_RELOC_PAGEOFF12 not supported";
+ target.addend = prefixRelocAddend;
+ instruction = contentValue;
+ encodedAddend = ((instruction & 0x003FFC00) >> 10);
+ // internally addend is in bytes. Some instructions have an implicit scale factor
+ if ( (instruction & 0x3B000000) == 0x39000000 ) {
+ switch ( instruction & 0xC0000000 ) {
+ case 0x00000000:
+ break;
+ case 0x40000000:
+ encodedAddend *= 2;
+ break;
+ case 0x80000000:
+ encodedAddend *= 4;
+ break;
+ case 0xC0000000:
+ encodedAddend *= 8;
+ break;
+ }
+ }
+ if ( encodedAddend != 0 ) {
+ if ( prefixRelocAddend == 0 ) {
+ warning("pageoff12 instruction at 0x%08X has embedded addend. ARM64_RELOC_ADDEND should be used instead", reloc->r_address());
+ target.addend = encodedAddend;
+ }
+ else {
+ throwf("pageoff12 instruction at 0x%08X has embedded addend and ARM64_RELOC_ADDEND also used", reloc->r_address());
+ }
+ }
+ parser.addFixups(src, ld::Fixup::kindStoreARM64PageOff12, target);
+ break;
+ case ARM64_RELOC_GOT_LOAD_PAGE21:
+ if ( ! reloc->r_pcrel() )
+ throw "not pcrel and ARM64_RELOC_GOT_LOAD_PAGE21 not supported";
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_GOT_LOAD_PAGE21 not supported";
+ if ( reloc->r_length() != 2 )
+ throw "length != 2 and ARM64_RELOC_GOT_LOAD_PAGE21 not supported";
+ if ( prefixRelocAddend != 0 )
+ throw "ARM64_RELOC_ADDEND followed by ARM64_RELOC_GOT_LOAD_PAGE21 not supported";
+ instruction = contentValue;
+ target.addend = ((instruction & 0x60000000) >> 29) | ((instruction & 0x01FFFFE0) >> 3);
+ if ( target.addend != 0 )
+ throw "non-zero addend with ARM64_RELOC_GOT_LOAD_PAGE21 is not supported";
+ parser.addFixups(src, ld::Fixup::kindStoreARM64GOTLoadPage21, target);
+ break;
+ case ARM64_RELOC_GOT_LOAD_PAGEOFF12:
+ if ( reloc->r_pcrel() )
+ throw "pcrel and ARM64_RELOC_GOT_LOAD_PAGEOFF12 not supported";
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_GOT_LOAD_PAGEOFF12 not supported";
+ if ( reloc->r_length() != 2 )
+ throw "length != 2 and ARM64_RELOC_GOT_LOAD_PAGEOFF12 not supported";
+ if ( prefixRelocAddend != 0 )
+ throw "ARM64_RELOC_ADDEND followed by ARM64_RELOC_GOT_LOAD_PAGEOFF12 not supported";
+ instruction = contentValue;
+ target.addend = ((instruction & 0x003FFC00) >> 10);
+ parser.addFixups(src, ld::Fixup::kindStoreARM64GOTLoadPageOff12, target);
+ break;
+ case ARM64_RELOC_TLVP_LOAD_PAGE21:
+ if ( ! reloc->r_pcrel() )
+ throw "not pcrel and ARM64_RELOC_TLVP_LOAD_PAGE21 not supported";
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_TLVP_LOAD_PAGE21 not supported";
+ if ( reloc->r_length() != 2 )
+ throw "length != 2 and ARM64_RELOC_TLVP_LOAD_PAGE21 not supported";
+ if ( prefixRelocAddend != 0 )
+ throw "ARM64_RELOC_ADDEND followed by ARM64_RELOC_TLVP_LOAD_PAGE21 not supported";
+ instruction = contentValue;
+ target.addend = ((instruction & 0x60000000) >> 29) | ((instruction & 0x01FFFFE0) >> 3);
+ if ( target.addend != 0 )
+ throw "non-zero addend with ARM64_RELOC_GOT_LOAD_PAGE21 is not supported";
+ parser.addFixups(src, ld::Fixup::kindStoreARM64TLVPLoadPage21, target);
+ break;
+ case ARM64_RELOC_TLVP_LOAD_PAGEOFF12:
+ if ( reloc->r_pcrel() )
+ throw "pcrel and ARM64_RELOC_TLVP_LOAD_PAGEOFF12 not supported";
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_TLVP_LOAD_PAGEOFF12 not supported";
+ if ( reloc->r_length() != 2 )
+ throw "length != 2 and ARM64_RELOC_TLVP_LOAD_PAGEOFF12 not supported";
+ if ( prefixRelocAddend != 0 )
+ throw "ARM64_RELOC_ADDEND followed by ARM64_RELOC_TLVP_LOAD_PAGEOFF12 not supported";
+ instruction = contentValue;
+ target.addend = ((instruction & 0x003FFC00) >> 10);
+ parser.addFixups(src, ld::Fixup::kindStoreARM64TLVPLoadPageOff12, target);
+ break;
+ case ARM64_RELOC_SUBTRACTOR:
+ if ( reloc->r_pcrel() )
+ throw "ARM64_RELOC_SUBTRACTOR cannot be pc-relative";
+ if ( reloc->r_length() < 2 )
+ throw "ARM64_RELOC_SUBTRACTOR must have r_length of 2 or 3";
+ if ( !reloc->r_extern() )
+ throw "ARM64_RELOC_SUBTRACTOR must have r_extern=1";
+ if ( nextReloc->r_type() != ARM64_RELOC_UNSIGNED )
+ throw "ARM64_RELOC_SUBTRACTOR must be followed by ARM64_RELOC_UNSIGNED";
+ if ( prefixRelocAddend != 0 )
+ throw "ARM64_RELOC_ADDEND followed by ARM64_RELOC_SUBTRACTOR not supported";
+ result = true;
+ if ( nextReloc->r_pcrel() )
+ throw "ARM64_RELOC_UNSIGNED following a ARM64_RELOC_SUBTRACTOR cannot be pc-relative";
+ if ( nextReloc->r_length() != reloc->r_length() )
+ throw "ARM64_RELOC_UNSIGNED following a ARM64_RELOC_SUBTRACTOR must have same r_length";
+ if ( nextReloc->r_extern() ) {
+ const macho_nlist<P>& sym = parser.symbolFromIndex(nextReloc->r_symbolnum());
+ // use direct reference for local symbols
+ if ( ((sym.n_type() & N_TYPE) == N_SECT) && (((sym.n_type() & N_EXT) == 0) || (parser.nameFromSymbol(sym)[0] == 'L')) ) {
+ parser.findTargetFromAddressAndSectionNum(sym.n_value(), sym.n_sect(), toTarget);
+ toTarget.addend = contentValue;
+ useDirectBinding = true;
+ }
+ else {
+ toTarget.name = parser.nameFromSymbol(sym);
+ toTarget.weakImport = parser.weakImportFromSymbol(sym);
+ toTarget.addend = contentValue;
+ useDirectBinding = false;
+ }
+ }
+ else {
+ parser.findTargetFromAddressAndSectionNum(contentValue, nextReloc->r_symbolnum(), toTarget);
+ useDirectBinding = (toTarget.atom->scope() == ld::Atom::scopeTranslationUnit);
+ }
+ if ( useDirectBinding )
+ parser.addFixup(src, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, toTarget.atom);
+ else
+ parser.addFixup(src, ld::Fixup::k1of4, ld::Fixup::kindSetTargetAddress, toTarget.weakImport, toTarget.name);
+ parser.addFixup(src, ld::Fixup::k2of4, ld::Fixup::kindAddAddend, toTarget.addend);
+ if ( target.atom == NULL )
+ parser.addFixup(src, ld::Fixup::k3of4, ld::Fixup::kindSubtractTargetAddress, false, target.name);
+ else
+ parser.addFixup(src, ld::Fixup::k3of4, ld::Fixup::kindSubtractTargetAddress, target.atom);
+ if ( reloc->r_length() == 2 )
+ parser.addFixup(src, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian32);
+ else
+ parser.addFixup(src, ld::Fixup::k4of4, ld::Fixup::kindStoreLittleEndian64);
+ break;
+ case ARM64_RELOC_POINTER_TO_GOT:
+ if ( ! reloc->r_extern() )
+ throw "r_extern == 0 and ARM64_RELOC_POINTER_TO_GOT not supported";
+ if ( prefixRelocAddend != 0 )
+ throw "ARM64_RELOC_ADDEND followed by ARM64_RELOC_POINTER_TO_GOT not supported";
+ if ( reloc->r_pcrel() ) {
+ if ( reloc->r_length() != 2 )
+ throw "r_length != 2 and r_extern = 1 and ARM64_RELOC_POINTER_TO_GOT not supported";
+ parser.addFixups(src, ld::Fixup::kindStoreARM64PCRelToGOT, target);
+ }
+ else {
+ if ( reloc->r_length() != 3 )
+ throw "r_length != 3 and r_extern = 0 and ARM64_RELOC_POINTER_TO_GOT not supported";
+ parser.addFixups(src, ld::Fixup::kindStoreARM64PointerToGOT, target);
+ }
+ break;
+ default:
+ throwf("unknown relocation type %d", reloc->r_type());
}
return result;
}
-
-
-
-
+#endif
template <typename A>
bool ObjC1ClassSection<A>::addRelocFixup(class Parser<A>& parser, const macho_relocation_info<P>* reloc)
return FixedSizeSection<x86>::addRelocFixup(parser, reloc);
}
-template <>
-bool ObjC1ClassSection<ppc>::addRelocFixup(class Parser<ppc>& parser, const macho_relocation_info<ppc::P>* reloc)
-{
- // if this is the reloc for the super class name string, add implicit reference to super class
- if ( ((reloc->r_address() & R_SCATTERED) == 0) && (reloc->r_type() == PPC_RELOC_VANILLA) ) {
- assert( reloc->r_length() == 2 );
- assert( ! reloc->r_pcrel() );
-
- const macho_section<P>* sect = this->machoSection();
- Parser<ppc>::SourceLocation src;
- uint32_t srcAddr = sect->addr() + reloc->r_address();
- src.atom = this->findAtomByAddress(srcAddr);
- src.offsetInAtom = srcAddr - src.atom->objectAddress();
- if ( src.offsetInAtom == 4 ) {
- Parser<ppc>::TargetDesc stringTarget;
- const uint8_t* fixUpPtr = file().fileContent() + sect->offset() + reloc->r_address();
- uint32_t contentValue = BigEndian::get32(*((uint32_t*)fixUpPtr));
- parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), stringTarget);
-
- assert(stringTarget.atom != NULL);
- assert(stringTarget.atom->contentType() == ld::Atom::typeCString);
- const char* superClassBaseName = (char*)stringTarget.atom->rawContentPointer();
- char* superClassName = new char[strlen(superClassBaseName) + 20];
- strcpy(superClassName, ".objc_class_name_");
- strcat(superClassName, superClassBaseName);
-
- parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindSetTargetAddress, false, superClassName);
- }
- }
-
- // inherited
- return FixedSizeSection<ppc>::addRelocFixup(parser, reloc);
-}
-
-
template <typename A>
}
-template <>
-bool Objc1ClassReferences<ppc>::addRelocFixup(class Parser<ppc>& parser, const macho_relocation_info<ppc::P>* reloc)
-{
- // add implict class refs, fixups not usable yet, so look at relocations
- assert( (reloc->r_address() & R_SCATTERED) == 0 );
- assert( reloc->r_type() == PPC_RELOC_VANILLA );
- assert( reloc->r_length() == 2 );
- assert( ! reloc->r_pcrel() );
-
- const macho_section<P>* sect = this->machoSection();
- Parser<ppc>::SourceLocation src;
- uint32_t srcAddr = sect->addr() + reloc->r_address();
- src.atom = this->findAtomByAddress(srcAddr);
- src.offsetInAtom = srcAddr - src.atom->objectAddress();
- Parser<ppc>::TargetDesc stringTarget;
- const uint8_t* fixUpPtr = file().fileContent() + sect->offset() + reloc->r_address();
- uint32_t contentValue = BigEndian::get32(*((uint32_t*)fixUpPtr));
- parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), stringTarget);
-
- assert(stringTarget.atom != NULL);
- assert(stringTarget.atom->contentType() == ld::Atom::typeCString);
- const char* baseClassName = (char*)stringTarget.atom->rawContentPointer();
- char* objcClassName = new char[strlen(baseClassName) + 20];
- strcpy(objcClassName, ".objc_class_name_");
- strcat(objcClassName, baseClassName);
-
- parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindSetTargetAddress, false, objcClassName);
-
- // inherited
- return PointerToCStringSection<ppc>::addRelocFixup(parser, reloc);
-}
-
template <>
bool Objc1ClassReferences<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocation_info<x86::P>* reloc)
return PointerToCStringSection<x86>::addRelocFixup(parser, reloc);
}
+#if SUPPORT_ARCH_arm64
+template <>
+void Section<arm64>::addLOH(class Parser<arm64>& parser, int kind, int count, const uint64_t addrs[]) {
+ switch (kind) {
+ case LOH_ARM64_ADRP_ADRP:
+ case LOH_ARM64_ADRP_LDR:
+ case LOH_ARM64_ADRP_ADD:
+ case LOH_ARM64_ADRP_LDR_GOT:
+ if ( count != 2 )
+ warning("arm64 Linker Optimiztion Hint %d has wrong number of arguments", kind);
+ break;
+ case LOH_ARM64_ADRP_ADD_LDR:
+ case LOH_ARM64_ADRP_LDR_GOT_LDR:
+ case LOH_ARM64_ADRP_ADD_STR:
+ case LOH_ARM64_ADRP_LDR_GOT_STR:
+ if ( count != 3 )
+ warning("arm64 Linker Optimiztion Hint %d has wrong number of arguments", kind);
+ }
+
+ // pick lowest address in tuple for use as offsetInAtom
+ uint64_t lowestAddress = addrs[0];
+ for(int i=1; i < count; ++i) {
+ if ( addrs[i] < lowestAddress )
+ lowestAddress = addrs[i];
+ }
+ // verify all other address are in same atom
+ Atom<arm64>* inAtom = parser.findAtomByAddress(lowestAddress);
+ const uint64_t atomStartAddr = inAtom->objectAddress();
+ const uint64_t atomEndAddr = atomStartAddr + inAtom->size();
+ for(int i=0; i < count; ++i) {
+ if ( (addrs[i] < atomStartAddr) || (addrs[i] >= atomEndAddr) ) {
+ warning("arm64 Linker Optimiztion Hint addresses are not in same atom: 0x%08llX and 0x%08llX",
+ lowestAddress, addrs[i]);
+ return; // skip this LOH
+ }
+ if ( (addrs[i] & 0x3) != 0 ) {
+ warning("arm64 Linker Optimiztion Hint address is not 4-byte aligned: 0x%08llX", addrs[i]);
+ return; // skip this LOH
+ }
+ if ( (addrs[i] - lowestAddress) > 0xFFFF ) {
+ if ( parser.verboseOptimizationHints() ) {
+ warning("arm64 Linker Optimiztion Hint addresses are too far apart: 0x%08llX and 0x%08llX",
+ lowestAddress, addrs[i]);
+ }
+ return; // skip this LOH
+ }
+ }
+
+ // encoded kind, count, and address deltas in 64-bit addend
+ ld::Fixup::LOH_arm64 extra;
+ extra.addend = 0;
+ extra.info.kind = kind;
+ extra.info.count = count-1;
+ extra.info.delta1 = (addrs[0] - lowestAddress) >> 2;
+ extra.info.delta2 = (count > 1) ? ((addrs[1] - lowestAddress) >> 2) : 0;
+ extra.info.delta3 = (count > 2) ? ((addrs[2] - lowestAddress) >> 2) : 0;
+ extra.info.delta4 = (count > 3) ? ((addrs[3] - lowestAddress) >> 2) : 0;
+ typename Parser<arm64>::SourceLocation src(inAtom, lowestAddress- inAtom->objectAddress());
+ parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindLinkerOptimizationHint, extra.addend);
+}
+#endif
+
+template <typename A>
+void Section<A>::addLOH(class Parser<A>& parser, int kind, int count, const uint64_t addrs[]) {
+
+}
template <typename A>
void Section<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&)
}
}
}
+ if ( !this->_altEntries.empty() && !this->addFollowOnFixups() ) {
+ if ( _altEntries.count(_beginAtoms) != 0 )
+ warning("N_ALT_ENTRY bit set on first atom in section %s/%s", sect->segname(), Section<A>::makeSectionName(sect));
+
+ Atom<A>* end = &_endAtoms[-1];
+ for(Atom<A>* p = _beginAtoms; p < end; ++p) {
+ Atom<A>* nextAtom = &p[1];
+ if ( _altEntries.count(nextAtom) != 0 ) {
+ typename Parser<A>::SourceLocation src(p, 0);
+ parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindNoneFollowOn, nextAtom);
+ typename Parser<A>::SourceLocation src2(nextAtom, 0);
+ parser.addFixup(src2, ld::Fixup::k1of1, ld::Fixup::kindNoneGroupSubordinate, p);
+ }
+ }
+ }
+
+ // <rdar://problem/9218847> track data-in-code
+ if ( parser.hasDataInCodeLabels() && (this->type() == ld::Section::typeCode) ) {
+ for (uint32_t i=0; i < parser.symbolCount(); ++i) {
+ const macho_nlist<P>& sym = parser.symbolFromIndex(i);
+ // ignore stabs
+ if ( (sym.n_type() & N_STAB) != 0 )
+ continue;
+ // ignore non-definitions
+ if ( (sym.n_type() & N_TYPE) != N_SECT )
+ continue;
+
+ // 'L' labels do not denote atom breaks
+ const char* symbolName = parser.nameFromSymbol(sym);
+ if ( symbolName[0] == 'L' ) {
+ if ( strncmp(symbolName, "L$start$", 8) == 0 ) {
+ ld::Fixup::Kind kind = ld::Fixup::kindNone;
+ if ( strncmp(&symbolName[8], "data$", 5) == 0 )
+ kind = ld::Fixup::kindDataInCodeStartData;
+ else if ( strncmp(&symbolName[8], "code$", 5) == 0 )
+ kind = ld::Fixup::kindDataInCodeEnd;
+ else if ( strncmp(&symbolName[8], "jt8$", 4) == 0 )
+ kind = ld::Fixup::kindDataInCodeStartJT8;
+ else if ( strncmp(&symbolName[8], "jt16$", 4) == 0 )
+ kind = ld::Fixup::kindDataInCodeStartJT16;
+ else if ( strncmp(&symbolName[8], "jt32$", 4) == 0 )
+ kind = ld::Fixup::kindDataInCodeStartJT32;
+ else if ( strncmp(&symbolName[8], "jta32$", 4) == 0 )
+ kind = ld::Fixup::kindDataInCodeStartJTA32;
+ else
+ warning("unknown L$start$ label %s in file %s", symbolName, this->file().path());
+ if ( kind != ld::Fixup::kindNone ) {
+ Atom<A>* inAtom = parser.findAtomByAddress(sym.n_value());
+ typename Parser<A>::SourceLocation src(inAtom, sym.n_value() - inAtom->objectAddress());
+ parser.addFixup(src, ld::Fixup::k1of1, kind);
+ }
+ }
+ }
+ }
+ }
+
+ // <rdar://problem/11150575> Handle LC_DATA_IN_CODE in object files
+ if ( this->type() == ld::Section::typeCode ) {
+ const pint_t startAddr = this->_machOSection->addr();
+ const pint_t endAddr = startAddr + this->_machOSection->size();
+ for ( const macho_data_in_code_entry<P>* p = parser.dataInCodeStart(); p != parser.dataInCodeEnd(); ++p ) {
+ if ( (p->offset() >= startAddr) && (p->offset() < endAddr) ) {
+ ld::Fixup::Kind kind = ld::Fixup::kindNone;
+ switch ( p->kind() ) {
+ case DICE_KIND_DATA:
+ kind = ld::Fixup::kindDataInCodeStartData;
+ break;
+ case DICE_KIND_JUMP_TABLE8:
+ kind = ld::Fixup::kindDataInCodeStartJT8;
+ break;
+ case DICE_KIND_JUMP_TABLE16:
+ kind = ld::Fixup::kindDataInCodeStartJT16;
+ break;
+ case DICE_KIND_JUMP_TABLE32:
+ kind = ld::Fixup::kindDataInCodeStartJT32;
+ break;
+ case DICE_KIND_ABS_JUMP_TABLE32:
+ kind = ld::Fixup::kindDataInCodeStartJTA32;
+ break;
+ default:
+ kind = ld::Fixup::kindDataInCodeStartData;
+ warning("uknown LC_DATA_IN_CODE kind (%d) at offset 0x%08X", p->kind(), p->offset());
+ break;
+ }
+ Atom<A>* inAtom = parser.findAtomByAddress(p->offset());
+ typename Parser<A>::SourceLocation srcStart(inAtom, p->offset() - inAtom->objectAddress());
+ parser.addFixup(srcStart, ld::Fixup::k1of1, kind);
+ typename Parser<A>::SourceLocation srcEnd(inAtom, p->offset() + p->length() - inAtom->objectAddress());
+ parser.addFixup(srcEnd, ld::Fixup::k1of1, ld::Fixup::kindDataInCodeEnd);
+ }
+ }
+ }
+
+ // <rdar://problem/11945700> convert linker optimization hints into internal format
+ if ( this->type() == ld::Section::typeCode && parser.hasOptimizationHints() ) {
+ const pint_t startAddr = this->_machOSection->addr();
+ const pint_t endAddr = startAddr + this->_machOSection->size();
+ for (const uint8_t* p = parser.optimizationHintsStart(); p < parser.optimizationHintsEnd(); ) {
+ uint64_t addrs[4];
+ int32_t kind = read_uleb128(&p, parser.optimizationHintsEnd());
+ if ( kind == 0 ) // padding at end of loh buffer
+ break;
+ if ( kind == -1 ) {
+ warning("malformed uleb128 kind in LC_LINKER_OPTIMIZATION_HINTS");
+ break;
+ }
+ int32_t count = read_uleb128(&p, parser.optimizationHintsEnd());
+ if ( count == -1 ) {
+ warning("malformed uleb128 count in LC_LINKER_OPTIMIZATION_HINTS");
+ break;
+ }
+ if ( count > 3 ) {
+ warning("address count > 3 in LC_LINKER_OPTIMIZATION_HINTS");
+ break;
+ }
+ for (int32_t i=0; i < count; ++i) {
+ addrs[i] = read_uleb128(&p, parser.optimizationHintsEnd());
+ }
+ if ( (startAddr <= addrs[0]) && (addrs[0] < endAddr) ) {
+ this->addLOH(parser, kind, count, addrs);
+ //fprintf(stderr, "kind=%d", kind);
+ //for (int32_t i=0; i < count; ++i) {
+ // fprintf(stderr, ", addr=0x%08llX", addrs[i]);
+ //}
+ //fprintf(stderr, "\n");
+ }
+ }
+ }
+
// add follow-on fixups for aliases
if ( _hasAliases ) {
// main function used by linker to instantiate ld::Files
//
ld::relocatable::File* parse(const uint8_t* fileContent, uint64_t fileLength,
- const char* path, time_t modTime, uint32_t ordinal, const ParserOptions& opts)
+ const char* path, time_t modTime, ld::File::Ordinal ordinal, const ParserOptions& opts)
{
switch ( opts.architecture ) {
+#if SUPPORT_ARCH_x86_64
case CPU_TYPE_X86_64:
if ( mach_o::relocatable::Parser<x86_64>::validFile(fileContent) )
return mach_o::relocatable::Parser<x86_64>::parse(fileContent, fileLength, path, modTime, ordinal, opts);
break;
+#endif
+#if SUPPORT_ARCH_i386
case CPU_TYPE_I386:
if ( mach_o::relocatable::Parser<x86>::validFile(fileContent) )
return mach_o::relocatable::Parser<x86>::parse(fileContent, fileLength, path, modTime, ordinal, opts);
break;
+#endif
+#if SUPPORT_ARCH_arm_any
case CPU_TYPE_ARM:
if ( mach_o::relocatable::Parser<arm>::validFile(fileContent, opts.objSubtypeMustMatch, opts.subType) )
return mach_o::relocatable::Parser<arm>::parse(fileContent, fileLength, path, modTime, ordinal, opts);
break;
- case CPU_TYPE_POWERPC:
- if ( mach_o::relocatable::Parser<ppc>::validFile(fileContent) )
- return mach_o::relocatable::Parser<ppc>::parse(fileContent, fileLength, path, modTime, ordinal, opts);
- break;
- case CPU_TYPE_POWERPC64:
- if ( mach_o::relocatable::Parser<ppc64>::validFile(fileContent) )
- return mach_o::relocatable::Parser<ppc64>::parse(fileContent, fileLength, path, modTime, ordinal, opts);
+#endif
+#if SUPPORT_ARCH_arm64
+ case CPU_TYPE_ARM64:
+ if ( mach_o::relocatable::Parser<arm64>::validFile(fileContent, opts.objSubtypeMustMatch, opts.subType) )
+ return mach_o::relocatable::Parser<arm64>::parse(fileContent, fileLength, path, modTime, ordinal, opts);
break;
+#endif
}
return NULL;
}
return ( mach_o::relocatable::Parser<x86>::validFile(fileContent) );
case CPU_TYPE_ARM:
return ( mach_o::relocatable::Parser<arm>::validFile(fileContent, opts.objSubtypeMustMatch, opts.subType) );
- case CPU_TYPE_POWERPC:
- return ( mach_o::relocatable::Parser<ppc>::validFile(fileContent) );
- case CPU_TYPE_POWERPC64:
- return ( mach_o::relocatable::Parser<ppc64>::validFile(fileContent) );
+ case CPU_TYPE_ARM64:
+ return ( mach_o::relocatable::Parser<arm64>::validFile(fileContent, opts.objSubtypeMustMatch, opts.subType) );
}
return false;
}
//
// used by linker to infer architecture when no -arch is on command line
//
-bool isObjectFile(const uint8_t* fileContent, cpu_type_t* result, cpu_subtype_t* subResult)
+bool isObjectFile(const uint8_t* fileContent, cpu_type_t* result, cpu_subtype_t* subResult, Options::Platform* platform)
{
if ( mach_o::relocatable::Parser<x86_64>::validFile(fileContent) ) {
*result = CPU_TYPE_X86_64;
- *subResult = CPU_SUBTYPE_X86_64_ALL;
+ const macho_header<Pointer64<LittleEndian> >* header = (const macho_header<Pointer64<LittleEndian> >*)fileContent;
+ *subResult = header->cpusubtype();
+ *platform = Parser<x86_64>::findPlatform(header);
return true;
}
if ( mach_o::relocatable::Parser<x86>::validFile(fileContent) ) {
+ const macho_header<Pointer32<LittleEndian> >* header = (const macho_header<Pointer32<LittleEndian> >*)fileContent;
*result = CPU_TYPE_I386;
*subResult = CPU_SUBTYPE_X86_ALL;
+ *platform = Parser<x86>::findPlatform(header);
return true;
}
if ( mach_o::relocatable::Parser<arm>::validFile(fileContent, false, 0) ) {
- *result = CPU_TYPE_ARM;
const macho_header<Pointer32<LittleEndian> >* header = (const macho_header<Pointer32<LittleEndian> >*)fileContent;
+ *result = CPU_TYPE_ARM;
*subResult = header->cpusubtype();
+ *platform = Parser<arm>::findPlatform(header);
return true;
}
- if ( mach_o::relocatable::Parser<ppc>::validFile(fileContent) ) {
- *result = CPU_TYPE_POWERPC;
- const macho_header<Pointer32<BigEndian> >* header = (const macho_header<Pointer32<BigEndian> >*)fileContent;
- *subResult = header->cpusubtype();
- return true;
- }
- if ( mach_o::relocatable::Parser<ppc64>::validFile(fileContent) ) {
- *result = CPU_TYPE_POWERPC64;
- *subResult = CPU_SUBTYPE_POWERPC_ALL;
+ if ( mach_o::relocatable::Parser<arm64>::validFile(fileContent, false, 0) ) {
+ const macho_header<Pointer64<LittleEndian> >* header = (const macho_header<Pointer64<LittleEndian> >*)fileContent;
+ *result = CPU_TYPE_ARM64;
+ *subResult = CPU_SUBTYPE_ARM64_ALL;
+ *platform = Parser<arm64>::findPlatform(header);
return true;
}
return false;
if ( mach_o::relocatable::Parser<arm>::validFile(fileContent, false, 0) ) {
return mach_o::relocatable::Parser<arm>::fileKind(fileContent);
}
- if ( mach_o::relocatable::Parser<ppc>::validFile(fileContent) ) {
- return mach_o::relocatable::Parser<ppc>::fileKind(fileContent);
- }
- if ( mach_o::relocatable::Parser<ppc64>::validFile(fileContent) ) {
- return mach_o::relocatable::Parser<ppc64>::fileKind(fileContent);
- }
return NULL;
}
else if ( mach_o::relocatable::Parser<x86>::validFile(fileContent, false, 0) ) {
return mach_o::relocatable::Parser<x86>::hasObjC2Categories(fileContent);
}
+#if SUPPORT_ARCH_arm64
+ else if ( mach_o::relocatable::Parser<arm64>::validFile(fileContent, false, 0) ) {
+ return mach_o::relocatable::Parser<arm64>::hasObjC2Categories(fileContent);
+ }
+#endif
return false;
}
+//
+// Used by archive reader when -ObjC option is specified
+//
+bool hasObjC1Categories(const uint8_t* fileContent)
+{
+ if ( mach_o::relocatable::Parser<x86>::validFile(fileContent, false, 0) ) {
+ return mach_o::relocatable::Parser<x86>::hasObjC1Categories(fileContent);
+ }
+ return false;
+}
+
+//
+// Used by bitcode obfuscator to get a list of non local symbols from object file
+//
+bool getNonLocalSymbols(const uint8_t* fileContent, std::vector<const char*> &syms)
+{
+ if ( mach_o::relocatable::Parser<x86_64>::validFile(fileContent) ) {
+ return mach_o::relocatable::Parser<x86_64>::getNonLocalSymbols(fileContent, syms);
+ }
+ else if ( mach_o::relocatable::Parser<arm>::validFile(fileContent, false, 0) ) {
+ return mach_o::relocatable::Parser<arm>::getNonLocalSymbols(fileContent, syms);
+ }
+ else if ( mach_o::relocatable::Parser<x86>::validFile(fileContent, false, 0) ) {
+ return mach_o::relocatable::Parser<x86>::getNonLocalSymbols(fileContent, syms);
+ }
+ else if ( mach_o::relocatable::Parser<arm64>::validFile(fileContent, false, 0) ) {
+ return mach_o::relocatable::Parser<arm64>::getNonLocalSymbols(fileContent, syms);
+ }
+ return false;
+}
+
} // namespace relocatable