Skip to content

Commit 1490f38

Browse files
committed
[ELF] Avoid make<ArmCmseSGVeneer>
Store them as unique_ptr in sgVeneers instead.
1 parent 3761b67 commit 1490f38

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,22 +1330,6 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
13301330
});
13311331
}
13321332

1333-
class elf::ArmCmseSGVeneer {
1334-
public:
1335-
ArmCmseSGVeneer(Symbol *sym, Symbol *acleSeSym,
1336-
std::optional<uint64_t> addr = std::nullopt)
1337-
: sym(sym), acleSeSym(acleSeSym), entAddr{addr} {}
1338-
static const size_t size{ACLESESYM_SIZE};
1339-
const std::optional<uint64_t> getAddr() const { return entAddr; };
1340-
1341-
Symbol *sym;
1342-
Symbol *acleSeSym;
1343-
uint64_t offset = 0;
1344-
1345-
private:
1346-
const std::optional<uint64_t> entAddr;
1347-
};
1348-
13491333
ArmCmseSGSection::ArmCmseSGSection(Ctx &ctx)
13501334
: SyntheticSection(ctx, llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
13511335
llvm::ELF::SHT_PROGBITS,
@@ -1389,19 +1373,19 @@ void ArmCmseSGSection::addSGVeneer(Symbol *acleSeSym, Symbol *sym) {
13891373
return;
13901374
// Only secure symbols with values equal to that of it's non-secure
13911375
// counterpart needs to be in the .gnu.sgstubs section.
1392-
ArmCmseSGVeneer *ss = nullptr;
1376+
std::unique_ptr<ArmCmseSGVeneer> ss;
13931377
if (ctx.symtab->cmseImportLib.count(sym->getName())) {
13941378
Defined *impSym = ctx.symtab->cmseImportLib[sym->getName()];
1395-
ss = make<ArmCmseSGVeneer>(sym, acleSeSym, impSym->value);
1379+
ss = std::make_unique<ArmCmseSGVeneer>(sym, acleSeSym, impSym->value);
13961380
} else {
1397-
ss = make<ArmCmseSGVeneer>(sym, acleSeSym);
1381+
ss = std::make_unique<ArmCmseSGVeneer>(sym, acleSeSym);
13981382
++newEntries;
13991383
}
1400-
sgVeneers.emplace_back(ss);
1384+
sgVeneers.emplace_back(std::move(ss));
14011385
}
14021386

14031387
void ArmCmseSGSection::writeTo(uint8_t *buf) {
1404-
for (ArmCmseSGVeneer *s : sgVeneers) {
1388+
for (std::unique_ptr<ArmCmseSGVeneer> &s : sgVeneers) {
14051389
uint8_t *p = buf + s->offset;
14061390
write16(ctx, p + 0, 0xe97f); // SG
14071391
write16(ctx, p + 2, 0xe97f);
@@ -1430,8 +1414,8 @@ void ArmCmseSGSection::finalizeContents() {
14301414

14311415
auto it =
14321416
std::stable_partition(sgVeneers.begin(), sgVeneers.end(),
1433-
[](auto *i) { return i->getAddr().has_value(); });
1434-
std::sort(sgVeneers.begin(), it, [](auto *a, auto *b) {
1417+
[](auto &i) { return i->getAddr().has_value(); });
1418+
std::sort(sgVeneers.begin(), it, [](auto &a, auto &b) {
14351419
return a->getAddr().value() < b->getAddr().value();
14361420
});
14371421
// This is the partition of the veneers with fixed addresses.
@@ -1441,13 +1425,12 @@ void ArmCmseSGSection::finalizeContents() {
14411425
// Check if the start address of '.gnu.sgstubs' correspond to the
14421426
// linker-synthesized veneer with the lowest address.
14431427
if ((getVA() & ~1) != (addr & ~1)) {
1444-
ErrAlways(ctx)
1428+
Err(ctx)
14451429
<< "start address of '.gnu.sgstubs' is different from previous link";
14461430
return;
14471431
}
14481432

1449-
for (size_t i = 0; i < sgVeneers.size(); ++i) {
1450-
ArmCmseSGVeneer *s = sgVeneers[i];
1433+
for (auto [i, s] : enumerate(sgVeneers)) {
14511434
s->offset = i * s->size;
14521435
Defined(ctx, file, StringRef(), s->sym->binding, s->sym->stOther,
14531436
s->sym->type, s->offset | 1, s->size, this)

lld/ELF/SyntheticSections.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,21 @@ class ThunkSection final : public SyntheticSection {
13001300
const char ACLESESYM_PREFIX[] = "__acle_se_";
13011301
const int ACLESESYM_SIZE = 8;
13021302

1303-
class ArmCmseSGVeneer;
1303+
class ArmCmseSGVeneer {
1304+
public:
1305+
ArmCmseSGVeneer(Symbol *sym, Symbol *acleSeSym,
1306+
std::optional<uint64_t> addr = std::nullopt)
1307+
: sym(sym), acleSeSym(acleSeSym), entAddr{addr} {}
1308+
static const size_t size{ACLESESYM_SIZE};
1309+
const std::optional<uint64_t> getAddr() const { return entAddr; };
1310+
1311+
Symbol *sym;
1312+
Symbol *acleSeSym;
1313+
uint64_t offset = 0;
1314+
1315+
private:
1316+
const std::optional<uint64_t> entAddr;
1317+
};
13041318

13051319
class ArmCmseSGSection final : public SyntheticSection {
13061320
public:
@@ -1316,7 +1330,7 @@ class ArmCmseSGSection final : public SyntheticSection {
13161330

13171331
private:
13181332
SmallVector<std::pair<Symbol *, Symbol *>, 0> entries;
1319-
SmallVector<ArmCmseSGVeneer *, 0> sgVeneers;
1333+
SmallVector<std::unique_ptr<ArmCmseSGVeneer>, 0> sgVeneers;
13201334
uint64_t newEntries = 0;
13211335
};
13221336

0 commit comments

Comments
 (0)