]> git.saurik.com Git - apple/ld64.git/blobdiff - src/ld/parsers/macho_relocatable_file.cpp
ld64-128.2.tar.gz
[apple/ld64.git] / src / ld / parsers / macho_relocatable_file.cpp
index 25c19653aa4bde31d963f4306b97548a863d87c2..e79d2618c01215181f594fdcc15b39e98bc499d9 100644 (file)
@@ -21,7 +21,7 @@
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
-
 
 #include <stdint.h>
 #include <stdlib.h>
 
 #include <stdint.h>
 #include <stdlib.h>
@@ -34,9 +34,9 @@
 
 #include "MachOFileAbstraction.hpp"
 
 
 #include "MachOFileAbstraction.hpp"
 
-#include <libunwind/DwarfInstructions.hpp>
-#include <libunwind/AddressSpace.hpp>
-#include <libunwind/Registers.hpp>
+#include "libunwind/DwarfInstructions.hpp"
+#include "libunwind/AddressSpace.hpp"
+#include "libunwind/Registers.hpp"
 
 #include <vector>
 #include <set>
 
 #include <vector>
 #include <set>
@@ -64,6 +64,7 @@ template <typename A> class Parser;
 template <typename A> class Atom;
 template <typename A> class Section;
 template <typename A> class CFISection;
 template <typename A> class Atom;
 template <typename A> class Section;
 template <typename A> class CFISection;
+template <typename A> class CUSection;
 
 template <typename A>
 class File : public ld::relocatable::File
 
 template <typename A>
 class File : public ld::relocatable::File
@@ -147,15 +148,16 @@ public:
        virtual bool                                    addFollowOnFixups() const       { return ! _file.canScatterAtoms(); }
        virtual uint32_t                                appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual bool                                    addFollowOnFixups() const       { return ! _file.canScatterAtoms(); }
        virtual uint32_t                                appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                               const struct Parser<A>::CFIInfoArray&) = 0;
+                                                                                               const struct Parser<A>::CFI_CU_InfoArrays&) = 0;
        virtual uint32_t                                computeAtomCount(class Parser<A>& parser, 
                                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual uint32_t                                computeAtomCount(class Parser<A>& parser, 
                                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                                               const struct Parser<A>::CFIInfoArray&) = 0;
-       virtual void                                    makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray&);
+                                                                                                               const struct Parser<A>::CFI_CU_InfoArrays&) = 0;
+       virtual void                                    makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
        virtual bool                                    addRelocFixup(class Parser<A>& parser, const macho_relocation_info<P>*);
        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                                    addRelocFixup(class Parser<A>& parser, const macho_relocation_info<P>*);
        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; }
+       static const char*                              makeSectionName(const macho_section<typename A::P>* s);
 
 protected:     
                                                Section(File<A>& f, const macho_section<typename A::P>* s)
 
 protected:     
                                                Section(File<A>& f, const macho_section<typename A::P>* s)
@@ -166,11 +168,9 @@ protected:
                                                                _beginAtoms(NULL), _endAtoms(NULL), _hasAliases(false) { }
 
 
                                                                _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);
        static const char*                              makeSegmentName(const macho_section<typename A::P>* s);
        Atom<A>*                                                findContentAtomByAddress(pint_t addr, class Atom<A>* start, class Atom<A>* end);
        uint32_t                                                x86_64PcRelOffset(uint8_t r_type);
        static const char*                              makeSegmentName(const macho_section<typename A::P>* s);
-       static const char*                              makeSectionName(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);
        static bool                                             exectuable(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);
        static bool                                             exectuable(const macho_section<typename A::P>* s);
@@ -193,9 +193,9 @@ public:
        uint32_t                        cfiCount();
 
        virtual ld::Atom::ContentType   contentType()           { return ld::Atom::typeCFI; }
        uint32_t                        cfiCount();
 
        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>::CFIInfoArray&);
-       virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFIInfoArray&);
-       virtual void            makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray&);
+       virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
+       virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
+       virtual void            makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
        virtual bool            addFollowOnFixups() const       { return false; }
 
 
        virtual bool            addFollowOnFixups() const       { return false; }
 
 
@@ -248,6 +248,46 @@ private:
 };
 
 
 };
 
 
+template <typename A>
+class CUSection : public Section<A>
+{
+public:
+                                               CUSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
+                                                       : Section<A>(f, s) { }
+
+       typedef typename A::P::uint_t   pint_t;
+       typedef typename A::P                   P;
+       typedef typename A::P::E                E;
+                                       
+       virtual uint32_t                computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&) { return 0; }
+       virtual uint32_t                appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&) { return 0; }
+       virtual void                    makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
+       virtual bool                    addFollowOnFixups() const       { return false; }
+       
+       struct Info {
+               pint_t          functionStartAddress;
+               uint32_t        functionSymbolIndex;
+               uint32_t        rangeLength;
+               uint32_t        compactUnwindInfo;
+               const char*     personality;
+               pint_t          lsdaAddress;
+               Atom<A>*        function;
+               Atom<A>*        lsda;
+       };
+
+       uint32_t                                count();
+       void                                    parse(class Parser<A>& parser, uint32_t cnt, Info array[]);
+       
+       
+private:
+       
+       const char*                             personalityName(class Parser<A>& parser, const macho_relocation_info<P>* reloc);
+
+       static int                              infoSorter(const void* l, const void* r);
+
+};
+
+
 template <typename A>
 class TentativeDefinitionSection : public Section<A>
 {
 template <typename A>
 class TentativeDefinitionSection : public Section<A>
 {
@@ -259,11 +299,11 @@ public:
        virtual bool            addFollowOnFixups() const       { return false; }
        virtual Atom<A>*        findAtomByAddress(typename A::P::uint_t addr) { throw "TentativeDefinitionSection::findAtomByAddress() should never be called"; }
        virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual bool            addFollowOnFixups() const       { return false; }
        virtual Atom<A>*        findAtomByAddress(typename A::P::uint_t addr) { throw "TentativeDefinitionSection::findAtomByAddress() should never be called"; }
        virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                       const struct Parser<A>::CFIInfoArray&);
+                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&);
        virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                               const struct Parser<A>::CFIInfoArray&);
-       virtual void            makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray&) {}
+                                                                               const struct Parser<A>::CFI_CU_InfoArrays&);
+       virtual void            makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&) {}
 private:
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
 private:
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
@@ -283,11 +323,11 @@ public:
        virtual bool            addFollowOnFixups() const       { return false; }
        virtual Atom<A>*        findAtomByAddress(typename A::P::uint_t addr) { throw "AbsoluteSymbolSection::findAtomByAddress() should never be called"; }
        virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual bool            addFollowOnFixups() const       { return false; }
        virtual Atom<A>*        findAtomByAddress(typename A::P::uint_t addr) { throw "AbsoluteSymbolSection::findAtomByAddress() should never be called"; }
        virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                       const struct Parser<A>::CFIInfoArray&);
+                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&);
        virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                               const struct Parser<A>::CFIInfoArray&);
-       virtual void            makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray&) {}
+                                                                               const struct Parser<A>::CFI_CU_InfoArrays&);
+       virtual void            makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&) {}
        virtual Atom<A>*        findAbsAtomForValue(typename A::P::uint_t);
        
 private:
        virtual Atom<A>*        findAbsAtomForValue(typename A::P::uint_t);
        
 private:
@@ -304,10 +344,10 @@ public:
        virtual ld::Atom::ContentType   contentType() { return _type; }
        virtual bool                                    dontDeadStrip();
        virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual ld::Atom::ContentType   contentType() { return _type; }
        virtual bool                                    dontDeadStrip();
        virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                       const struct Parser<A>::CFIInfoArray&);
+                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&);
        virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
        virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, 
                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                       const struct Parser<A>::CFIInfoArray&);
+                                                                       const struct Parser<A>::CFI_CU_InfoArrays&);
 protected:
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
 protected:
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
@@ -334,8 +374,8 @@ class ImplicitSizeSection : public Section<A>
 public:
                                                ImplicitSizeSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
                                                        : Section<A>(f, s) { }
 public:
                                                ImplicitSizeSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
                                                        : Section<A>(f, s) { }
-       virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFIInfoArray&);
-       virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFIInfoArray&);
+       virtual uint32_t        computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
+       virtual uint32_t        appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
 protected:
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
 protected:
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
@@ -437,7 +477,7 @@ protected:
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
 
        typedef typename A::P::uint_t   pint_t;
        typedef typename A::P                   P;
 
-       virtual void                                    makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray&);
+       virtual void                                    makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
        virtual ld::Atom::ContentType   contentType()                                                   { return ld::Atom::typeNonLazyPointer; }
        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 "non_lazy_ptr"; }
        virtual ld::Atom::ContentType   contentType()                                                   { return ld::Atom::typeNonLazyPointer; }
        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 "non_lazy_ptr"; }
@@ -598,6 +638,7 @@ protected:
        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 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                                    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; }
        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; }
@@ -668,6 +709,7 @@ public:
                        File<A>&                                                        machofile() const                       { return ((Section<A>*)(this->_section))->file(); }
                        void                                                            setFixupsRange(uint32_t s, uint32_t c);
                        void                                                            setUnwindInfoRange(uint32_t s, uint32_t c);
                        File<A>&                                                        machofile() const                       { return ((Section<A>*)(this->_section))->file(); }
                        void                                                            setFixupsRange(uint32_t s, uint32_t c);
                        void                                                            setUnwindInfoRange(uint32_t s, uint32_t c);
