mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 20:23:39 +08:00
Skip some relocations in scanRelocs.
When a tls access is optimized, a group of relocations is converted at a time. We were already skipping relocations that were optimized out in relocate, but not in scanRelocs. This is a small optimization. I got here while working on a patch that will always keep scanRelocs and relocate in sync. llvm-svn: 264048
This commit is contained in:
@@ -258,21 +258,22 @@ template <bool Is64Bits> struct DenseMapInfo<SectionKey<Is64Bits>> {
|
||||
};
|
||||
}
|
||||
|
||||
// Returns the number of relocations processed.
|
||||
template <class ELFT, class RelT>
|
||||
static bool handleTlsRelocation(uint32_t Type, SymbolBody &Body,
|
||||
InputSectionBase<ELFT> &C, RelT &RI) {
|
||||
static unsigned handleTlsRelocation(uint32_t Type, SymbolBody &Body,
|
||||
InputSectionBase<ELFT> &C, RelT &RI) {
|
||||
if (Target->pointsToLocalDynamicGotEntry(Type)) {
|
||||
if (Target->canRelaxTls(Type, nullptr))
|
||||
return true;
|
||||
return 1;
|
||||
if (Out<ELFT>::Got->addTlsIndex())
|
||||
Out<ELFT>::RelaDyn->addReloc({Target->TlsModuleIndexRel,
|
||||
DynamicReloc<ELFT>::Off_LTlsIndex,
|
||||
nullptr});
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!Body.IsTls)
|
||||
return false;
|
||||
return 0;
|
||||
|
||||
if (Target->isTlsGlobalDynamicRel(Type)) {
|
||||
if (!Target->canRelaxTls(Type, &Body)) {
|
||||
@@ -283,12 +284,16 @@ static bool handleTlsRelocation(uint32_t Type, SymbolBody &Body,
|
||||
Out<ELFT>::RelaDyn->addReloc(
|
||||
{Target->TlsOffsetRel, DynamicReloc<ELFT>::Off_GTlsOffset, &Body});
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
if (!Body.isPreemptible())
|
||||
return true;
|
||||
return 1;
|
||||
Out<ELFT>::Got->addEntry(Body);
|
||||
Out<ELFT>::RelaDyn->addReloc(
|
||||
{Target->TlsGotRel, DynamicReloc<ELFT>::Off_Got, false, &Body});
|
||||
return 2;
|
||||
}
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The reason we have to do this early scan is as follows
|
||||
@@ -309,7 +314,8 @@ template <class RelTy>
|
||||
void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C,
|
||||
iterator_range<const RelTy *> Rels) {
|
||||
const elf::ObjectFile<ELFT> &File = *C.getFile();
|
||||
for (const RelTy &RI : Rels) {
|
||||
for (auto I = Rels.begin(), E = Rels.end(); I != E; ++I) {
|
||||
const RelTy &RI = *I;
|
||||
uint32_t SymIndex = RI.getSymbol(Config->Mips64EL);
|
||||
SymbolBody &OrigBody = File.getSymbolBody(SymIndex);
|
||||
SymbolBody &Body = OrigBody.repl();
|
||||
@@ -328,8 +334,10 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C,
|
||||
S->File->IsUsed = true;
|
||||
|
||||
bool Preemptible = Body.isPreemptible();
|
||||
if (handleTlsRelocation<ELFT>(Type, Body, C, RI))
|
||||
if (unsigned Processed = handleTlsRelocation<ELFT>(Type, Body, C, RI)) {
|
||||
I += (Processed - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Target->needsDynRelative(Type))
|
||||
Out<ELFT>::RelaDyn->addReloc({Target->RelativeRel, &C, RI.r_offset, true,
|
||||
|
||||
Reference in New Issue
Block a user