@@ -752,9 +752,6 @@ Error RewriteInstance::run() {
752
752
void RewriteInstance::discoverFileObjects () {
753
753
NamedRegionTimer T (" discoverFileObjects" , " discover file objects" ,
754
754
TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
755
- FileSymRefs.clear ();
756
- BC->getBinaryFunctions ().clear ();
757
- BC->clearBinaryData ();
758
755
759
756
// For local symbols we want to keep track of associated FILE symbol name for
760
757
// disambiguation by combined name.
@@ -891,26 +888,21 @@ void RewriteInstance::discoverFileObjects() {
891
888
unsigned AnonymousId = 0 ;
892
889
893
890
// Regex object for matching cold fragments.
894
- Regex ColdFragment (" .*\\ .cold(\\ .[0-9]+)?" );
891
+ const Regex ColdFragment (" .*\\ .cold(\\ .[0-9]+)?" );
895
892
896
893
const auto SortedSymbolsEnd =
897
894
LastSymbol == SortedSymbols.end () ? LastSymbol : std::next (LastSymbol);
898
895
for (auto Iter = SortedSymbols.begin (); Iter != SortedSymbolsEnd; ++Iter) {
899
896
const SymbolRef &Symbol = Iter->Symbol ;
900
-
901
- // Keep undefined symbols for pretty printing?
902
- if (cantFail (Symbol.getFlags ()) & SymbolRef::SF_Undefined)
903
- continue ;
904
-
897
+ const uint64_t SymbolAddress = Iter->Address ;
898
+ const auto SymbolFlags = cantFail (Symbol.getFlags ());
905
899
const SymbolRef::Type SymbolType = cantFail (Symbol.getType ());
906
900
907
901
if (SymbolType == SymbolRef::ST_File)
908
902
continue ;
909
903
910
904
StringRef SymName = cantFail (Symbol.getName (), " cannot get symbol name" );
911
- uint64_t Address =
912
- cantFail (Symbol.getAddress (), " cannot get symbol address" );
913
- if (Address == 0 ) {
905
+ if (SymbolAddress == 0 ) {
914
906
if (opts::Verbosity >= 1 && SymbolType == SymbolRef::ST_Function)
915
907
errs () << " BOLT-WARNING: function with 0 address seen\n " ;
916
908
continue ;
@@ -920,11 +912,12 @@ void RewriteInstance::discoverFileObjects() {
920
912
if (SymName == " __hot_start" || SymName == " __hot_end" )
921
913
continue ;
922
914
923
- FileSymRefs[Address ] = Symbol;
915
+ FileSymRefs[SymbolAddress ] = Symbol;
924
916
925
917
// Skip section symbols that will be registered by disassemblePLT().
926
- if ((cantFail (Symbol.getType ()) == SymbolRef::ST_Debug)) {
927
- ErrorOr<BinarySection &> BSection = BC->getSectionForAddress (Address);
918
+ if (SymbolType == SymbolRef::ST_Debug) {
919
+ ErrorOr<BinarySection &> BSection =
920
+ BC->getSectionForAddress (SymbolAddress);
928
921
if (BSection && getPLTSectionInfo (BSection->getName ()))
929
922
continue ;
930
923
}
@@ -946,10 +939,10 @@ void RewriteInstance::discoverFileObjects() {
946
939
std::string AlternativeName;
947
940
if (Name.empty ()) {
948
941
UniqueName = " ANONYMOUS." + std::to_string (AnonymousId++);
949
- } else if (cantFail (Symbol. getFlags ()) & SymbolRef::SF_Global) {
942
+ } else if (SymbolFlags & SymbolRef::SF_Global) {
950
943
if (const BinaryData *BD = BC->getBinaryDataByName (Name)) {
951
944
if (BD->getSize () == ELFSymbolRef (Symbol).getSize () &&
952
- BD->getAddress () == Address ) {
945
+ BD->getAddress () == SymbolAddress ) {
953
946
if (opts::Verbosity > 1 )
954
947
errs () << " BOLT-WARNING: ignoring duplicate global symbol " << Name
955
948
<< " \n " ;
@@ -985,14 +978,13 @@ void RewriteInstance::discoverFileObjects() {
985
978
986
979
uint64_t SymbolSize = ELFSymbolRef (Symbol).getSize ();
987
980
uint64_t SymbolAlignment = Symbol.getAlignment ();
988
- unsigned SymbolFlags = cantFail (Symbol.getFlags ());
989
981
990
982
auto registerName = [&](uint64_t FinalSize) {
991
983
// Register names even if it's not a function, e.g. for an entry point.
992
- BC->registerNameAtAddress (UniqueName, Address , FinalSize, SymbolAlignment ,
993
- SymbolFlags);
984
+ BC->registerNameAtAddress (UniqueName, SymbolAddress , FinalSize,
985
+ SymbolAlignment, SymbolFlags);
994
986
if (!AlternativeName.empty ())
995
- BC->registerNameAtAddress (AlternativeName, Address , FinalSize,
987
+ BC->registerNameAtAddress (AlternativeName, SymbolAddress , FinalSize,
996
988
SymbolAlignment, SymbolFlags);
997
989
};
998
990
@@ -1012,7 +1004,7 @@ void RewriteInstance::discoverFileObjects() {
1012
1004
LLVM_DEBUG (dbgs () << " BOLT-DEBUG: considering symbol " << UniqueName
1013
1005
<< " for function\n " );
1014
1006
1015
- if (Address == Section->getAddress () + Section->getSize ()) {
1007
+ if (SymbolAddress == Section->getAddress () + Section->getSize ()) {
1016
1008
assert (SymbolSize == 0 &&
1017
1009
" unexpect non-zero sized symbol at end of section" );
1018
1010
LLVM_DEBUG (
@@ -1038,11 +1030,12 @@ void RewriteInstance::discoverFileObjects() {
1038
1030
// their local labels. The only way to tell them apart is to look at
1039
1031
// symbol scope - global vs local.
1040
1032
if (PreviousFunction && SymbolType != SymbolRef::ST_Function) {
1041
- if (PreviousFunction->containsAddress (Address )) {
1033
+ if (PreviousFunction->containsAddress (SymbolAddress )) {
1042
1034
if (PreviousFunction->isSymbolValidInScope (Symbol, SymbolSize)) {
1043
1035
LLVM_DEBUG (dbgs ()
1044
1036
<< " BOLT-DEBUG: symbol is a function local symbol\n " );
1045
- } else if (Address == PreviousFunction->getAddress () && !SymbolSize) {
1037
+ } else if (SymbolAddress == PreviousFunction->getAddress () &&
1038
+ !SymbolSize) {
1046
1039
LLVM_DEBUG (dbgs () << " BOLT-DEBUG: ignoring symbol as a marker\n " );
1047
1040
} else if (opts::Verbosity > 1 ) {
1048
1041
errs () << " BOLT-WARNING: symbol " << UniqueName
@@ -1059,8 +1052,8 @@ void RewriteInstance::discoverFileObjects() {
1059
1052
}
1060
1053
}
1061
1054
1062
- if (PreviousFunction && PreviousFunction->containsAddress (Address ) &&
1063
- PreviousFunction->getAddress () != Address ) {
1055
+ if (PreviousFunction && PreviousFunction->containsAddress (SymbolAddress ) &&
1056
+ PreviousFunction->getAddress () != SymbolAddress ) {
1064
1057
if (PreviousFunction->isSymbolValidInScope (Symbol, SymbolSize)) {
1065
1058
if (opts::Verbosity >= 1 )
1066
1059
outs () << " BOLT-INFO: skipping possibly another entry for function "
@@ -1072,12 +1065,12 @@ void RewriteInstance::discoverFileObjects() {
1072
1065
1073
1066
registerName (0 );
1074
1067
1075
- PreviousFunction->addEntryPointAtOffset (Address -
1068
+ PreviousFunction->addEntryPointAtOffset (SymbolAddress -
1076
1069
PreviousFunction->getAddress ());
1077
1070
1078
1071
// Remove the symbol from FileSymRefs so that we can skip it from
1079
1072
// in the future.
1080
- auto SI = FileSymRefs.find (Address );
1073
+ auto SI = FileSymRefs.find (SymbolAddress );
1081
1074
assert (SI != FileSymRefs.end () && " symbol expected to be present" );
1082
1075
assert (SI->second == Symbol && " wrong symbol found" );
1083
1076
FileSymRefs.erase (SI);
@@ -1087,18 +1080,19 @@ void RewriteInstance::discoverFileObjects() {
1087
1080
1088
1081
// Checkout for conflicts with function data from FDEs.
1089
1082
bool IsSimple = true ;
1090
- auto FDEI = CFIRdWrt->getFDEs ().lower_bound (Address );
1083
+ auto FDEI = CFIRdWrt->getFDEs ().lower_bound (SymbolAddress );
1091
1084
if (FDEI != CFIRdWrt->getFDEs ().end ()) {
1092
1085
const dwarf::FDE &FDE = *FDEI->second ;
1093
- if (FDEI->first != Address ) {
1086
+ if (FDEI->first != SymbolAddress ) {
1094
1087
// There's no matching starting address in FDE. Make sure the previous
1095
1088
// FDE does not contain this address.
1096
1089
if (FDEI != CFIRdWrt->getFDEs ().begin ()) {
1097
1090
--FDEI;
1098
1091
const dwarf::FDE &PrevFDE = *FDEI->second ;
1099
1092
uint64_t PrevStart = PrevFDE.getInitialLocation ();
1100
1093
uint64_t PrevLength = PrevFDE.getAddressRange ();
1101
- if (Address > PrevStart && Address < PrevStart + PrevLength) {
1094
+ if (SymbolAddress > PrevStart &&
1095
+ SymbolAddress < PrevStart + PrevLength) {
1102
1096
errs () << " BOLT-ERROR: function " << UniqueName
1103
1097
<< " is in conflict with FDE ["
1104
1098
<< Twine::utohexstr (PrevStart) << " , "
@@ -1115,11 +1109,11 @@ void RewriteInstance::discoverFileObjects() {
1115
1109
<< " ; symbol table : " << SymbolSize << " . Using max size.\n " ;
1116
1110
}
1117
1111
SymbolSize = std::max (SymbolSize, FDE.getAddressRange ());
1118
- if (BC->getBinaryDataAtAddress (Address )) {
1119
- BC->setBinaryDataSize (Address , SymbolSize);
1112
+ if (BC->getBinaryDataAtAddress (SymbolAddress )) {
1113
+ BC->setBinaryDataSize (SymbolAddress , SymbolSize);
1120
1114
} else {
1121
1115
LLVM_DEBUG (dbgs () << " BOLT-DEBUG: No BD @ 0x"
1122
- << Twine::utohexstr (Address ) << " \n " );
1116
+ << Twine::utohexstr (SymbolAddress ) << " \n " );
1123
1117
}
1124
1118
}
1125
1119
}
@@ -1128,7 +1122,7 @@ void RewriteInstance::discoverFileObjects() {
1128
1122
// Since function may not have yet obtained its real size, do a search
1129
1123
// using the list of registered functions instead of calling
1130
1124
// getBinaryFunctionAtAddress().
1131
- auto BFI = BC->getBinaryFunctions ().find (Address );
1125
+ auto BFI = BC->getBinaryFunctions ().find (SymbolAddress );
1132
1126
if (BFI != BC->getBinaryFunctions ().end ()) {
1133
1127
BF = &BFI->second ;
1134
1128
// Duplicate the function name. Make sure everything matches before we add
@@ -1142,23 +1136,26 @@ void RewriteInstance::discoverFileObjects() {
1142
1136
<< BF->getSize () << " new " << SymbolSize << " \n " ;
1143
1137
}
1144
1138
BF->setSize (std::max (SymbolSize, BF->getSize ()));
1145
- BC->setBinaryDataSize (Address , BF->getSize ());
1139
+ BC->setBinaryDataSize (SymbolAddress , BF->getSize ());
1146
1140
}
1147
1141
BF->addAlternativeName (UniqueName);
1148
1142
} else {
1149
- ErrorOr<BinarySection &> Section = BC->getSectionForAddress (Address);
1143
+ ErrorOr<BinarySection &> Section =
1144
+ BC->getSectionForAddress (SymbolAddress);
1150
1145
// Skip symbols from invalid sections
1151
1146
if (!Section) {
1152
1147
errs () << " BOLT-WARNING: " << UniqueName << " (0x"
1153
- << Twine::utohexstr (Address) << " ) does not have any section\n " ;
1148
+ << Twine::utohexstr (SymbolAddress)
1149
+ << " ) does not have any section\n " ;
1154
1150
continue ;
1155
1151
}
1156
1152
1157
1153
// Skip symbols from zero-sized sections.
1158
1154
if (!Section->getSize ())
1159
1155
continue ;
1160
1156
1161
- BF = BC->createBinaryFunction (UniqueName, *Section, Address, SymbolSize);
1157
+ BF = BC->createBinaryFunction (UniqueName, *Section, SymbolAddress,
1158
+ SymbolSize);
1162
1159
if (!IsSimple)
1163
1160
BF->setSimple (false );
1164
1161
}
0 commit comments