+                       void                                                            extendUnwindInfoRange();
                        void                                                            setLineInfoRange(uint32_t s, uint32_t c);
                        bool                                                            roomForMoreLineInfoCount() { return (_lineInfoCount < ((1<<kLineInfoCountBits)-1)); }
                        void                                                            incrementLineInfoCount() { assert(roomForMoreLineInfoCount()); ++_lineInfoCount; }
                        void                                                            setLineInfoRange(uint32_t s, uint32_t c);
                        bool                                                            roomForMoreLineInfoCount() { return (_lineInfoCount < ((1<<kLineInfoCountBits)-1)); }
                        void                                                            incrementLineInfoCount() { assert(roomForMoreLineInfoCount()); ++_lineInfoCount; }
@@ -758,6 +800,14 @@ void Atom<A>::setUnwindInfoRange(uint32_t startIndex, uint32_t count)
        _unwindInfoCount = count; 
 }
 
        _unwindInfoCount = count; 
 }
 
+template <typename A>
+void Atom<A>::extendUnwindInfoRange()
+{
+       if ( _unwindInfoCount+1 >= (1 << kUnwindInfoCountBits) ) 
+               throwf("too many compact unwind infos in function %s", this->name());
+       _unwindInfoCount += 1;
+}
+
 template <typename A>
 void Atom<A>::setLineInfoRange(uint32_t startIndex, uint32_t count)
 { 
 template <typename A>
 void Atom<A>::setLineInfoRange(uint32_t startIndex, uint32_t count)
 { 
@@ -792,8 +842,8 @@ template <>
 void Atom<arm>::verifyAlignment() const
 {
        if ( (this->section().type() == ld::Section::typeCode) && ! isThumb() ) {
 void Atom<arm>::verifyAlignment() const
 {
        if ( (this->section().type() == ld::Section::typeCode) && ! isThumb() ) {
-               if ( (_objAddress % 4) != 0 )
-                       warning("ARM function %s not 4-byte aligned", this->name());
+               if ( ((_objAddress % 4) != 0) || (this->alignment().powerOf2 < 2) )
+                       warning("ARM function not 4-byte aligned: %s from %s", this->name(), this->file()->path());
        }
 }
 
        }
 }
 
@@ -951,14 +1001,19 @@ public:
                uint32_t                                        symIndex;
        };
 
                uint32_t                                        symIndex;
        };
 
-       struct CFIInfoArray {
+       struct CFI_CU_InfoArrays {
                        typedef typename CFISection<A>::CFI_Atom_Info CFI_Atom_Info;
                        typedef typename CFISection<A>::CFI_Atom_Info CFI_Atom_Info;
-                                                       CFIInfoArray(const CFI_Atom_Info* cfia, uint32_t cfiac) : array(cfia), count(cfiac) {} 
-               const CFI_Atom_Info* const      array;
-               const uint32_t                          count;
+                       typedef typename CUSection<A>::Info CU_Info;
+                                               CFI_CU_InfoArrays(const CFI_Atom_Info* cfiAr, uint32_t cfiC, CU_Info* cuAr, uint32_t cuC) 
+                                                       : cfiArray(cfiAr), cuArray(cuAr), cfiCount(cfiC), cuCount(cuC) {} 
+               const CFI_Atom_Info* const      cfiArray;
+                       CU_Info* const                  cuArray;
+               const uint32_t                          cfiCount;
+               const uint32_t                          cuCount;
        };
 
 
        };
 
 
+
 private:
        friend class Section<A>;
        
 private:
        friend class Section<A>;
        
@@ -966,7 +1021,8 @@ private:
                                                sectionTypeNonLazy, sectionTypeCFI, sectionTypeCString, sectionTypeCStringPointer, 
                                                sectionTypeUTF16Strings, sectionTypeCFString, sectionTypeObjC2ClassRefs, typeObjC2CategoryList,
                                                sectionTypeObjC1Classes, sectionTypeSymboled, sectionTypeObjC1ClassRefs,
                                                sectionTypeNonLazy, sectionTypeCFI, sectionTypeCString, sectionTypeCStringPointer, 
                                                sectionTypeUTF16Strings, sectionTypeCFString, sectionTypeObjC2ClassRefs, typeObjC2CategoryList,
                                                sectionTypeObjC1Classes, sectionTypeSymboled, sectionTypeObjC1ClassRefs,
-                                               sectionTypeTentativeDefinitions, sectionTypeAbsoluteSymbols, sectionTypeTLVDefs };
+                                               sectionTypeTentativeDefinitions, sectionTypeAbsoluteSymbols, sectionTypeTLVDefs,
+                                               sectionTypeCompactUnwind };
 
        template <typename P>
        struct MachOSectionAndSectionClass
 
        template <typename P>
        struct MachOSectionAndSectionClass
@@ -986,6 +1042,9 @@ private:
                                return 1;
                }
        };
                                return 1;
                }
        };
+       
+       struct ParserAndSectionsArray { Parser* parser; const uint32_t* sortedSectionsArray; };
+       
 
                                                                                                        Parser(const uint8_t* fileContent, uint64_t fileLength, 
                                                                                                                        const char* path, time_t modTime, 
 
                                                                                                        Parser(const uint8_t* fileContent, uint64_t fileLength, 
                                                                                                                        const char* path, time_t modTime, 
@@ -994,11 +1053,13 @@ private:
        uint8_t                                                                                 loadCommandSizeMask();
        bool                                                                                    parseLoadCommands();
        void                                                                                    makeSections();
        uint8_t                                                                                 loadCommandSizeMask();
        bool                                                                                    parseLoadCommands();
        void                                                                                    makeSections();
-       void                                                                                    checkForLSDA();
        void                                                                                    prescanSymbolTable();
        void                                                                                    prescanSymbolTable();
-       void                                                                                    makeSortedSymbolsArray(uint32_t array[]);
+       void                                                                                    makeSortedSymbolsArray(uint32_t symArray[], const uint32_t sectionArray[]);
+       void                                                                                    makeSortedSectionsArray(uint32_t array[]);
        static int                                                                              pointerSorter(const void* l, const void* r);
        static int                                                                              symbolIndexSorter(void* extra, const void* l, const void* r);
        static int                                                                              pointerSorter(const void* l, const void* r);
        static int                                                                              symbolIndexSorter(void* extra, const void* l, const void* r);
+       static int                                                                              sectionIndexSorter(void* extra, const void* l, const void* r);
+
        void                                                                                    parseDebugInfo();
        void                                                                                    parseStabs();
        static bool                                                                             isConstFunStabs(const char *stabStr);
        void                                                                                    parseDebugInfo();
        void                                                                                    parseStabs();
        static bool                                                                             isConstFunStabs(const char *stabStr);
@@ -1032,9 +1093,8 @@ private:
        
        // filled in by parse()
        CFISection<A>*                                                          _EHFrameSection;
        
        // filled in by parse()
        CFISection<A>*                                                          _EHFrameSection;
+       CUSection<A>*                                                           _compactUnwindSection;
        AbsoluteSymbolSection<A>*                                       _absoluteSection;
        AbsoluteSymbolSection<A>*                                       _absoluteSection;
-       uint32_t                                                                        _lsdaTextSectionNum;
-       uint32_t                                                                        _lsdaDataSectionNum;
        uint32_t                                                                        _tentativeDefinitionCount;
        uint32_t                                                                        _absoluteSymbolCount;
        uint32_t                                                                        _symbolsInSections;
        uint32_t                                                                        _tentativeDefinitionCount;
        uint32_t                                                                        _absoluteSymbolCount;
        uint32_t                                                                        _symbolsInSections;
@@ -1059,8 +1119,7 @@ Parser<A>::Parser(const uint8_t* fileContent, uint64_t fileLength, const char* p
                        _indirectTable(NULL), _indirectTableCount(0), 
                        _undefinedStartIndex(0), _undefinedEndIndex(0), 
                        _sectionsStart(NULL), _machOSectionsCount(0), _hasUUID(false), 
                        _indirectTable(NULL), _indirectTableCount(0), 
                        _undefinedStartIndex(0), _undefinedEndIndex(0), 
                        _sectionsStart(NULL), _machOSectionsCount(0), _hasUUID(false), 
-                       _EHFrameSection(NULL), _absoluteSection(NULL),
-                       _lsdaTextSectionNum(0), _lsdaDataSectionNum(0),
+                       _EHFrameSection(NULL), _compactUnwindSection(NULL), _absoluteSection(NULL),
                        _tentativeDefinitionCount(0), _absoluteSymbolCount(0),
                        _symbolsInSections(0), _hasLongBranchStubs(false),  _AppleObjc(false),
                        _overlappingSymbols(false), _convertUnwindInfo(convertDUI), 
                        _tentativeDefinitionCount(0), _absoluteSymbolCount(0),
                        _symbolsInSections(0), _hasLongBranchStubs(false),  _AppleObjc(false),
                        _overlappingSymbols(false), _convertUnwindInfo(convertDUI), 
@@ -1068,31 +1127,6 @@ Parser<A>::Parser(const uint8_t* fileContent, uint64_t fileLength, const char* p
 {
 }
 
 {
 }
 
-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 <>
 bool Parser<x86>::validFile(const uint8_t* fileContent, bool, cpu_subtype_t)
@@ -1142,39 +1176,6 @@ bool Parser<arm>::validFile(const uint8_t* fileContent, bool subtypeMustMatch, c
 }
 
 
 }
 
 
-template <>
-const char* Parser<ppc>::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_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???";
-}
-
-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)
 
 template <>
 const char* Parser<x86>::fileKind(const uint8_t* fileContent)
@@ -1206,17 +1207,10 @@ const char* Parser<arm>::fileKind(const uint8_t* fileContent)
                return NULL;
        if ( header->cputype() != CPU_TYPE_ARM )
                return NULL;
                return NULL;
        if ( header->cputype() != CPU_TYPE_ARM )
                return NULL;
-       switch ( header->cpusubtype() ) {
-               case CPU_SUBTYPE_ARM_V4T:
-                       return "armv4t";
-               case CPU_SUBTYPE_ARM_V5TEJ:
-                       return "armv5";
-               case CPU_SUBTYPE_ARM_V6:
-                       return "armv6";
-               case CPU_SUBTYPE_ARM_V7:
-                       return "armv7";
-               case CPU_SUBTYPE_ARM_ALL:
-                       return "arm-ALL";
+       for (const ARMSubType* t=ARMSubTypes; t->subTypeName != NULL; ++t) {
+               if ( t->subType == (cpu_subtype_t)header->cpusubtype() ) {
+                       return t->subTypeName;
+               }
        }
        return "arm???";
 }
        }
        return "arm???";
 }
