| 891 | } |
| 892 | |
| 893 | int BlCodeView::CreatePublicStream() |
| 894 | { |
| 895 | BP_ZONE("BlCodeView::CreatePublicStream"); |
| 896 | |
| 897 | int publicStreamIdx = StartStream(); |
| 898 | |
| 899 | BlCvRecordMap publics; |
| 900 | |
| 901 | struct _SortEntry |
| 902 | { |
| 903 | uint64 mAddr; |
| 904 | int mRecordIdx; |
| 905 | }; |
| 906 | |
| 907 | Array<_SortEntry> addrMap; |
| 908 | addrMap.Reserve(mContext->mSymTable.mMap.size()); |
| 909 | |
| 910 | for (auto symPair : mContext->mSymTable.mMap) |
| 911 | { |
| 912 | auto sym = symPair.second; |
| 913 | if ((sym->mSegmentIdx >= 0) || (sym->mKind == BlSymKind_Absolute)) |
| 914 | { |
| 915 | bool isAbs = sym->mKind == BlSymKind_Absolute; |
| 916 | |
| 917 | #define ADDR_FLAG_ABS 0x8000000000000000L |
| 918 | |
| 919 | auto segment = (isAbs) ? (BlSegment*)NULL : mContext->mSegments[sym->mSegmentIdx]; |
| 920 | |
| 921 | |
| 922 | int pubSymLen = (int)offsetof(PUBSYM32, name); |
| 923 | int nameSize = (int)strlen(sym->mName) + 1; |
| 924 | |
| 925 | PUBSYM32 pubSym = { 0 }; |
| 926 | pubSym.reclen = pubSymLen + nameSize - 2; |
| 927 | pubSym.rectyp = S_PUB32; |
| 928 | |
| 929 | if (isAbs) |
| 930 | { |
| 931 | pubSym.seg = (int)mContext->mOutSections.size(); // One past end is 'Abs' section |
| 932 | pubSym.off = sym->mSegmentOffset; |
| 933 | } |
| 934 | else |
| 935 | { |
| 936 | auto outSection = mContext->mOutSections[segment->mOutSectionIdx]; |
| 937 | if ((outSection->mCharacteristics & IMAGE_SCN_MEM_EXECUTE) != 0) |
| 938 | { |
| 939 | pubSym.pubsymflags.fFunction = 1; |
| 940 | pubSym.pubsymflags.fCode = 1; |
| 941 | } |
| 942 | |
| 943 | pubSym.off = (segment->mRVA - outSection->mRVA) + sym->mSegmentOffset; |
| 944 | pubSym.seg = outSection->mIdx + 1; |
| 945 | } |
| 946 | |
| 947 | int addBytes = ((nameSize + 2 + 3) & ~3) - (nameSize + 2); |
| 948 | pubSym.reclen += addBytes; |
| 949 | |
| 950 | int idx = mSymRecordsWriter.GetStreamPos(); |