@@ -1116,69 +1116,74 @@ bool ElfView::Init()
11161116 {
11171117 case ELF_STT_OBJECT:
11181118 case ELF_STT_NOTYPE:
1119- if (entry.section != ELF_SHN_UNDEF)
1120- DefineElfSymbol (DataSymbol, entry.name , gotEntry, true , entry.binding , 4 , Type::PointerType (
1121- GetDefaultPlatform ()->GetArchitecture (), Type::VoidType ())->WithConfidence (BN_FULL_CONFIDENCE));
1122- else
1119+ {
1120+ bool relocationExists = false ;
1121+ for (auto & reloc : relocs)
11231122 {
1124- bool relocationExists = false ;
1125- for (auto & reloc : relocs)
1123+ if (reloc.offset == gotEntry)
11261124 {
1127- if (reloc.offset == gotEntry)
1128- {
1129- relocationExists = true ;
1130- break ;
1131- }
1132- }
1133- if (!relocationExists)
1134- {
1135- int relocType = m_arch->GetAddressSize () == 4 ? 126 /* R_MIPS_COPY */ : 125 /* R_MIPS64_COPY */ ;
1136- relocs.push_back (ELFRelocEntry (gotEntry, i, relocType, 0 , 0 , false ));
1125+ relocationExists = true ;
1126+ break ;
11371127 }
1138- DefineElfSymbol (ImportAddressSymbol, entry.name , gotEntry, true , entry.binding , entry.size );
11391128 }
1129+ if (!relocationExists)
1130+ {
1131+ int relocType = m_arch->GetAddressSize () == 4 ? 126 /* R_MIPS_COPY */ : 125 /* R_MIPS64_COPY */ ;
1132+ relocs.push_back (ELFRelocEntry (gotEntry, i, relocType, 0 , 0 , false ));
1133+ }
1134+ if (entry.section != ELF_SHN_UNDEF)
1135+ {
1136+ DefineElfSymbol (DataSymbol, entry.name , gotEntry, true , entry.binding , 4 ,
1137+ Type::PointerType (GetDefaultPlatform ()->GetArchitecture (),
1138+ Type::VoidType ())->WithConfidence (BN_FULL_CONFIDENCE));
1139+ }
1140+ else
1141+ DefineElfSymbol (ImportAddressSymbol, entry.name , gotEntry, true , entry.binding , entry.size );
11401142 break ;
1143+ }
11411144 case ELF_STT_FUNC:
1145+ {
1146+ bool relocationExists = false ;
1147+ for (auto & reloc : relocs)
1148+ {
1149+ if (reloc.offset == gotEntry)
1150+ {
1151+ relocationExists = true ;
1152+ break ;
1153+ }
1154+ }
1155+ if (!relocationExists)
1156+ {
1157+ int relocType = m_arch->GetAddressSize () == 4 ? 127 /* R_MIPS_JUMP_SLOT*/ : 125 /* R_MIPS64_COPY */ ;
1158+ relocs.push_back (ELFRelocEntry (gotEntry, i, relocType, 0 , 0 , false ));
1159+ }
11421160 if (entry.section != ELF_SHN_UNDEF)
1161+ {
11431162 DefineElfSymbol (DataSymbol, entry.name , gotEntry, true , entry.binding , 4 ,
11441163 Type::PointerType (GetDefaultPlatform ()->GetArchitecture (),
11451164 Type::FunctionType (Type::IntegerType (GetDefaultPlatform ()->GetArchitecture ()->GetAddressSize (), true ),
11461165 GetDefaultPlatform ()->GetDefaultCallingConvention (), vector<FunctionParameter>())->WithConfidence (0 )));
1166+ }
11471167 else
1148- {
1149- bool relocationExists = false ;
1150- for (auto & reloc : relocs)
1151- {
1152- if (reloc.offset == gotEntry)
1153- {
1154- relocationExists = true ;
1155- break ;
1156- }
1157- }
1158- if (!relocationExists)
1159- {
1160- int relocType = m_arch->GetAddressSize () == 4 ? 127 /* R_MIPS_JUMP_SLOT*/ : 125 /* R_MIPS64_COPY */ ;
1161- relocs.push_back (ELFRelocEntry (gotEntry, i, relocType, 0 , 0 , false ));
1162- }
11631168 DefineElfSymbol (ImportAddressSymbol, entry.name , gotEntry, true , entry.binding , entry.size );
1164- // TODO for now create associated PLT entry if it exists. At some point we could extend the detection in RecognizeELFPLTEntries in arch_mips.
1165- Ref<Symbol> sym = GetSymbolByAddress (gotEntry);
1166- if (entry.value && sym && (sym->GetType () == ImportAddressSymbol))
1169+ // TODO for now create associated PLT entry if it exists. At some point we could extend the detection in RecognizeELFPLTEntries in arch_mips.
1170+ Ref<Symbol> sym = GetSymbolByAddress (gotEntry);
1171+ if (entry.value && sym && (sym->GetType () == ImportAddressSymbol))
1172+ {
1173+ uint64_t adjustedAddress = entry.value + imageBaseAdjustment;
1174+ Ref<Platform> targetPlatform = platform->GetAssociatedPlatformByAddress (adjustedAddress);
1175+ Ref<Function> func = AddFunctionForAnalysis (targetPlatform, adjustedAddress);
1176+ if (func)
11671177 {
1168- uint64_t adjustedAddress = entry.value + imageBaseAdjustment;
1169- Ref<Platform> targetPlatform = platform->GetAssociatedPlatformByAddress (adjustedAddress);
1170- Ref<Function> func = AddFunctionForAnalysis (targetPlatform, adjustedAddress);
1171- if (func)
1172- {
1173- Ref<Symbol> funcSym = new Symbol (ImportedFunctionSymbol,
1174- sym->GetShortName (), sym->GetFullName (), sym->GetRawName (),
1175- adjustedAddress, NoBinding, sym->GetNameSpace (), sym->GetOrdinal ());
1176- DefineAutoSymbol (funcSym);
1177- func->ApplyImportedTypes (funcSym);
1178- }
1178+ Ref<Symbol> funcSym = new Symbol (ImportedFunctionSymbol,
1179+ sym->GetShortName (), sym->GetFullName (), sym->GetRawName (),
1180+ adjustedAddress, NoBinding, sym->GetNameSpace (), sym->GetOrdinal ());
1181+ DefineAutoSymbol (funcSym);
1182+ func->ApplyImportedTypes (funcSym);
11791183 }
11801184 }
11811185 break ;
1186+ }
11821187 default :
11831188 m_logger->LogDebug (" ELF symbol type of %d not handled." , entry.type );
11841189 break ;
0 commit comments