@@ -1302,7 +1296,8 @@ bool Parser<A>::LabelAndCFIBreakIterator::next(Parser<A>& parser, uint32_t sectN
                while ( symIndex < sortedSymbolCount ) {
                        const macho_nlist<P>& sym = parser.symbolFromIndex(sortedSymbolIndexes[symIndex]);
                        pint_t nextSymbolAddr = sym.n_value();
                while ( symIndex < sortedSymbolCount ) {
                        const macho_nlist<P>& sym = parser.symbolFromIndex(sortedSymbolIndexes[symIndex]);
                        pint_t nextSymbolAddr = sym.n_value();
-                       if ( (nextSymbolAddr >= startAddr) && (sym.n_sect() >= sectNum) )
+                       //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;
                }
                                break;
                        ++symIndex;
                }
@@ -1444,16 +1439,28 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
        if ( ! parseLoadCommands() )
                return _file;
        
        if ( ! parseLoadCommands() )
                return _file;
        
+       // make array of 
+       uint32_t sortedSectionIndexes[_machOSectionsCount];
+       this->makeSortedSectionsArray(sortedSectionIndexes);
+       
        // make symbol table sorted by address
        // make symbol table sorted by address
-       this->checkForLSDA();
        this->prescanSymbolTable();
        uint32_t sortedSymbolIndexes[_symbolsInSections];
        this->prescanSymbolTable();
        uint32_t sortedSymbolIndexes[_symbolsInSections];
-       this->makeSortedSymbolsArray(sortedSymbolIndexes);
+       this->makeSortedSymbolsArray(sortedSymbolIndexes, sortedSectionIndexes);
                
        // allocate Section<A> object for each mach-o section
        makeSections();
        
                
        // allocate Section<A> object for each mach-o section
        makeSections();
        
-       // if it exists, do special parsing of __eh_frame section 
+       // if it exists, do special early parsing of __compact_unwind section
+       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;
+       if ( countOfCUs != 0 )
+               _compactUnwindSection->parse(*this, countOfCUs, cuInfoArray);
+       
+       // if it exists, do special early parsing of __eh_frame section 
        // stack allocate array of CFI_Atom_Info
        uint32_t countOfCFIs = 0;
        if ( _EHFrameSection != NULL )
        // stack allocate array of CFI_Atom_Info
        uint32_t countOfCFIs = 0;
        if ( _EHFrameSection != NULL )
@@ -1489,7 +1496,7 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
                                ++cfiStartsCount;
                }
        }
                                ++cfiStartsCount;
                }
        }
-       CFIInfoArray cfis(cfiArray, countOfCFIs);
+       CFI_CU_InfoArrays cfis(cfiArray, countOfCFIs, cuInfoArray, countOfCUs);
        
        // create sorted array of function starts and lsda starts
        pint_t cfiStartsArray[cfiStartsCount];
        
        // create sorted array of function starts and lsda starts
        pint_t cfiStartsArray[cfiStartsCount];
@@ -1539,7 +1546,7 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
                uint8_t* atoms = _file->_atomsArray + _file->_atomsArrayCount*sizeof(Atom<A>);
                breakIterator2.beginSection();
                uint32_t count = sections[i]->appendAtoms(*this, atoms, breakIterator2, cfis);
                uint8_t* atoms = _file->_atomsArray + _file->_atomsArrayCount*sizeof(Atom<A>);
                breakIterator2.beginSection();
                uint32_t count = sections[i]->appendAtoms(*this, atoms, breakIterator2, cfis);
-               //fprintf(stderr, "append count=%u for section %s\n", count, sections[i]->machoSection()->sectname());
+               //fprintf(stderr, "append count=%u for section %s/%s\n", count, sections[i]->machoSection()->segname(), sections[i]->machoSection()->sectname());
                _file->_atomsArrayCount += count;
        }
        assert( _file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected");
                _file->_atomsArrayCount += count;
        }
        assert( _file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected");
@@ -1574,7 +1581,7 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
        _allFixups.clear();
 
        // add unwind info
        _allFixups.clear();
 
        // add unwind info
-       _file->_unwindInfos.reserve(countOfFDEs);
+       _file->_unwindInfos.reserve(countOfFDEs+countOfCUs);
        for(uint32_t i=0; i < countOfCFIs; ++i) {
                if ( cfiArray[i].isCIE )
                        continue;
        for(uint32_t i=0; i < countOfCFIs; ++i) {
                if ( cfiArray[i].isCIE )
                        continue;
@@ -1587,7 +1594,33 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
                        func->setUnwindInfoRange(_file->_unwindInfos.size()-1, 1);
                }
        }
                        func->setUnwindInfoRange(_file->_unwindInfos.size()-1, 1);
                }
        }
-
+       // apply compact infos in __LD,__compact_unwind section to each function
+       // if function also has dwarf unwind, CU will override it
+       Atom<A>* lastFunc = NULL;
+       uint32_t lastEnd = 0;
+       for(uint32_t i=0; i < countOfCUs; ++i) {
+               typename CUSection<A>::Info* info = &cuInfoArray[i];
+               assert(info->function != NULL);
+               ld::Atom::UnwindInfo ui;
+               ui.startOffset = info->functionStartAddress - info->function->objectAddress();
+               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);
+                       }
+                       lastFunc->extendUnwindInfoRange();
+               }
+               else 
+                       info->function->setUnwindInfoRange(_file->_unwindInfos.size()-1, 1);
+               lastFunc = info->function;
+               lastEnd = ui.startOffset + info->rangeLength;
+       }
+       
        // parse dwarf debug info to get line info
        this->parseDebugInfo();
 
        // parse dwarf debug info to get line info
        this->parseDebugInfo();
 
@@ -1596,8 +1629,6 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
 
 
 
 
 
 
-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<x86>::loadCommandSizeMask()         { return 0x03; }
 template <> uint8_t Parser<x86_64>::loadCommandSizeMask()      { return 0x07; }
 template <> uint8_t Parser<arm>::loadCommandSizeMask()         { return 0x03; }
@@ -1686,31 +1717,6 @@ bool Parser<A>::parseLoadCommands()
        return true;
 }
 
        return true;
 }
 
-template <>
-void Parser<arm>::checkForLSDA()
-{
-       // ARM has no FDEs, so need labels to break up section into atoms
-}
-
-template <typename A>
-void Parser<A>::checkForLSDA()
-{
-       // ignore labels on __gcc_except_tab section, we'll break it into atoms based on FDE info
-       for (uint32_t i=0; i < _machOSectionsCount; ++i) {
-               const macho_section<P>* sect = &_sectionsStart[i];
-               if ( strncmp(sect->sectname(), "__gcc_except_tab", 16) == 0 ) {
-                       if ( strcmp(sect->segname(), "__TEXT") == 0 ) {
-                               assert(_lsdaTextSectionNum == 0);
-                               _lsdaTextSectionNum = i+1;
-                       }
-                       else if ( strcmp(sect->segname(), "__DATA") == 0 ) {
-                               assert(_lsdaDataSectionNum == 0);
-                               _lsdaDataSectionNum = i+1;
-                       }
-               }
-       }
-}
-
 
 template <typename A>
 void Parser<A>::prescanSymbolTable()
 
 template <typename A>
 void Parser<A>::prescanSymbolTable()
@@ -1766,12 +1772,6 @@ void Parser<A>::prescanSymbolTable()
                if ( symbolName[0] == 'L' )
                        continue;
                
                if ( symbolName[0] == 'L' )
                        continue;
                
-               // ignore labels in __gcc_except_tab section
-               if ( (_lsdaTextSectionNum != 0) && (sym.n_sect() == _lsdaTextSectionNum) )
-                       continue;
-               if ( (_lsdaDataSectionNum != 0) && (sym.n_sect() == _lsdaDataSectionNum) )
-                       continue;
-               
                // how many def syms in each section
                if ( sym.n_sect() > _machOSectionsCount )
                        throw "bad n_sect in symbol table";
                // how many def syms in each section
                if ( sym.n_sect() > _machOSectionsCount )
                        throw "bad n_sect in symbol table";
@@ -1781,11 +1781,68 @@ void Parser<A>::prescanSymbolTable()
 }
 
 template <typename A>
 }
 
 template <typename A>
