@@ -1021,41 +1021,6 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
1021
1021
1022
1022
ArrayRef<Elf_Sym> eSyms = this ->getELFSyms <ELFT>();
1023
1023
symbols.resize (eSyms.size ());
1024
- SymbolUnion *locals =
1025
- firstGlobal == 0
1026
- ? nullptr
1027
- : getSpecificAllocSingleton<SymbolUnion>().Allocate (firstGlobal);
1028
-
1029
- for (size_t i = 0 , end = firstGlobal; i != end; ++i) {
1030
- const Elf_Sym &eSym = eSyms[i];
1031
- uint32_t secIdx = eSym.st_shndx ;
1032
- if (LLVM_UNLIKELY (secIdx == SHN_XINDEX))
1033
- secIdx = check (getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
1034
- else if (secIdx >= SHN_LORESERVE)
1035
- secIdx = 0 ;
1036
- if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1037
- fatal (toString (this ) + " : invalid section index: " + Twine (secIdx));
1038
- if (LLVM_UNLIKELY (eSym.getBinding () != STB_LOCAL))
1039
- error (toString (this ) + " : non-local symbol (" + Twine (i) +
1040
- " ) found at index < .symtab's sh_info (" + Twine (end) + " )" );
1041
-
1042
- InputSectionBase *sec = sections[secIdx];
1043
- uint8_t type = eSym.getType ();
1044
- if (type == STT_FILE)
1045
- sourceFile = CHECK (eSym.getName (stringTable), this );
1046
- if (LLVM_UNLIKELY (stringTable.size () <= eSym.st_name ))
1047
- fatal (toString (this ) + " : invalid symbol name offset" );
1048
- StringRef name (stringTable.data () + eSym.st_name );
1049
-
1050
- symbols[i] = reinterpret_cast <Symbol *>(locals + i);
1051
- if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
1052
- new (symbols[i]) Undefined (this , name, STB_LOCAL, eSym.st_other , type,
1053
- /* discardedSecIdx=*/ secIdx);
1054
- else
1055
- new (symbols[i]) Defined (this , name, STB_LOCAL, eSym.st_other , type,
1056
- eSym.st_value , eSym.st_size , sec);
1057
- symbols[i]->isUsedInRegularObj = true ;
1058
- }
1059
1024
1060
1025
// Some entries have been filled by LazyObjFile.
1061
1026
for (size_t i = firstGlobal, end = eSyms.size (); i != end; ++i)
@@ -1149,6 +1114,45 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
1149
1114
}
1150
1115
}
1151
1116
1117
+ template <class ELFT > void ObjFile<ELFT>::initializeLocalSymbols() {
1118
+ if (!firstGlobal)
1119
+ return ;
1120
+ localSymStorage = std::make_unique<SymbolUnion[]>(firstGlobal);
1121
+ SymbolUnion *locals = localSymStorage.get ();
1122
+
1123
+ ArrayRef<Elf_Sym> eSyms = this ->getELFSyms <ELFT>();
1124
+ for (size_t i = 0 , end = firstGlobal; i != end; ++i) {
1125
+ const Elf_Sym &eSym = eSyms[i];
1126
+ uint32_t secIdx = eSym.st_shndx ;
1127
+ if (LLVM_UNLIKELY (secIdx == SHN_XINDEX))
1128
+ secIdx = check (getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
1129
+ else if (secIdx >= SHN_LORESERVE)
1130
+ secIdx = 0 ;
1131
+ if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1132
+ fatal (toString (this ) + " : invalid section index: " + Twine (secIdx));
1133
+ if (LLVM_UNLIKELY (eSym.getBinding () != STB_LOCAL))
1134
+ error (toString (this ) + " : non-local symbol (" + Twine (i) +
1135
+ " ) found at index < .symtab's sh_info (" + Twine (end) + " )" );
1136
+
1137
+ InputSectionBase *sec = sections[secIdx];
1138
+ uint8_t type = eSym.getType ();
1139
+ if (type == STT_FILE)
1140
+ sourceFile = CHECK (eSym.getName (stringTable), this );
1141
+ if (LLVM_UNLIKELY (stringTable.size () <= eSym.st_name ))
1142
+ fatal (toString (this ) + " : invalid symbol name offset" );
1143
+ StringRef name (stringTable.data () + eSym.st_name );
1144
+
1145
+ symbols[i] = reinterpret_cast <Symbol *>(locals + i);
1146
+ if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
1147
+ new (symbols[i]) Undefined (this , name, STB_LOCAL, eSym.st_other , type,
1148
+ /* discardedSecIdx=*/ secIdx);
1149
+ else
1150
+ new (symbols[i]) Defined (this , name, STB_LOCAL, eSym.st_other , type,
1151
+ eSym.st_value , eSym.st_size , sec);
1152
+ symbols[i]->isUsedInRegularObj = true ;
1153
+ }
1154
+ }
1155
+
1152
1156
// Called after all ObjFile::parse is called for all ObjFiles. This checks
1153
1157
// duplicate symbols and may do symbol property merge in the future.
1154
1158
template <class ELFT > void ObjFile<ELFT>::postParse() {
0 commit comments