Skip to content

Commit

Permalink
[ELF] Remove needsPltAddr in favor of needsCopy
Browse files Browse the repository at this point in the history
needsPltAddr is equivalent to `needsCopy && isFunc`. In many places, it is
equivalent to `needsCopy` because the non-STT_FUNC cases are ruled out.

Reviewed By: ikudrin, peter.smith

Differential Revision: https://reviews.llvm.org/D115603
  • Loading branch information
MaskRay committed Dec 14, 2021
1 parent df44aaa commit b79686c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lld/ELF/Arch/AArch64.cpp
Expand Up @@ -690,11 +690,11 @@ void AArch64BtiPac::writePlt(uint8_t *buf, const Symbol &sym,
};
const uint8_t nopData[] = { 0x1f, 0x20, 0x03, 0xd5 }; // nop

// needsPltAddr indicates a non-ifunc canonical PLT entry whose address may
// needsCopy indicates a non-ifunc canonical PLT entry whose address may
// escape to shared objects. isInIplt indicates a non-preemptible ifunc. Its
// address may escape if referenced by a direct relocation. The condition is
// conservative.
bool hasBti = btiHeader && (sym.needsPltAddr || sym.isInIplt);
bool hasBti = btiHeader && (sym.needsCopy || sym.isInIplt);
if (hasBti) {
memcpy(buf, btiData, sizeof(btiData));
buf += sizeof(btiData);
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/MapFile.cpp
Expand Up @@ -58,7 +58,7 @@ static std::vector<Defined *> getSymbols() {
for (Symbol *b : file->getSymbols())
if (auto *dr = dyn_cast<Defined>(b))
if (!dr->isSection() && dr->section && dr->section->isLive() &&
(dr->file == file || dr->needsPltAddr || dr->section->bss))
(dr->file == file || dr->needsCopy || dr->section->bss))
v.push_back(dr);
return v;
}
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/Relocations.cpp
Expand Up @@ -1626,14 +1626,14 @@ void elf::postScanRelocations() {
replaceWithDefined(
sym, in.plt,
target->pltHeaderSize + target->pltEntrySize * sym.pltIndex, 0);
sym.needsCopy = true;
if (config->emachine == EM_PPC) {
// PPC32 canonical PLT entries are at the beginning of .glink
cast<Defined>(sym).value = in.plt->headerSize;
in.plt->headerSize += 16;
cast<PPC32GlinkSection>(in.plt)->canonical_plts.push_back(&sym);
}
}
sym.needsPltAddr = true;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/Symbols.cpp
Expand Up @@ -120,7 +120,7 @@ static uint64_t getSymVA(const Symbol &sym, int64_t addend) {
// field etc) do the same trick as compiler uses to mark microMIPS
// for CPU - set the less-significant bit.
if (config->emachine == EM_MIPS && isMicroMips() &&
((sym.stOther & STO_MIPS_MICROMIPS) || sym.needsPltAddr))
((sym.stOther & STO_MIPS_MICROMIPS) || sym.needsCopy))
va |= 1;

if (d.isTls() && !config->relocatable) {
Expand Down
13 changes: 4 additions & 9 deletions lld/ELF/Symbols.h
Expand Up @@ -245,17 +245,12 @@ class Symbol {
type(type), stOther(stOther), symbolKind(k), visibility(stOther & 3),
isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind),
exportDynamic(isExportDynamic(k, visibility)), inDynamicList(false),
canInline(false), referenced(false), traced(false), needsPltAddr(false),
isInIplt(false), gotInIgot(false), isPreemptible(false),
used(!config->gcSections), needsTocRestore(false), scriptDefined(false),
needsCopy(false), needsGot(false), needsPlt(false),
hasDirectReloc(false) {}
canInline(false), referenced(false), traced(false), isInIplt(false),
gotInIgot(false), isPreemptible(false), used(!config->gcSections),
needsTocRestore(false), scriptDefined(false), needsCopy(false),
needsGot(false), needsPlt(false), hasDirectReloc(false) {}

public:
// True the symbol should point to its PLT entry.
// For SharedSymbol only.
uint8_t needsPltAddr : 1;

// True if this symbol is in the Iplt sub-section of the Plt and the Igot
// sub-section of the .got.plt or .got.
uint8_t isInIplt : 1;
Expand Down
7 changes: 4 additions & 3 deletions lld/ELF/SyntheticSections.cpp
Expand Up @@ -2175,7 +2175,8 @@ static BssSection *getCommonSec(Symbol *sym) {
static uint32_t getSymSectionIndex(Symbol *sym) {
if (getCommonSec(sym))
return SHN_COMMON;
if (!isa<Defined>(sym) || sym->needsPltAddr)
assert(!(sym->needsCopy && sym->isObject()));
if (!isa<Defined>(sym) || sym->needsCopy)
return SHN_UNDEF;
if (const OutputSection *os = sym->getOutputSection())
return os->sectionIndex >= SHN_LORESERVE ? (uint32_t)SHN_XINDEX
Expand Down Expand Up @@ -2250,7 +2251,7 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *buf) {

for (SymbolTableEntry &ent : symbols) {
Symbol *sym = ent.sym;
if (sym->isInPlt() && sym->needsPltAddr)
if (sym->isInPlt() && sym->needsCopy)
eSym->st_other |= STO_MIPS_PLT;
if (isMicroMips()) {
// We already set the less-significant bit for symbols
Expand All @@ -2261,7 +2262,7 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *buf) {
// like `objdump` will be able to deal with a correct
// symbol position.
if (sym->isDefined() &&
((sym->stOther & STO_MIPS_MICROMIPS) || sym->needsPltAddr)) {
((sym->stOther & STO_MIPS_MICROMIPS) || sym->needsCopy)) {
if (!strTabSec.isDynamic())
eSym->st_value &= ~1;
eSym->st_other |= STO_MIPS_MICROMIPS;
Expand Down

0 comments on commit b79686c

Please sign in to comment.