-int Parser<A>::symbolIndexSorter(void* extra, const void* l, const void* r)
+int Parser<A>::sectionIndexSorter(void* extra, const void* l, const void* r)
 {
        Parser<A>* parser = (Parser<A>*)extra;
        const uint32_t* left = (uint32_t*)l;
        const uint32_t* right = (uint32_t*)r;
 {
        Parser<A>* parser = (Parser<A>*)extra;
        const uint32_t* left = (uint32_t*)l;
        const uint32_t* right = (uint32_t*)r;
+       const macho_section<P>* leftSect =      parser->machOSectionFromSectionIndex(*left);
+       const macho_section<P>* rightSect = parser->machOSectionFromSectionIndex(*right);
+       
+       // can't just return difference because 64-bit diff does not fit in 32-bit return type
+       int64_t result = leftSect->addr() - rightSect->addr();
+       if ( result == 0 ) {
+               // two sections with same start address
+               // one with zero size goes first
+               bool leftEmpty = ( leftSect->size() == 0 );
+               bool rightEmpty = ( rightSect->size() == 0 );
+               if ( leftEmpty != rightEmpty ) {
+                       return ( rightEmpty ? 1 : -1 );
+               }
+               if ( !leftEmpty && !rightEmpty )
+                       throwf("overlapping sections");
+               // both empty, so chose file order
+               return ( rightSect - leftSect );
+       }
+       else if ( result < 0 )
+               return -1;
+       else
+               return 1;
+}
+
+template <typename A>
+void Parser<A>::makeSortedSectionsArray(uint32_t array[])
+{
+       const bool log = false;
+       
+       if ( log ) {
+               fprintf(stderr, "unsorted sections:\n");
+               for(unsigned int i=0; i < _machOSectionsCount; ++i ) 
+                       fprintf(stderr, "0x%08llX %s %s\n", _sectionsStart[i].addr(), _sectionsStart[i].segname(), _sectionsStart[i].sectname());
+       }
+       
+       // sort by symbol table address
+       for (uint32_t i=0; i < _machOSectionsCount; ++i)
+               array[i] = i;
+       ::qsort_r(array, _machOSectionsCount, sizeof(uint32_t), this, &sectionIndexSorter);
+
+       if ( log ) {
+               fprintf(stderr, "sorted sections:\n");
+               for(unsigned int i=0; i < _machOSectionsCount; ++i ) 
+                       fprintf(stderr, "0x%08llX %s %s\n", _sectionsStart[array[i]].addr(), _sectionsStart[array[i]].segname(), _sectionsStart[array[i]].sectname());
+       }
+}
+
+
+
+template <typename A>
+int Parser<A>::symbolIndexSorter(void* extra, const void* l, const void* r)
+{
+       ParserAndSectionsArray* extraInfo = (ParserAndSectionsArray*)extra;
+       Parser<A>* parser = extraInfo->parser;
+       const uint32_t* sortedSectionsArray = extraInfo->sortedSectionsArray;
+       const uint32_t* left = (uint32_t*)l;
+       const uint32_t* right = (uint32_t*)r;
        const macho_nlist<P>& leftSym = parser->symbolFromIndex(*left);
        const macho_nlist<P>& rightSym = parser->symbolFromIndex(*right);
        // can't just return difference because 64-bit diff does not fit in 32-bit return type
        const macho_nlist<P>& leftSym = parser->symbolFromIndex(*left);
        const macho_nlist<P>& rightSym = parser->symbolFromIndex(*right);
        // can't just return difference because 64-bit diff does not fit in 32-bit return type
@@ -1793,9 +1850,15 @@ int Parser<A>::symbolIndexSorter(void* extra, const void* l, const void* r)
        if ( result == 0 ) {
                // two symbols with same address
                // if in different sections, sort earlier section first
        if ( result == 0 ) {
                // two symbols with same address
                // if in different sections, sort earlier section first
-               if ( leftSym.n_sect() != rightSym.n_sect() )
-                       return (leftSym.n_sect() - rightSym.n_sect());
-               //, means one is an alias
+               if ( leftSym.n_sect() != rightSym.n_sect() ) {
+                       for (uint32_t i=0; i < parser->machOSectionCount(); ++i) {
+                               if ( sortedSectionsArray[i]+1 == leftSym.n_sect() )
+                                       return -1;
+                               if ( sortedSectionsArray[i]+1 == rightSym.n_sect() )
+                                       return 1;
+                       }
+               }
+               // two symbols in same section, means one is an alias
                // 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 )
                // 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 )
@@ -1812,9 +1875,12 @@ int Parser<A>::symbolIndexSorter(void* extra, const void* l, const void* r)
                return 1;
 }
 
                return 1;
 }
 
+
 template <typename A>
 template <typename A>
-void Parser<A>::makeSortedSymbolsArray(uint32_t array[])
+void Parser<A>::makeSortedSymbolsArray(uint32_t array[], const uint32_t sectionArray[])
 {
 {
+       const bool log = false;
+       
        uint32_t* p = array;
        for (uint32_t i=0; i < this->_symbolCount; ++i) {
                const macho_nlist<P>& sym =     symbolFromIndex(i);
        uint32_t* p = array;
        for (uint32_t i=0; i < this->_symbolCount; ++i) {
                const macho_nlist<P>& sym =     symbolFromIndex(i);
@@ -1831,12 +1897,6 @@ void Parser<A>::makeSortedSymbolsArray(uint32_t array[])
                if ( symbolName[0] == 'L' )
                        continue;
 
                if ( symbolName[0] == 'L' )
                        continue;
 
-               // ignore labels in __gcc_except_tab section
-               if ( (_lsdaTextSectionNum != 0) && (sym.n_sect() == _lsdaTextSectionNum) )
-                       continue;
-               if ( (_lsdaDataSectionNum != 0) && (sym.n_sect() == _lsdaDataSectionNum) )
-                       continue;
-               
                // how many def syms in each section
                if ( sym.n_sect() > _machOSectionsCount )
                        throw "bad n_sect in symbol table";
                // how many def syms in each section
                if ( sym.n_sect() > _machOSectionsCount )
                        throw "bad n_sect in symbol table";
@@ -1847,7 +1907,8 @@ void Parser<A>::makeSortedSymbolsArray(uint32_t array[])
        assert(p == &array[_symbolsInSections] && "second pass over symbol table yield a different number of symbols");
        
        // sort by symbol table address
        assert(p == &array[_symbolsInSections] && "second pass over symbol table yield a different number of symbols");
        
        // sort by symbol table address
-       ::qsort_r(array, _symbolsInSections, sizeof(uint32_t), this, &symbolIndexSorter);
+       ParserAndSectionsArray extra = { this, sectionArray };
+       ::qsort_r(array, _symbolsInSections, sizeof(uint32_t), &extra, &symbolIndexSorter);
        
        // look for two symbols at same address
        _overlappingSymbols = false;
        
        // look for two symbols at same address
        _overlappingSymbols = false;
@@ -1858,9 +1919,11 @@ void Parser<A>::makeSortedSymbolsArray(uint32_t array[])
                }
        }
 
                }
        }
 
-       //fprintf(stderr, "sorted symbols:\n");
-       //for(unsigned int i=0; i < _symbolsInSections; ++i ) 
-       //      fprintf(stderr, "0x%09llX symIndex=%3d sectNum=%2d, %s\n", symbolFromIndex(array[i]).n_value(), array[i], symbolFromIndex(array[i]).n_sect(), nameFromSymbol(symbolFromIndex(array[i])) );
+       if ( log ) {
+               fprintf(stderr, "sorted symbols:\n");
+               for(unsigned int i=0; i < _symbolsInSections; ++i ) 
+                       fprintf(stderr, "0x%09llX symIndex=%d sectNum=%2d, %s\n", symbolFromIndex(array[i]).n_value(), array[i], symbolFromIndex(array[i]).n_sect(), nameFromSymbol(symbolFromIndex(array[i])) );
+       }
 }
 
 
 }
 
 
@@ -1876,21 +1939,30 @@ void Parser<A>::makeSections()
        unsigned int count = 0;
        for (uint32_t i=0; i < _machOSectionsCount; ++i) {
                const macho_section<P>* sect = &_sectionsStart[i];
        unsigned int count = 0;
        for (uint32_t i=0; i < _machOSectionsCount; ++i) {
                const macho_section<P>* sect = &_sectionsStart[i];
-               // ignore dwarf sections
                if ( (sect->flags() & S_ATTR_DEBUG) != 0 ) {
                if ( (sect->flags() & S_ATTR_DEBUG) != 0 ) {
-                       // note that .o file has dwarf
-                       _file->_debugInfoKind = ld::relocatable::File::kDebugInfoDwarf;
-                       // save off iteresting dwarf sections
-                       if ( strcmp(sect->sectname(), "__debug_info") == 0 )
-                               _file->_dwarfDebugInfoSect = sect;
-                       else if ( strcmp(sect->sectname(), "__debug_abbrev") == 0 )
-                               _file->_dwarfDebugAbbrevSect = sect;
-                       else if ( strcmp(sect->sectname(), "__debug_line") == 0 )
-                               _file->_dwarfDebugLineSect = sect;
-                       else if ( strcmp(sect->sectname(), "__debug_str") == 0 )
-                               _file->_dwarfDebugStringSect = sect;
-                       // linker does not propagate dwarf sections to output file
-                       continue;
+                       if ( strcmp(sect->segname(), "__DWARF") == 0 ) {
+                               // note that .o file has dwarf
+                               _file->_debugInfoKind = ld::relocatable::File::kDebugInfoDwarf;
+                               // save off iteresting dwarf sections
+                               if ( strcmp(sect->sectname(), "__debug_info") == 0 )
+                                       _file->_dwarfDebugInfoSect = sect;
+                               else if ( strcmp(sect->sectname(), "__debug_abbrev") == 0 )
+                                       _file->_dwarfDebugAbbrevSect = sect;
+                               else if ( strcmp(sect->sectname(), "__debug_line") == 0 )
+                                       _file->_dwarfDebugLineSect = sect;
+                               else if ( strcmp(sect->sectname(), "__debug_str") == 0 )
+                                       _file->_dwarfDebugStringSect = sect;
+                               // linker does not propagate dwarf sections to output file
+                               continue;
+                       }
+                       else if ( strcmp(sect->segname(), "__LD") == 0 ) {
+                               if ( strncmp(sect->sectname(), "__compact_unwind", 16) == 0 ) {
+                                       machOSects[count].sect = sect;
+                                       totalSectionsSize += sizeof(CUSection<A>);
+                                       machOSects[count++].type = sectionTypeCompactUnwind;
+                                       continue;
+                               }
+                       }
                }
                // ignore empty __OBJC sections
                if ( (sect->size() == 0) && (strcmp(sect->segname(), "__OBJC") == 0) )
                }
                // ignore empty __OBJC sections
                if ( (sect->size() == 0) && (strcmp(sect->segname(), "__OBJC") == 0) )
@@ -1918,11 +1990,11 @@ void Parser<A>::makeSections()
                                        _file->_ojcReplacmentClass = true;
                                if ( sect->size() > 8 ) {
                                        warning("section %s/%s has unexpectedly large size %llu in %s", 
                                        _file->_ojcReplacmentClass = true;
                                if ( sect->size() > 8 ) {
                                        warning("section %s/%s has unexpectedly large size %llu in %s", 
-                                                       sect->segname(), sect->sectname(), sect->size(), _file->path());
+                                                       sect->segname(), Section<A>::makeSectionName(sect), sect->size(), _file->path());
                                }
                        }
                        else {
                                }
                        }
                        else {
-                               warning("can't parse %s/%s section in %s", sect->segname(), sect->sectname(), _file->path());
+                               warning("can't parse %s/%s section in %s", sect->segname(), Section<A>::makeSectionName(sect), _file->path());
                        }
                        continue;
                }
                        }
                        continue;
                }
