Skip to content

Commit b96269b

Browse files
jrtc27resistor
authored andcommitted
[ELF] Delete dead code used for __cap_relocs in input object files
This should have been cleaned up when CheriCapRelocsSection::addSection had its implementation (and caller) removed. Fixes: ed4dee7 ("[ELF][CHERI] GC old __cap_relocs input section code")
1 parent fa751db commit b96269b

File tree

2 files changed

+0
-131
lines changed

2 files changed

+0
-131
lines changed

lld/ELF/Arch/Cheri.cpp

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -183,133 +183,6 @@ std::string CheriCapRelocLocation::toString(Ctx &ctx) const {
183183
return SymbolAndOffset(section, offset).verboseToString(ctx);
184184
}
185185

186-
template <class ELFT>
187-
void CheriCapRelocsSection::processSection(InputSectionBase *s) {
188-
// TODO: sort by offset (or is that always true?
189-
const auto rels = s->relsOrRelas<ELFT>().relas;
190-
for (auto i = rels.begin(), end = rels.end(); i != end; ++i) {
191-
const auto &locationRel = *i;
192-
++i;
193-
const auto &targetRel = *i;
194-
if ((locationRel.r_offset % entsize) != 0) {
195-
error(
196-
"corrupted __cap_relocs: expected Relocation offset to be a "
197-
"multiple of " +
198-
Twine(entsize) + " but got " + Twine(locationRel.r_offset));
199-
return;
200-
}
201-
constexpr unsigned fieldSize = InMemoryCapRelocEntry<ELFT>::fieldSize;
202-
if (targetRel.r_offset != locationRel.r_offset + fieldSize) {
203-
error("corrupted __cap_relocs: expected target relocation (" +
204-
Twine(targetRel.r_offset) +
205-
" to directly follow location relocation (" +
206-
Twine(locationRel.r_offset) + ")");
207-
return;
208-
}
209-
if (locationRel.r_addend < 0) {
210-
Msg(ctx) << "corrupted __cap_relocs: addend is less than zero in" << *s
211-
<< ": " << Twine(locationRel.r_addend);
212-
return;
213-
}
214-
uint64_t capRelocsOffset = locationRel.r_offset;
215-
assert(capRelocsOffset + entsize <= s->getSize());
216-
if (ctx.arg.emachine == EM_MIPS) {
217-
if (locationRel.getType(ctx.arg.isMips64EL) != R_MIPS_64) {
218-
error("Exptected a R_MIPS_64 relocation in __cap_relocs but got " +
219-
toString(locationRel.getType(ctx.arg.isMips64EL)));
220-
continue;
221-
}
222-
if (targetRel.getType(ctx.arg.isMips64EL) != R_MIPS_64) {
223-
error("Exptected a R_MIPS_64 relocation in __cap_relocs but got " +
224-
toString(targetRel.getType(ctx.arg.isMips64EL)));
225-
continue;
226-
}
227-
} else {
228-
if (locationRel.getType(ctx.arg.isMips64EL) !=
229-
*ctx.target->absPointerRel) {
230-
error(
231-
"Exptected an absolute pointer relocation in __cap_relocs "
232-
"but got " +
233-
toString(locationRel.getType(ctx.arg.isMips64EL)));
234-
continue;
235-
}
236-
if (targetRel.getType(ctx.arg.isMips64EL) != *ctx.target->absPointerRel) {
237-
error(
238-
"Exptected an absolute pointer relocation in __cap_relocs "
239-
"but got " +
240-
toString(targetRel.getType(ctx.arg.isMips64EL)));
241-
continue;
242-
}
243-
}
244-
Symbol *locationSym = &s->getFile<ELFT>()->getRelocTargetSym(locationRel);
245-
Symbol &targetSym = s->getFile<ELFT>()->getRelocTargetSym(targetRel);
246-
247-
if (locationSym->file != s->file) {
248-
Err(ctx) << "Expected capability relocation to point to " << *s->file
249-
<< " but got " << *locationSym->file;
250-
continue;
251-
}
252-
// errs() << "Adding cap reloc at " << toString(LocationSym) << " type "
253-
// << Twine((int)LocationSym.Type) << " against "
254-
// << toString(TargetSym) << "\n";
255-
auto *rawInput = reinterpret_cast<const InMemoryCapRelocEntry<ELFT> *>(
256-
s->content().begin() + capRelocsOffset);
257-
int64_t targetCapabilityOffset = (int64_t)rawInput->offset;
258-
assert(rawInput->size == 0 &&
259-
"Clang should not have set size in __cap_relocs");
260-
if (!isa<Defined>(locationSym)) {
261-
error("Unhandled symbol kind for cap_reloc: " +
262-
Twine(locationSym->kind()));
263-
continue;
264-
}
265-
266-
const SymbolAndOffset relocLocation{locationSym, locationRel.r_addend};
267-
const SymbolAndOffset relocTarget{&targetSym, targetRel.r_addend};
268-
SymbolAndOffset realLocation = relocLocation.findRealSymbol(ctx);
269-
SymbolAndOffset realTarget = relocTarget.findRealSymbol(ctx);
270-
if (ctx.arg.verboseCapRelocs) {
271-
message("Adding capability relocation at " +
272-
realLocation.verboseToString(ctx) + "\nagainst " +
273-
realTarget.verboseToString(ctx));
274-
}
275-
276-
bool targetNeedsDynReloc = false;
277-
if (targetSym.isPreemptible) {
278-
// Do we need this?
279-
// TargetNeedsDynReloc = true;
280-
}
281-
switch (targetSym.kind()) {
282-
case Symbol::DefinedKind:
283-
break;
284-
case Symbol::SharedKind:
285-
if (!hasDynamicLinker(ctx)) {
286-
error(
287-
"cannot create a capability relocation against a shared symbol"
288-
" when linking statically");
289-
continue;
290-
}
291-
targetNeedsDynReloc = true;
292-
break;
293-
case Symbol::UndefinedKind:
294-
// addCapReloc() will add an error if we are building an executable
295-
// instead of a shlib
296-
// TODO: we really should add a dynamic SIZE relocation as well
297-
targetNeedsDynReloc = true;
298-
break;
299-
default:
300-
error("Unhandled symbol kind for cap_reloc target: " +
301-
Twine(targetSym.kind()));
302-
continue;
303-
}
304-
assert(locationSym->isSection());
305-
auto *locationDef = cast<Defined>(locationSym);
306-
auto *locationSec = cast<InputSectionBase>(locationDef->section);
307-
addCapReloc<ELFT>({locationSec, (uint64_t)locationRel.r_addend}, realTarget,
308-
targetNeedsDynReloc, targetCapabilityOffset,
309-
realLocation.sym());
310-
}
311-
}
312-
313186
template <class ELFT>
314187
void CheriCapRelocsSection::addCapReloc(CheriCapRelocLocation loc,
315188
const SymbolAndOffset &target,

lld/ELF/Arch/Cheri.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ struct CheriCapReloc {
7676
class CheriCapRelocsSection : public SyntheticSection {
7777
public:
7878
CheriCapRelocsSection(Ctx &ctx, StringRef name);
79-
// Add a __cap_relocs section from in input object file
80-
template <class ELFT>
81-
void addSection(InputSectionBase *s);
8279
bool isNeeded() const override { return !relocsMap.empty(); }
8380
size_t getSize() const override { return relocsMap.size() * entsize; }
8481
void writeTo(uint8_t *buf) override;
@@ -89,7 +86,6 @@ class CheriCapRelocsSection : public SyntheticSection {
8986

9087
private:
9188
template <class ELFT> void writeToImpl(uint8_t *);
92-
template <class ELFT> void processSection(InputSectionBase *s);
9389
bool addEntry(CheriCapRelocLocation loc, CheriCapReloc relocation) {
9490
auto it = relocsMap.insert(std::make_pair(loc, relocation));
9591
// assert(it.first->second == Relocation);

0 commit comments

Comments
 (0)