[lld] 1490f38 - [ELF] Avoid make<ArmCmseSGVeneer>
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 21 23:16:10 PST 2024
Author: Fangrui Song
Date: 2024-11-21T23:16:05-08:00
New Revision: 1490f38b2253a10fcb186a18dd2875cbbeb89fd1
URL: https://github.com/llvm/llvm-project/commit/1490f38b2253a10fcb186a18dd2875cbbeb89fd1
DIFF: https://github.com/llvm/llvm-project/commit/1490f38b2253a10fcb186a18dd2875cbbeb89fd1.diff
LOG: [ELF] Avoid make<ArmCmseSGVeneer>
Store them as unique_ptr in sgVeneers instead.
Added:
Modified:
lld/ELF/Arch/ARM.cpp
lld/ELF/SyntheticSections.h
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index c23a2f872d9183..69ec0d34ae1195 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -1330,22 +1330,6 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
});
}
-class elf::ArmCmseSGVeneer {
-public:
- ArmCmseSGVeneer(Symbol *sym, Symbol *acleSeSym,
- std::optional<uint64_t> addr = std::nullopt)
- : sym(sym), acleSeSym(acleSeSym), entAddr{addr} {}
- static const size_t size{ACLESESYM_SIZE};
- const std::optional<uint64_t> getAddr() const { return entAddr; };
-
- Symbol *sym;
- Symbol *acleSeSym;
- uint64_t offset = 0;
-
-private:
- const std::optional<uint64_t> entAddr;
-};
-
ArmCmseSGSection::ArmCmseSGSection(Ctx &ctx)
: SyntheticSection(ctx, llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
llvm::ELF::SHT_PROGBITS,
@@ -1389,19 +1373,19 @@ void ArmCmseSGSection::addSGVeneer(Symbol *acleSeSym, Symbol *sym) {
return;
// Only secure symbols with values equal to that of it's non-secure
// counterpart needs to be in the .gnu.sgstubs section.
- ArmCmseSGVeneer *ss = nullptr;
+ std::unique_ptr<ArmCmseSGVeneer> ss;
if (ctx.symtab->cmseImportLib.count(sym->getName())) {
Defined *impSym = ctx.symtab->cmseImportLib[sym->getName()];
- ss = make<ArmCmseSGVeneer>(sym, acleSeSym, impSym->value);
+ ss = std::make_unique<ArmCmseSGVeneer>(sym, acleSeSym, impSym->value);
} else {
- ss = make<ArmCmseSGVeneer>(sym, acleSeSym);
+ ss = std::make_unique<ArmCmseSGVeneer>(sym, acleSeSym);
++newEntries;
}
- sgVeneers.emplace_back(ss);
+ sgVeneers.emplace_back(std::move(ss));
}
void ArmCmseSGSection::writeTo(uint8_t *buf) {
- for (ArmCmseSGVeneer *s : sgVeneers) {
+ for (std::unique_ptr<ArmCmseSGVeneer> &s : sgVeneers) {
uint8_t *p = buf + s->offset;
write16(ctx, p + 0, 0xe97f); // SG
write16(ctx, p + 2, 0xe97f);
@@ -1430,8 +1414,8 @@ void ArmCmseSGSection::finalizeContents() {
auto it =
std::stable_partition(sgVeneers.begin(), sgVeneers.end(),
- [](auto *i) { return i->getAddr().has_value(); });
- std::sort(sgVeneers.begin(), it, [](auto *a, auto *b) {
+ [](auto &i) { return i->getAddr().has_value(); });
+ std::sort(sgVeneers.begin(), it, [](auto &a, auto &b) {
return a->getAddr().value() < b->getAddr().value();
});
// This is the partition of the veneers with fixed addresses.
@@ -1441,13 +1425,12 @@ void ArmCmseSGSection::finalizeContents() {
// Check if the start address of '.gnu.sgstubs' correspond to the
// linker-synthesized veneer with the lowest address.
if ((getVA() & ~1) != (addr & ~1)) {
- ErrAlways(ctx)
+ Err(ctx)
<< "start address of '.gnu.sgstubs' is
diff erent from previous link";
return;
}
- for (size_t i = 0; i < sgVeneers.size(); ++i) {
- ArmCmseSGVeneer *s = sgVeneers[i];
+ for (auto [i, s] : enumerate(sgVeneers)) {
s->offset = i * s->size;
Defined(ctx, file, StringRef(), s->sym->binding, s->sym->stOther,
s->sym->type, s->offset | 1, s->size, this)
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 163a4950a0983f..cf178411e1eacc 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -1300,7 +1300,21 @@ class ThunkSection final : public SyntheticSection {
const char ACLESESYM_PREFIX[] = "__acle_se_";
const int ACLESESYM_SIZE = 8;
-class ArmCmseSGVeneer;
+class ArmCmseSGVeneer {
+public:
+ ArmCmseSGVeneer(Symbol *sym, Symbol *acleSeSym,
+ std::optional<uint64_t> addr = std::nullopt)
+ : sym(sym), acleSeSym(acleSeSym), entAddr{addr} {}
+ static const size_t size{ACLESESYM_SIZE};
+ const std::optional<uint64_t> getAddr() const { return entAddr; };
+
+ Symbol *sym;
+ Symbol *acleSeSym;
+ uint64_t offset = 0;
+
+private:
+ const std::optional<uint64_t> entAddr;
+};
class ArmCmseSGSection final : public SyntheticSection {
public:
@@ -1316,7 +1330,7 @@ class ArmCmseSGSection final : public SyntheticSection {
private:
SmallVector<std::pair<Symbol *, Symbol *>, 0> entries;
- SmallVector<ArmCmseSGVeneer *, 0> sgVeneers;
+ SmallVector<std::unique_ptr<ArmCmseSGVeneer>, 0> sgVeneers;
uint64_t newEntries = 0;
};
More information about the llvm-commits
mailing list