@@ -2101,6 +2173,11 @@ void Parser<A>::makeSections()
                                *objects++ = new (space) TLVDefsSection<A>(*this, *_file, machOSects[i].sect);
                                space += sizeof(TLVDefsSection<A>);
                                break;
                                *objects++ = new (space) TLVDefsSection<A>(*this, *_file, machOSects[i].sect);
                                space += sizeof(TLVDefsSection<A>);
                                break;
+                       case sectionTypeCompactUnwind:
+                               _compactUnwindSection = new (space) CUSection<A>(*this, *_file, machOSects[i].sect);
+                               *objects++ = _compactUnwindSection;
+                               space += sizeof(CUSection<A>);
+                               break;
                        case sectionTypeTentativeDefinitions:
                                *objects++ = new (space) TentativeDefinitionSection<A>(*this, *_file);
                                space += sizeof(TentativeDefinitionSection<A>);
                        case sectionTypeTentativeDefinitions:
                                *objects++ = new (space) TentativeDefinitionSection<A>(*this, *_file);
                                space += sizeof(TentativeDefinitionSection<A>);
@@ -2386,9 +2463,6 @@ void Parser<A>::addFixups(const SourceLocation& src, ld::Fixup::Kind setKind, co
                        case ld::Fixup::kindStoreThumbBranch22:
                                firstKind = ld::Fixup::kindStoreTargetAddressThumbBranch22;
                                break;
                        case ld::Fixup::kindStoreThumbBranch22:
                                firstKind = ld::Fixup::kindStoreTargetAddressThumbBranch22;
                                break;
-                       case ld::Fixup::kindStorePPCBranch24:
-                               firstKind = ld::Fixup::kindStoreTargetAddressPPCBranch24;
-                               break;
                        default:
                                combined = false;
                                cl = ld::Fixup::k1of2;
                        default:
                                combined = false;
                                cl = ld::Fixup::k1of2;
@@ -2462,7 +2536,7 @@ void Parser<A>::addFixups(const SourceLocation& src, ld::Fixup::Kind kind, const
 template <typename A>
 uint32_t TentativeDefinitionSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t TentativeDefinitionSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                                                       const struct Parser<A>::CFIInfoArray&)
+                                                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        return parser.tentativeDefinitionCount();
 }
 {
        return parser.tentativeDefinitionCount();
 }
@@ -2470,7 +2544,7 @@ uint32_t TentativeDefinitionSection<A>::computeAtomCount(class Parser<A>& parser
 template <typename A>
 uint32_t TentativeDefinitionSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t TentativeDefinitionSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                                               const struct Parser<A>::CFIInfoArray&)
+                                                                                                               const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        this->_beginAtoms = (Atom<A>*)p;
        uint32_t count = 0;
 {
        this->_beginAtoms = (Atom<A>*)p;
        uint32_t count = 0;
@@ -2489,8 +2563,8 @@ uint32_t TentativeDefinitionSection<A>::appendAtoms(class Parser<A>& parser, uin
                                        ++alignP2;
                        }
                        // limit alignment of extremely large commons to 2^15 bytes (8-page)
                                        ++alignP2;
                        }
                        // limit alignment of extremely large commons to 2^15 bytes (8-page)
-                       if ( alignP2 > 12 )
-                               alignP2 = 12;
+                       if ( alignP2 > 15 )
+                               alignP2 = 15;
                        Atom<A>* allocatedSpace = (Atom<A>*)p;
                        new (allocatedSpace) Atom<A>(*this, parser.nameFromSymbol(sym), (pint_t)ULLONG_MAX, size,
                                                                                ld::Atom::definitionTentative,  ld::Atom::combineByName, 
                        Atom<A>* allocatedSpace = (Atom<A>*)p;
                        new (allocatedSpace) Atom<A>(*this, parser.nameFromSymbol(sym), (pint_t)ULLONG_MAX, size,
                                                                                ld::Atom::definitionTentative,  ld::Atom::combineByName, 
@@ -2508,7 +2582,7 @@ uint32_t TentativeDefinitionSection<A>::appendAtoms(class Parser<A>& parser, uin
 template <typename A>
 uint32_t AbsoluteSymbolSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t AbsoluteSymbolSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                                                       const struct Parser<A>::CFIInfoArray&)
+                                                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        return parser.absoluteSymbolCount();
 }
 {
        return parser.absoluteSymbolCount();
 }
@@ -2516,7 +2590,7 @@ uint32_t AbsoluteSymbolSection<A>::computeAtomCount(class Parser<A>& parser,
 template <typename A>
 uint32_t AbsoluteSymbolSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t AbsoluteSymbolSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                                               const struct Parser<A>::CFIInfoArray&)
+                                                                                                               const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        this->_beginAtoms = (Atom<A>*)p;
        uint32_t count = 0;
 {
        this->_beginAtoms = (Atom<A>*)p;
        uint32_t count = 0;
@@ -3488,6 +3562,8 @@ ld::Section::Type Section<A>::sectionType(const macho_section<typename A::P>* se
                                        return ld::Section::typeCode;
                                else if ( strcmp(sect->sectname(), "__StaticInit") == 0 )
                                        return ld::Section::typeCode;
                                        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 ) 
                        }
                        else if ( strcmp(sect->segname(), "__DATA") == 0 ) {
                                if ( strcmp(sect->sectname(), "__cfstring") == 0 ) 
@@ -3567,8 +3643,6 @@ uint32_t Section<A>::sectionNum(class Parser<A>& parser) const
                return 1 + (this->_machOSection - parser.firstMachOSection());
 }
 
                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; }
 
 // arm does not have zero cost exceptions
 template <> uint32_t CFISection<arm>::cfiCount() { return 0; }
 
@@ -3689,32 +3763,7 @@ void CFISection<x86>::cfiParse(class Parser<x86>& parser, uint8_t* buffer,
 }
 
 
 }
 
 
