15
15
16
16
#include " llvm/ADT/SmallString.h"
17
17
#include " llvm/ADT/SmallVector.h"
18
+ #include " llvm/ADT/iterator_range.h"
18
19
#include " llvm/BinaryFormat/XCOFF.h"
19
20
#include " llvm/Object/ObjectFile.h"
20
21
#include " llvm/Support/Endian.h"
23
24
namespace llvm {
24
25
namespace object {
25
26
27
+ class xcoff_symbol_iterator ;
28
+
26
29
struct XCOFFFileHeader32 {
27
30
support::ubig16_t Magic;
28
31
support::ubig16_t NumberOfSections;
@@ -576,6 +579,10 @@ class XCOFFObjectFile : public ObjectFile {
576
579
Expected<uint32_t > getSymbolFlags (DataRefImpl Symb) const override ;
577
580
basic_symbol_iterator symbol_begin () const override ;
578
581
basic_symbol_iterator symbol_end () const override ;
582
+
583
+ using xcoff_symbol_iterator_range = iterator_range<xcoff_symbol_iterator>;
584
+ xcoff_symbol_iterator_range symbols () const ;
585
+
579
586
bool is64Bit () const override ;
580
587
Expected<StringRef> getSymbolName (DataRefImpl Symb) const override ;
581
588
Expected<uint64_t > getSymbolAddress (DataRefImpl Symb) const override ;
@@ -761,33 +768,47 @@ struct XCOFFSymbolEntry64 {
761
768
uint8_t NumberOfAuxEntries;
762
769
};
763
770
764
- class XCOFFSymbolRef {
771
+ class XCOFFSymbolRef : public SymbolRef {
765
772
public:
766
773
enum { NAME_IN_STR_TBL_MAGIC = 0x0 };
767
774
768
775
XCOFFSymbolRef (DataRefImpl SymEntDataRef,
769
776
const XCOFFObjectFile *OwningObjectPtr)
770
- : OwningObjectPtr( OwningObjectPtr) {
777
+ : SymbolRef(SymEntDataRef, OwningObjectPtr) {
771
778
assert (OwningObjectPtr && " OwningObjectPtr cannot be nullptr!" );
772
779
assert (SymEntDataRef.p != 0 &&
773
780
" Symbol table entry pointer cannot be nullptr!" );
781
+ }
774
782
775
- if (OwningObjectPtr->is64Bit ())
776
- Entry64 = reinterpret_cast <const XCOFFSymbolEntry64 *>(SymEntDataRef.p );
777
- else
778
- Entry32 = reinterpret_cast <const XCOFFSymbolEntry32 *>(SymEntDataRef.p );
783
+ const XCOFFSymbolEntry32 *getSymbol32 () const {
784
+ return reinterpret_cast <const XCOFFSymbolEntry32 *>(getRawDataRefImpl ().p );
785
+ }
786
+ const XCOFFSymbolEntry64 *getSymbol64 () const {
787
+ return reinterpret_cast <const XCOFFSymbolEntry64 *>(getRawDataRefImpl ().p );
779
788
}
780
789
781
- const XCOFFSymbolEntry32 *getSymbol32 () { return Entry32; }
782
- const XCOFFSymbolEntry64 *getSymbol64 () { return Entry64; }
790
+ uint64_t getValue () const {
791
+ return getObject ()->is64Bit () ? getValue64 () : getValue32 ();
792
+ }
783
793
784
- uint64_t getValue () const { return Entry32 ? getValue32 () : getValue64 (); }
794
+ uint32_t getValue32 () const {
795
+ return reinterpret_cast <const XCOFFSymbolEntry32 *>(getRawDataRefImpl ().p )
796
+ ->Value ;
797
+ }
785
798
786
- uint32_t getValue32 () const { return Entry32->Value ; }
799
+ uint64_t getValue64 () const {
800
+ return reinterpret_cast <const XCOFFSymbolEntry64 *>(getRawDataRefImpl ().p )
801
+ ->Value ;
802
+ }
787
803
788
- uint64_t getValue64 () const { return Entry64->Value ; }
804
+ uint64_t getSize () const {
805
+ return getObject ()->getSymbolSize (getRawDataRefImpl ());
806
+ }
789
807
790
- #define GETVALUE (X ) Entry32 ? Entry32->X : Entry64->X
808
+ #define GETVALUE (X ) \
809
+ getObject ()->is64Bit () \
810
+ ? reinterpret_cast<const XCOFFSymbolEntry64 *>(getRawDataRefImpl().p)->X \
811
+ : reinterpret_cast<const XCOFFSymbolEntry32 *>(getRawDataRefImpl().p)->X
791
812
792
813
int16_t getSectionNumber() const { return GETVALUE (SectionNumber); }
793
814
@@ -812,8 +833,7 @@ class XCOFFSymbolRef {
812
833
#undef GETVALUE
813
834
814
835
uintptr_t getEntryAddress () const {
815
- return Entry32 ? reinterpret_cast <uintptr_t >(Entry32)
816
- : reinterpret_cast <uintptr_t >(Entry64);
836
+ return getRawDataRefImpl ().p ;
817
837
}
818
838
819
839
Expected<StringRef> getName () const ;
@@ -822,9 +842,23 @@ class XCOFFSymbolRef {
822
842
Expected<XCOFFCsectAuxRef> getXCOFFCsectAuxRef () const ;
823
843
824
844
private:
825
- const XCOFFObjectFile *OwningObjectPtr;
826
- const XCOFFSymbolEntry32 *Entry32 = nullptr ;
827
- const XCOFFSymbolEntry64 *Entry64 = nullptr ;
845
+ const XCOFFObjectFile *getObject () const {
846
+ return cast<XCOFFObjectFile>(BasicSymbolRef::getObject ());
847
+ }
848
+ };
849
+
850
+ class xcoff_symbol_iterator : public symbol_iterator {
851
+ public:
852
+ xcoff_symbol_iterator (const basic_symbol_iterator &B)
853
+ : symbol_iterator(B) {}
854
+
855
+ const XCOFFSymbolRef *operator ->() const {
856
+ return static_cast <const XCOFFSymbolRef *>(symbol_iterator::operator ->());
857
+ }
858
+
859
+ const XCOFFSymbolRef &operator *() const {
860
+ return static_cast <const XCOFFSymbolRef &>(symbol_iterator::operator *());
861
+ }
828
862
};
829
863
830
864
class TBVectorExt {
0 commit comments