Skip to content

Commit d255a57

Browse files
committed
[NFC] Store signature symbol in ELFObjectFile
Signature symbols are relevant only for sections of type SHT_GROUP and is best tracked at the level of ObjectFile. Remove this member from ELFSection. Addresses part of #629 Signed-off-by: Shankar Easwaran <seaswara@qti.qualcomm.com>
1 parent fb4dcac commit d255a57

5 files changed

Lines changed: 30 additions & 7 deletions

File tree

include/eld/Input/ELFObjectFile.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace eld {
1717

1818
class ELFSection;
19+
class LDSymbol;
1920
class TimingSection;
2021
class RelocMap;
2122

@@ -119,6 +120,20 @@ class ELFObjectFile : public ELFFileBase {
119120
llvm::ArrayRef<std::string>
120121
getSectionAnnotations(const ELFSection &S) const;
121122

123+
void setSectionSignatureSymbol(const ELFSection &S, LDSymbol *Sym) {
124+
if (Sym)
125+
SignatureSymbolForGroupSections[&S] = Sym;
126+
else
127+
SignatureSymbolForGroupSections.erase(&S);
128+
}
129+
130+
LDSymbol *getSectionSignatureSymbol(const ELFSection &S) const {
131+
auto It = SignatureSymbolForGroupSections.find(&S);
132+
if (It == SignatureSymbolForGroupSections.end())
133+
return nullptr;
134+
return It->second;
135+
}
136+
122137
private:
123138
eld::ELFSection *LLVMBCSection = nullptr;
124139
eld::TimingSection *TimingSection = nullptr;
@@ -138,6 +153,8 @@ class ELFObjectFile : public ELFFileBase {
138153
std::unordered_map<const ELFSection *, InputFile *> OldInputFileBySection;
139154
std::unordered_map<const ELFSection *, llvm::SmallVector<std::string, 1>>
140155
SectionAnnotationsBySection;
156+
std::unordered_map<const ELFSection *, LDSymbol *>
157+
SignatureSymbolForGroupSections;
141158
};
142159

143160
} // namespace eld

include/eld/Readers/ELFSection.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,16 @@ class ELFSection : public ELFSectionBase {
204204

205205
void setPaddr(size_t A);
206206

207-
void setSymbol(LDSymbol *S) { Symbol = S; }
207+
void setSignatureSymbol(LDSymbol *S) {
208+
auto *ObjFile = llvm::dyn_cast_or_null<ELFObjectFile>(getInputFile());
209+
assert(ObjFile && "Section symbol must be stored on an ELFObjectFile");
210+
ObjFile->setSectionSignatureSymbol(*this, S);
211+
}
208212

209-
LDSymbol *getSymbol() const { return Symbol; }
213+
LDSymbol *getSignatureSymbol() const {
214+
auto *ObjFile = llvm::dyn_cast_or_null<ELFObjectFile>(getInputFile());
215+
return ObjFile ? ObjFile->getSectionSignatureSymbol(*this) : nullptr;
216+
}
210217

211218
llvm::ArrayRef<const ELFSection *> getGroupSections() const {
212219
auto *ObjFile = llvm::dyn_cast_or_null<ELFObjectFile>(getInputFile());
@@ -320,8 +327,6 @@ class ELFSection : public ELFSectionBase {
320327
uint64_t Offset = ~uint64_t(0);
321328
uint64_t Addr = InvalidAddr;
322329

323-
LDSymbol *Symbol = nullptr;
324-
325330
/// FIXME: These can probably be moved out
326331
bool Wanted = false;
327332
bool WantedInOutput = false;

lib/Object/ObjectBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ ELFSection *ObjectBuilder::mergeSection(GNULDBackend &PGnuldBackend,
141141
// Add all the input sections that were part of the group
142142
for (auto *GroupSection : CurInputSection->getGroupSections())
143143
Target->addSectionsToGroup(GroupSection);
144-
Target->setSymbol(CurInputSection->getSymbol());
144+
Target->setSignatureSymbol(CurInputSection->getSignatureSymbol());
145145
if (!CurInputSection->getOutputSection())
146146
CurInputSection->setOutputSection(Target->getOutputSection());
147147
return Target;

lib/Readers/RelocELFReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ eld::Expected<bool> RelocELFReader<ELFT>::readOneGroup(ELFSection *S) {
294294
// FIXME: Return an error instead!
295295
if (!signatureSymbol)
296296
return false;
297-
S->setSymbol(signatureSymbol->resolveInfo()->outSymbol());
297+
S->setSignatureSymbol(signatureSymbol->resolveInfo()->outSymbol());
298298
return true;
299299
}
300300

lib/Writers/ELFObjectWriter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,8 @@ uint64_t ELFObjectWriter::getSectLink(const ELFSection *S) const {
751751
/// getSectInfo - compute ElfXX_Shdr::sh_info
752752
uint64_t ELFObjectWriter::getSectInfo(ELFSection *CurSection) const {
753753
if (CurSection->isGroupKind())
754-
return ThisModule.getBackend().getSymbolIdx(CurSection->getSymbol());
754+
return ThisModule.getBackend().getSymbolIdx(
755+
CurSection->getSignatureSymbol());
755756

756757
if (llvm::ELF::SHT_SYMTAB == CurSection->getType() ||
757758
llvm::ELF::SHT_DYNSYM == CurSection->getType())

0 commit comments

Comments
 (0)