-// 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)
-{
-       // 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(
-                                                       oas, this->_machOSection->addr(), this->_machOSection->size(), 
-                                                       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, 
 
 template <>
 void CFISection<arm>::cfiParse(class Parser<arm>& parser, uint8_t* buffer, 
@@ -3730,9 +3779,9 @@ void CFISection<arm>::cfiParse(class Parser<arm>& parser, uint8_t* buffer,
 template <typename A>
 uint32_t CFISection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t CFISection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                       const struct Parser<A>::CFIInfoArray& cfis)
+                                                                                       const struct Parser<A>::CFI_CU_InfoArrays& cfis)
 {
 {
-       return cfis.count;
+       return cfis.cfiCount;
 }
 
 
 }
 
 
@@ -3740,12 +3789,12 @@ uint32_t CFISection<A>::computeAtomCount(class Parser<A>& parser,
 template <typename A>
 uint32_t CFISection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t CFISection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                       const struct Parser<A>::CFIInfoArray& cfis)
+                                                                       const struct Parser<A>::CFI_CU_InfoArrays& cfis)
 {
        this->_beginAtoms = (Atom<A>*)p;
        // walk CFI_Atom_Info array and create atom for each entry
 {
        this->_beginAtoms = (Atom<A>*)p;
        // walk CFI_Atom_Info array and create atom for each entry
-       const CFI_Atom_Info* start = &cfis.array[0];
-       const CFI_Atom_Info* end   = &cfis.array[cfis.count];
+       const CFI_Atom_Info* start = &cfis.cfiArray[0];
+       const CFI_Atom_Info* end   = &cfis.cfiArray[cfis.cfiCount];
        for(const CFI_Atom_Info* a=start; a < end; ++a) {
                Atom<A>* space = (Atom<A>*)p;
                new (space) Atom<A>(*this, (a->isCIE ? "CIE" : "FDE"), a->address, a->size, 
        for(const CFI_Atom_Info* a=start; a < end; ++a) {
                Atom<A>* space = (Atom<A>*)p;
                new (space) Atom<A>(*this, (a->isCIE ? "CIE" : "FDE"), a->address, a->size, 
@@ -3755,15 +3804,13 @@ uint32_t CFISection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p,
                p += sizeof(Atom<A>);
        }
        this->_endAtoms = (Atom<A>*)p;
                p += sizeof(Atom<A>);
        }
        this->_endAtoms = (Atom<A>*)p;
-       return cfis.count;
+       return cfis.cfiCount;
 }
 
 
 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<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 <>
 
 
 template <>
@@ -3813,30 +3860,6 @@ void CFISection<x86>::addCiePersonalityFixups(class Parser<x86>& parser, const C
 }
 
 
 }
 
 
-template <>
-void CFISection<ppc>::addCiePersonalityFixups(class Parser<ppc>& 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);
-               assert(nlpAtom->contentType() == ld::Atom::typeNonLazyPointer);
-               Parser<ppc>::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);
-       }
-       else if ( personalityEncoding != 0 ) {
-               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)
 {
 template <typename A>
 void CFISection<A>::addCiePersonalityFixups(class Parser<A>& parser, const CFI_Atom_Info* cieInfo)
 {
@@ -3845,14 +3868,14 @@ void CFISection<A>::addCiePersonalityFixups(class Parser<A>& parser, const CFI_A
 }
 
 template <typename A>
 }
 
 template <typename A>
-void CFISection<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray& cfis)
+void CFISection<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays& cfis)
 {
        ld::Fixup::Kind store32 = bigEndian() ? ld::Fixup::kindStoreBigEndian32 : ld::Fixup::kindStoreLittleEndian32;
        ld::Fixup::Kind store64 = bigEndian() ? ld::Fixup::kindStoreBigEndian64 : ld::Fixup::kindStoreLittleEndian64;
 
        // add all references for FDEs, including implicit group references
 {
        ld::Fixup::Kind store32 = bigEndian() ? ld::Fixup::kindStoreBigEndian32 : ld::Fixup::kindStoreLittleEndian32;
        ld::Fixup::Kind store64 = bigEndian() ? ld::Fixup::kindStoreBigEndian64 : ld::Fixup::kindStoreLittleEndian64;
 
        // add all references for FDEs, including implicit group references
-       const CFI_Atom_Info* end = &cfis.array[cfis.count];
-       for(const CFI_Atom_Info* p = &cfis.array[0]; p < end; ++p) {
+       const CFI_Atom_Info* end = &cfis.cfiArray[cfis.cfiCount];
+       for(const CFI_Atom_Info* p = &cfis.cfiArray[0]; p < end; ++p) {
                if ( p->isCIE ) {
                        // add reference to personality function if used
                        if ( p->u.cieInfo.personality.targetAddress != CFI_INVALID_ADDRESS ) {
                if ( p->isCIE ) {
                        // add reference to personality function if used
                        if ( p->u.cieInfo.personality.targetAddress != CFI_INVALID_ADDRESS ) {
@@ -4072,6 +4095,136 @@ typename A::P::uint_t CFISection<A>::OAS::getEncodedP(pint_t& addr, pint_t end,
        return result;
 }
 
        return result;
 }
 
+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);
+}
+
+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);
+}
+
+template <typename A>
+const char* CUSection<A>::personalityName(class Parser<A>& parser, const macho_relocation_info<P>* reloc)
+{
+       return NULL;
+}
+
+
+template <typename A>
+int CUSection<A>::infoSorter(const void* l, const void* r)
+{
+       // sort references by symbol index, then address 
+       const Info* left = (Info*)l;
+       const Info* right = (Info*)r;
+       if ( left->functionSymbolIndex == right->functionSymbolIndex )
+               return (left->functionStartAddress - right->functionStartAddress);
+       else
+               return (left->functionSymbolIndex - right->functionSymbolIndex);
+}
+
+template <typename A>
+void CUSection<A>::parse(class Parser<A>& parser, uint32_t cnt, Info array[])
+{
+       // walk section content and copy to Info array
+       const macho_compact_unwind_entry<P>* const entries = (macho_compact_unwind_entry<P>*)(this->file().fileContent() + this->_machOSection->offset());
+       for (uint32_t i=0; i < cnt; ++i) {
+               Info* info = &array[i];
+               const macho_compact_unwind_entry<P>* entry = &entries[i];
+               info->functionStartAddress      = entry->codeStart();
+               info->functionSymbolIndex   = 0xFFFFFFFF;
+               info->rangeLength                       = entry->codeLen();
+               info->compactUnwindInfo         = entry->compactUnwindInfo();
+               info->personality                       = NULL;
+               info->lsdaAddress                       = entry->lsda();
+               info->function                          = NULL;
+               info->lsda                                      = NULL;
+               if ( (info->compactUnwindInfo & UNWIND_PERSONALITY_MASK) != 0 )
+                       warning("no bits should be set in UNWIND_PERSONALITY_MASK of compact unwind encoding in __LD,__compact_unwind section");
+               if ( info->lsdaAddress != 0 ) {
+                       info->compactUnwindInfo |= UNWIND_HAS_LSDA;
+               }
+       }
+       
+       // scan relocs, local relocs are useless - ignore them
+       // 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) {
+               if ( reloc->r_extern() ) {
+                       // only expect external relocs on some colummns
+                       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);
+                       }
+                       else if ( (reloc->r_address() % sizeof(macho_compact_unwind_entry<P>)) == macho_compact_unwind_entry<P>::lsdaFieldOffset() ) {
+                               uint32_t entryIndex = reloc->r_address() / sizeof(macho_compact_unwind_entry<P>);
+                               const macho_nlist<P>& lsdaSym = parser.symbolFromIndex(reloc->r_symbolnum());
+                               if ( (lsdaSym.n_type() & N_TYPE) == N_SECT ) 
+                                       array[entryIndex].lsdaAddress = lsdaSym.n_value();
+                               else
+                                       warning("unexpected extern relocation to lsda in __compact_unwind section");
+                       }
+                       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();
+                       }
+                       else {
+                               warning("unexpected extern relocation in __compact_unwind section");
+                       }
+               }
+       }
+       
+       // sort array by function start address so unwind infos will be contiguous for a given function
+       ::qsort(array, cnt, sizeof(Info), infoSorter);
+}
+
+template <typename A>
+uint32_t CUSection<A>::count()
+{
+       const macho_section<P>* machoSect =     this->machoSection();
+       if ( (machoSect->size() % sizeof(macho_compact_unwind_entry<P>)) != 0 )
+               throw "malformed __LD,__compact_unwind section, bad length";
+               
+       return machoSect->size() / sizeof(macho_compact_unwind_entry<P>);
+}
+
+template <typename A>
+void CUSection<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays& cus)
+{
+       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
+               if ( info->lsdaAddress != 0 ) {
+                       info->lsda = parser.findAtomByAddress(info->lsdaAddress);               
+                       // add lsda subordinate
+                       typename Parser<A>::SourceLocation src(info->function, info->functionStartAddress - info->function->objectAddress());
+                       parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindNoneGroupSubordinateLSDA, info->lsda);
+               }
+               if ( info->personality != NULL ) {
+                       // add personality subordinate
+                       typename Parser<A>::SourceLocation src(info->function, info->functionStartAddress - info->function->objectAddress());
+                       parser.addFixup(src, ld::Fixup::k1of1, ld::Fixup::kindNoneGroupSubordinatePersonality, false, info->personality);
+               }
+       }
+       
+}
+
 template <typename A>
 SymboledSection<A>::SymboledSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
        : Section<A>(f, s), _type(ld::Atom::typeUnclassified) 
 template <typename A>
 SymboledSection<A>::SymboledSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
        : Section<A>(f, s), _type(ld::Atom::typeUnclassified) 
@@ -4101,6 +4254,8 @@ SymboledSection<A>::SymboledSection(Parser<A>& parser, File<A>& f, const macho_s
                case S_REGULAR:
                        if ( strncmp(s->sectname(), "__gcc_except_tab", 16) == 0 )
                                _type = ld::Atom::typeLSDA;
                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;
        }
 }
                        break;
        }
 }
@@ -4127,7 +4282,7 @@ bool SymboledSection<A>::dontDeadStrip()
 template <typename A>
 uint32_t SymboledSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t SymboledSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                               const struct Parser<A>::CFIInfoArray&)
+                                                                                               const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        const pint_t startAddr = this->_machOSection->addr();
        const pint_t endAddr = startAddr + this->_machOSection->size();
 {
        const pint_t startAddr = this->_machOSection->addr();
        const pint_t endAddr = startAddr + this->_machOSection->size();
@@ -4147,7 +4302,7 @@ uint32_t SymboledSection<A>::computeAtomCount(class Parser<A>& parser,
 template <typename A>
 uint32_t SymboledSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t SymboledSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                       const struct Parser<A>::CFIInfoArray&)
+                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        this->_beginAtoms = (Atom<A>*)p;
 
 {
        this->_beginAtoms = (Atom<A>*)p;
 
@@ -4173,8 +4328,12 @@ uint32_t SymboledSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p,
                                this->_hasAliases = true;
                }
                else {
                                this->_hasAliases = true;
                }
                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, this->contentType(), ld::Atom::symbolTableNotIn, 
+                                                                               ld::Atom::scopeTranslationUnit, ctype, inclusion, 
                                                                                this->dontDeadStrip(), false, false, this->alignmentForAddress(addr));
                }
                p += sizeof(Atom<A>);
                                                                                this->dontDeadStrip(), false, false, this->alignmentForAddress(addr));
                }
                p += sizeof(Atom<A>);
@@ -4189,7 +4348,7 @@ uint32_t SymboledSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p,
 template <typename A>
 uint32_t ImplicitSizeSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t ImplicitSizeSection<A>::computeAtomCount(class Parser<A>& parser, 
                                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                                       const struct Parser<A>::CFIInfoArray&)
