Skip to content

[NFC] [lld] [MTE] Rename MemtagDescriptors to MemtagGlobalDescriptors #77300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lld/ELF/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ void elf::postScanRelocations() {
return;

if (sym.isTagged() && sym.isDefined())
mainPart->memtagDescriptors->addSymbol(sym);
mainPart->memtagGlobalDescriptors->addSymbol(sym);

if (!sym.needsDynReloc())
return;
Expand Down
22 changes: 12 additions & 10 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,9 +1454,10 @@ DynamicSection<ELFT>::computeContents() {
addInt(DT_AARCH64_MEMTAG_MODE, config->androidMemtagMode == NT_MEMTAG_LEVEL_ASYNC);
addInt(DT_AARCH64_MEMTAG_HEAP, config->androidMemtagHeap);
addInt(DT_AARCH64_MEMTAG_STACK, config->androidMemtagStack);
if (mainPart->memtagDescriptors->isNeeded()) {
addInSec(DT_AARCH64_MEMTAG_GLOBALS, *mainPart->memtagDescriptors);
addInt(DT_AARCH64_MEMTAG_GLOBALSSZ, mainPart->memtagDescriptors->getSize());
if (mainPart->memtagGlobalDescriptors->isNeeded()) {
addInSec(DT_AARCH64_MEMTAG_GLOBALS, *mainPart->memtagGlobalDescriptors);
addInt(DT_AARCH64_MEMTAG_GLOBALSSZ,
mainPart->memtagGlobalDescriptors->getSize());
}
}
}
Expand Down Expand Up @@ -3919,8 +3920,9 @@ static size_t computeOrWriteULEB128(uint64_t v, uint8_t *buf, size_t offset) {
// https://github.com/ARM-software/abi-aa/blob/main/memtagabielf64/memtagabielf64.rst#83encoding-of-sht_aarch64_memtag_globals_dynamic
constexpr uint64_t kMemtagStepSizeBits = 3;
constexpr uint64_t kMemtagGranuleSize = 16;
static size_t createMemtagDescriptors(const SmallVector<const Symbol *, 0> &symbols,
uint8_t *buf = nullptr) {
static size_t
createMemtagGlobalDescriptors(const SmallVector<const Symbol *, 0> &symbols,
uint8_t *buf = nullptr) {
size_t sectionSize = 0;
uint64_t lastGlobalEnd = 0;

Expand Down Expand Up @@ -3961,7 +3963,7 @@ static size_t createMemtagDescriptors(const SmallVector<const Symbol *, 0> &symb
return sectionSize;
}

bool MemtagDescriptors::updateAllocSize() {
bool MemtagGlobalDescriptors::updateAllocSize() {
size_t oldSize = getSize();
std::stable_sort(symbols.begin(), symbols.end(),
[](const Symbol *s1, const Symbol *s2) {
Expand All @@ -3970,12 +3972,12 @@ bool MemtagDescriptors::updateAllocSize() {
return oldSize != getSize();
}

void MemtagDescriptors::writeTo(uint8_t *buf) {
createMemtagDescriptors(symbols, buf);
void MemtagGlobalDescriptors::writeTo(uint8_t *buf) {
createMemtagGlobalDescriptors(symbols, buf);
}

size_t MemtagDescriptors::getSize() const {
return createMemtagDescriptors(symbols);
size_t MemtagGlobalDescriptors::getSize() const {
return createMemtagGlobalDescriptors(symbols);
}

InStruct elf::in;
Expand Down
6 changes: 3 additions & 3 deletions lld/ELF/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,9 @@ class PackageMetadataNote final : public SyntheticSection {
size_t getSize() const override;
};

class MemtagDescriptors final : public SyntheticSection {
class MemtagGlobalDescriptors final : public SyntheticSection {
public:
MemtagDescriptors()
MemtagGlobalDescriptors()
: SyntheticSection(llvm::ELF::SHF_ALLOC,
llvm::ELF::SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC,
/*alignment=*/4, ".memtag.globals.dynamic") {}
Expand Down Expand Up @@ -1315,7 +1315,7 @@ struct Partition {
std::unique_ptr<GnuHashTableSection> gnuHashTab;
std::unique_ptr<HashTableSection> hashTab;
std::unique_ptr<MemtagAndroidNote> memtagAndroidNote;
std::unique_ptr<MemtagDescriptors> memtagDescriptors;
std::unique_ptr<MemtagGlobalDescriptors> memtagGlobalDescriptors;
std::unique_ptr<PackageMetadataNote> packageMetadataNote;
std::unique_ptr<RelocationBaseSection> relaDyn;
std::unique_ptr<RelrBaseSection> relrDyn;
Expand Down
9 changes: 5 additions & 4 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ template <class ELFT> void elf::createSyntheticSections() {
part.memtagAndroidNote = std::make_unique<MemtagAndroidNote>();
add(*part.memtagAndroidNote);
if (canHaveMemtagGlobals()) {
part.memtagDescriptors = std::make_unique<MemtagDescriptors>();
add(*part.memtagDescriptors);
part.memtagGlobalDescriptors =
std::make_unique<MemtagGlobalDescriptors>();
add(*part.memtagGlobalDescriptors);
}
}

Expand Down Expand Up @@ -1731,8 +1732,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
changed |= part.relaDyn->updateAllocSize();
if (part.relrDyn)
changed |= part.relrDyn->updateAllocSize();
if (part.memtagDescriptors)
changed |= part.memtagDescriptors->updateAllocSize();
if (part.memtagGlobalDescriptors)
changed |= part.memtagGlobalDescriptors->updateAllocSize();
}

const Defined *changedSym = script->assignAddresses();
Expand Down