+                                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        uint32_t count = 0;
        const macho_section<P>* sect = this->machoSection();
 {
        uint32_t count = 0;
        const macho_section<P>* sect = this->machoSection();
@@ -4220,7 +4379,7 @@ uint32_t ImplicitSizeSection<A>::computeAtomCount(class Parser<A>& parser,
 template <typename A>
 uint32_t ImplicitSizeSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
 template <typename A>
 uint32_t ImplicitSizeSection<A>::appendAtoms(class Parser<A>& parser, uint8_t* p, 
                                                                                        struct Parser<A>::LabelAndCFIBreakIterator& it, 
-                                                                                       const struct Parser<A>::CFIInfoArray&)
+                                                                                       const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        this->_beginAtoms = (Atom<A>*)p;
        
 {
        this->_beginAtoms = (Atom<A>*)p;
        
@@ -4382,6 +4541,12 @@ bool CStringSection<A>::useElementAt(Parser<A>& parser, struct Parser<A>::LabelA
        return true;
 }
 
        return true;
 }
 
+template <typename A>
+bool CStringSection<A>::ignoreLabel(const char* label)  
+{ 
+       return (label[0] == 'L') || (label[0] == 'l'); 
+}
+
 template <typename A>
 Atom<A>* CStringSection<A>::findAtomByAddress(pint_t addr)
 {
 template <typename A>
 Atom<A>* CStringSection<A>::findAtomByAddress(pint_t addr)
 {
@@ -4436,26 +4601,15 @@ ld::Fixup::Kind NonLazyPointerSection<arm>::fixupKind()
        return ld::Fixup::kindStoreLittleEndian32;
 }
 
        return ld::Fixup::kindStoreLittleEndian32;
 }
 
-template <>
-ld::Fixup::Kind NonLazyPointerSection<ppc>::fixupKind()
-{
-       return ld::Fixup::kindStoreBigEndian32;
-}
-
-template <>
-ld::Fixup::Kind NonLazyPointerSection<ppc64>::fixupKind()
-{
-       return ld::Fixup::kindStoreBigEndian64;
-}
 
 template <>
 
 template <>
-void NonLazyPointerSection<x86_64>::makeFixups(class Parser<x86_64>& parser, const struct Parser<x86_64>::CFIInfoArray&)
+void NonLazyPointerSection<x86_64>::makeFixups(class Parser<x86_64>& parser, const struct Parser<x86_64>::CFI_CU_InfoArrays&)
 {
        assert(0 && "x86_64 should not have non-lazy-pointer sections in .o files");
 }
 
 template <typename A>
 {
        assert(0 && "x86_64 should not have non-lazy-pointer sections in .o files");
 }
 
 template <typename A>
-void NonLazyPointerSection<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray&)
+void NonLazyPointerSection<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        // add references for each NLP atom based on indirect symbol table
        const macho_section<P>* sect = this->machoSection();
 {
        // add references for each NLP atom based on indirect symbol table
        const macho_section<P>* sect = this->machoSection();
@@ -5192,7 +5346,7 @@ bool Section<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocati
                                const macho_nlist<P>& targetSymbol = parser.symbolFromIndex(reloc->r_symbolnum());
                                target.name = parser.nameFromSymbol(targetSymbol);
                                target.weakImport = parser.weakImportFromSymbol(targetSymbol);
                                const macho_nlist<P>& targetSymbol = parser.symbolFromIndex(reloc->r_symbolnum());
                                target.name = parser.nameFromSymbol(targetSymbol);
                                target.weakImport = parser.weakImportFromSymbol(targetSymbol);
-                               target.addend = contentValue;
+                               target.addend = (int32_t)contentValue;
                        }
                        else {
                                parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), target);
                        }
                        else {
                                parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), target);
@@ -5247,6 +5401,7 @@ bool Section<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocati
                const macho_scattered_relocation_info<P>* sreloc = (macho_scattered_relocation_info<P>*)reloc;
                srcAddr = sect->addr() + sreloc->r_address();
                src.atom = this->findAtomByAddress(srcAddr);
                const macho_scattered_relocation_info<P>* sreloc = (macho_scattered_relocation_info<P>*)reloc;
                srcAddr = sect->addr() + sreloc->r_address();
                src.atom = this->findAtomByAddress(srcAddr);
+               assert(src.atom != NULL);
                src.offsetInAtom = srcAddr - src.atom->_objAddress;
                fixUpPtr = file().fileContent() + sect->offset() + sreloc->r_address();
                uint32_t relocValue = sreloc->r_value();
                src.offsetInAtom = srcAddr - src.atom->_objAddress;
                fixUpPtr = file().fileContent() + sect->offset() + sreloc->r_address();
                uint32_t relocValue = sreloc->r_value();
@@ -5279,17 +5434,17 @@ bool Section<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocati
                                        switch ( sreloc->r_length() ) {
                                                case 0:
                                                        contentValue = srcAddr + 1 + *fixUpPtr;
                                        switch ( sreloc->r_length() ) {
                                                case 0:
                                                        contentValue = srcAddr + 1 + *fixUpPtr;
-                                                       target.addend = contentValue - relocValue;
+                                                       target.addend = (int32_t)contentValue - (int32_t)relocValue;
                                                        parser.addFixups(src, ld::Fixup::kindStoreX86PCRel8, target);
                                                        break;
                                                case 1:
                                                        contentValue = srcAddr + 2 + LittleEndian::get16(*((uint16_t*)fixUpPtr));
                                                        parser.addFixups(src, ld::Fixup::kindStoreX86PCRel8, target);
                                                        break;
                                                case 1:
                                                        contentValue = srcAddr + 2 + LittleEndian::get16(*((uint16_t*)fixUpPtr));
-                                                       target.addend = contentValue - relocValue;
+                                                       target.addend = (int32_t)contentValue - (int32_t)relocValue;
                                                        parser.addFixups(src, ld::Fixup::kindStoreX86PCRel16, target);
                                                        break;
                                                case 2:
                                                        contentValue = srcAddr + 4 + LittleEndian::get32(*((uint32_t*)fixUpPtr));
                                                        parser.addFixups(src, ld::Fixup::kindStoreX86PCRel16, target);
                                                        break;
                                                case 2:
                                                        contentValue = srcAddr + 4 + LittleEndian::get32(*((uint32_t*)fixUpPtr));
-                                                       target.addend = contentValue - relocValue;
+                                                       target.addend = (int32_t)contentValue - (int32_t)relocValue;
                                                        parser.addFixups(src, ld::Fixup::kindStoreX86PCRel32, target);
                                                        break;
                                                case 3:
                                                        parser.addFixups(src, ld::Fixup::kindStoreX86PCRel32, target);
                                                        break;
                                                case 3:
@@ -5301,7 +5456,7 @@ bool Section<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocati
                                        if ( sreloc->r_length() != 2 )
                                                throwf("unsupported r_length=%d for scattered vanilla reloc", sreloc->r_length());
                                        contentValue = LittleEndian::get32(*((uint32_t*)fixUpPtr));
                                        if ( sreloc->r_length() != 2 )
                                                throwf("unsupported r_length=%d for scattered vanilla reloc", sreloc->r_length());
                                        contentValue = LittleEndian::get32(*((uint32_t*)fixUpPtr));
-                                       target.addend = contentValue - target.atom->objectAddress();
+                                       target.addend = (int32_t)contentValue - (int32_t)(target.atom->objectAddress());
                                        parser.addFixups(src, ld::Fixup::kindStoreLittleEndian32, target);
                                }
                                break;
                                        parser.addFixups(src, ld::Fixup::kindStoreLittleEndian32, target);
                                }
                                break;
@@ -5327,7 +5482,7 @@ bool Section<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocati
                                        uint32_t offsetInFrom = nextRelocValue - fromAtom->_objAddress;
                                        parser.findTargetFromAddress(sreloc->r_value(), target);
                                        // check for addend encoded in the section content
                                        uint32_t offsetInFrom = nextRelocValue - fromAtom->_objAddress;
                                        parser.findTargetFromAddress(sreloc->r_value(), target);
                                        // check for addend encoded in the section content
-                                       int32_t addend = contentValue - (sreloc->r_value() - nextRelocValue);
+                                       int64_t addend = (int32_t)contentValue - (int32_t)(sreloc->r_value() - nextRelocValue);
                                        if ( addend < 0 ) {
                                                // switch binding base on coalescing
                                                if ( target.atom == NULL ) {
                                        if ( addend < 0 ) {
                                                // switch binding base on coalescing
                                                if ( target.atom == NULL ) {
@@ -5375,12 +5530,10 @@ bool Section<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocati
 
 
        
 
 
        
-//
-// 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)
+
+
+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;
 {
        const macho_section<P>* sect = this->machoSection();
        bool result = false;
@@ -5389,429 +5542,37 @@ bool Section<A>::addRelocFixup_powerpc(class Parser<A>& parser,
        uint32_t* fixUpPtr;
        int32_t displacement = 0;
        uint32_t instruction = 0;
        uint32_t* fixUpPtr;
        int32_t displacement = 0;
        uint32_t instruction = 0;
-       int16_t lowBits;
        pint_t contentValue = 0;
        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 ) {
        
        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;
                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());
                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() ) {
                if ( reloc->r_extern() ) {
-                       target.atom = NULL;
                        const macho_nlist<P>& targetSymbol = parser.symbolFromIndex(reloc->r_symbolnum());
                        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() ) {
                }
                switch ( reloc->r_type() ) {
-                       case PPC_RELOC_BR24:
-                               assert((instruction & 0x4C000000) == 0x48000000);
-                               displacement = (instruction & 0x03FFFFFC);
-                               if ( (displacement & 0x02000000) != 0 )
-                                       displacement |= 0xFC000000;
-                               if ( reloc->r_extern() ) {
-                                       target.addend = srcAddr + displacement;
-                               }
-                               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::kindStorePPCDtraceCallSiteNop, 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);
-                                       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::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);
-                               }
-                               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);
-                               if ( reloc->r_extern() ) {
-                                       target.addend = 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);
-                               }
-                               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 {
-                                       parser.findTargetFromAddressAndSectionNum(dstAddr, reloc->r_symbolnum(), target);
-                               }
-                               parser.addFixups(src, ld::Fixup::kindStorePPCAbsHigh16AddLow, target);
-                               break;
-                       case PPC_RELOC_VANILLA:
-                               contentValue = P::getP(*((pint_t*)fixUpPtr));
-                               if ( reloc->r_extern() ) {
-                                       target.addend = contentValue;
-                               }
-                               else {
-                                       parser.findTargetFromAddressAndSectionNum(contentValue, reloc->r_symbolnum(), target);
-                               }
-                               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;
-                               }
-                               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";
-                               }
-                               parser.findTargetFromAddressAndSectionNum(nextReloc->r_address(), reloc->r_symbolnum(), target);
-                               parser.addFixups(src, ld::Fixup::kindStorePPCBranch24, target);
-                               break;
-                       default:
-                               warning("unknown relocation type %d", reloc->r_type());
-               }
-       }
-       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];
-               srcAddr = sect->addr() + sreloc->r_address();
-               dstAddr = sreloc->r_value();
-               fixUpPtr = (uint32_t*)(file().fileContent() + sect->offset() + sreloc->r_address());
-               instruction = BigEndian::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 ) {
-                               nextRelocIsPair = true;
-                               nextRelocAddress = nextReloc->r_address();
-                               result = true;
-                       }
-               }
-               else {
-                       if ( nextSReloc->r_type() == PPC_RELOC_PAIR ) {
-                               nextRelocIsPair = true;
-                               nextRelocAddress = nextSReloc->r_address();
-                               nextRelocValue = nextSReloc->r_value();
-                               result = true;
-                       }
-               }
-               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() ) {
-                       target.atom = NULL;
-                       const macho_nlist<P>& targetSymbol = parser.symbolFromIndex(reloc->r_symbolnum());
-                       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;
+                       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
                                if ( (displacement & 0x02000000) != 0 )
                                        displacement |= 0xFC000000;
                                // The pc added will be +8 from the pc
@@ -5892,7 +5653,7 @@ bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocati
                                        throw "bad length for ARM_RELOC_VANILLA";
                                contentValue = LittleEndian::get32(*fixUpPtr);
                                if ( reloc->r_extern() ) {
                                        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
                                }
                                        if ( externSymbolIsThumbDef )
                                                target.addend &= -2; // remove thumb bit
                                }
@@ -5939,13 +5700,31 @@ bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocati
                                        if ( reloc->r_length() & 1 ) {
                                                // high 16
                                                dstAddr = ((instruction16 << 16) | other16);
                                        if ( reloc->r_length() & 1 ) {
                                                // high 16
                                                dstAddr = ((instruction16 << 16) | other16);
-                                               parser.findTargetFromAddress(dstAddr, target);
+                        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;
                                                parser.addFixups(src, (isThumb ? ld::Fixup::kindStoreThumbHigh16 : ld::Fixup::kindStoreARMHigh16), target);
                                        }
                                        else {
                                                // low 16
                                                dstAddr = (other16 << 16) | instruction16;
-                                               parser.findTargetFromAddress(dstAddr, target);
+                        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.addFixups(src, (isThumb ? ld::Fixup::kindStoreThumbLow16 : ld::Fixup::kindStoreARMLow16), target);
                                        }
                                        result = true;
@@ -6052,7 +5831,7 @@ bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocati
                                        uint32_t offsetInTarget;
                                        Atom<arm>* targetAtom = parser.findAtomByAddressOrLocalTargetOfStub(sreloc->r_value(), &offsetInTarget);
                                        // check for addend encoded in the section content
                                        uint32_t offsetInTarget;
                                        Atom<arm>* targetAtom = parser.findAtomByAddressOrLocalTargetOfStub(sreloc->r_value(), &offsetInTarget);
                                        // check for addend encoded in the section content
-                    int64_t addend = contentValue - (sreloc->r_value() - nextRelocValue);
+                    int64_t addend = (int32_t)contentValue - (int32_t)(sreloc->r_value() - nextRelocValue);
                                        if ( targetAtom->isThumb() )
                                                addend &= -2; // remove thumb bit
                                        // if reference to LSDA, add group subordinate fixup
                                        if ( targetAtom->isThumb() )
                                                addend &= -2; // remove thumb bit
                                        // if reference to LSDA, add group subordinate fixup
@@ -6073,7 +5852,6 @@ bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocati
                                                else {
                                                        parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, false, targetAtom->name());
                                                }
                                                else {
                                                        parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, false, targetAtom->name());
                                                }
-                                               parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, targetAtom);
                                                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::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);
@@ -6103,8 +5881,6 @@ bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocati
                                        uint32_t offsetInFrom = nextRelocValue - fromAtom->_objAddress;
                                        Atom<arm>* targetAtom  = parser.findAtomByAddress(sreloc->r_value());
                                        uint32_t offsetInTarget = sreloc->r_value() - targetAtom->_objAddress;
                                        uint32_t offsetInFrom = nextRelocValue - fromAtom->_objAddress;
                                        Atom<arm>* targetAtom  = parser.findAtomByAddress(sreloc->r_value());
                                        uint32_t offsetInTarget = sreloc->r_value() - targetAtom->_objAddress;
-                                       //if ( targetAtom->isThumb() )
-                                       //      addend &= -2; // remove thumb bit
                                        uint32_t instruction16;
                                        uint32_t other16 = (nextRelocAddress & 0xFFFF);
                                        bool isThumb;
                                        uint32_t instruction16;
                                        uint32_t other16 = (nextRelocAddress & 0xFFFF);
                                        bool isThumb;
@@ -6126,6 +5902,8 @@ bool Section<arm>::addRelocFixup(class Parser<arm>& parser, const macho_relocati
                                                dstAddr = ((instruction16 << 16) | other16);
                                        else 
                                                dstAddr = (other16 << 16) | instruction16;
                                                dstAddr = ((instruction16 << 16) | other16);
                                        else 
                                                dstAddr = (other16 << 16) | instruction16;
+                                       if ( targetAtom->isThumb() )
+                                               dstAddr &= (-2); // remove thumb bit
                     int32_t addend = dstAddr - (sreloc->r_value() - nextRelocValue);
                                        if ( targetAtom->scope() == ld::Atom::scopeTranslationUnit ) {
                                                parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, targetAtom);
                     int32_t addend = dstAddr - (sreloc->r_value() - nextRelocValue);
                                        if ( targetAtom->scope() == ld::Atom::scopeTranslationUnit ) {
                                                parser.addFixup(src, ld::Fixup::k1of5, ld::Fixup::kindSetTargetAddress, targetAtom);
@@ -6254,41 +6032,6 @@ bool ObjC1ClassSection<x86>::addRelocFixup(class Parser<x86>& parser, const mach
        return FixedSizeSection<x86>::addRelocFixup(parser, 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 <typename A>
@@ -6302,38 +6045,6 @@ bool Objc1ClassReferences<A>::addRelocFixup(class Parser<A>& parser, const macho
 }
 
 
 }
 
 
-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)
 
 template <>
 bool Objc1ClassReferences<x86>::addRelocFixup(class Parser<x86>& parser, const macho_relocation_info<x86::P>* reloc)
@@ -6369,7 +6080,7 @@ bool Objc1ClassReferences<x86>::addRelocFixup(class Parser<x86>& parser, const m
 
 
 template <typename A>
 
 
 template <typename A>
-void Section<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFIInfoArray&)
+void Section<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&)
 {
        const macho_section<P>* sect = this->machoSection();
        const macho_relocation_info<P>* relocs = (macho_relocation_info<P>*)(file().fileContent() + sect->reloff());
 {
        const macho_section<P>* sect = this->machoSection();
        const macho_relocation_info<P>* relocs = (macho_relocation_info<P>*)(file().fileContent() + sect->reloff());
@@ -6380,7 +6091,7 @@ void Section<A>::makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI
                                ++r; // skip next
                }
                catch (const char* msg) {
                                ++r; // skip next
                }
                catch (const char* msg) {
-                       throwf("in section %s,%s reloc %u: %s", sect->segname(), sect->sectname(), r, msg);
+                       throwf("in section %s,%s reloc %u: %s", sect->segname(), Section<A>::makeSectionName(sect), r, msg);
                }
        }
        
                }
        }
        
@@ -6440,14 +6151,6 @@ ld::relocatable::File* parse(const uint8_t* fileContent, uint64_t fileLength,
                        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;
                        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);
-                       break;
        }
        return NULL;
 }
        }
        return NULL;
 }
@@ -6464,10 +6167,6 @@ bool isObjectFile(const uint8_t* fileContent, uint64_t fileLength, const ParserO
                        return ( mach_o::relocatable::Parser<x86>::validFile(fileContent) );
                case CPU_TYPE_ARM:
                        return ( mach_o::relocatable::Parser<arm>::validFile(fileContent, opts.objSubtypeMustMatch, opts.subType) );
                        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) );
        }
        return false;
 }
        }
        return false;
 }
@@ -6493,17 +6192,6 @@ bool isObjectFile(const uint8_t* fileContent, cpu_type_t* result, cpu_subtype_t*
                *subResult = header->cpusubtype();
                return true;
        }
                *subResult = header->cpusubtype();
                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;
-               return true;
-       }
        return false;
 }                                      
 
        return false;
 }                                      
 
@@ -6521,12 +6209,6 @@ const char* archName(const uint8_t* fileContent)
        if ( mach_o::relocatable::Parser<arm>::validFile(fileContent, false, 0) ) {
                return mach_o::relocatable::Parser<arm>::fileKind(fileContent);
        }
        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;
 }
 
        return NULL;
 }
 
@@ -6541,6 +6223,9 @@ bool hasObjC2Categories(const uint8_t* fileContent)
        else if ( mach_o::relocatable::Parser<arm>::validFile(fileContent, false, 0) ) {
                return mach_o::relocatable::Parser<arm>::hasObjC2Categories(fileContent);
        }
        else if ( mach_o::relocatable::Parser<arm>::validFile(fileContent, false, 0) ) {
                return mach_o::relocatable::Parser<arm>::hasObjC2Categories(fileContent);
        }
+       else if ( mach_o::relocatable::Parser<x86>::validFile(fileContent, false, 0) ) {
+               return mach_o::relocatable::Parser<x86>::hasObjC2Categories(fileContent);
+       }
        return false;
 }                              
 
        return false;
 }