Skip to content

Commit 56aa727

Browse files
committed
[ELF] Add getEnclosingSymbol for code sharing. NFC
1 parent d9dadfd commit 56aa727

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lld/ELF/InputSection.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ InputSection *InputSectionBase::getLinkOrderDep() const {
241241
return cast<InputSection>(file->getSections()[link]);
242242
}
243243

244-
// Find a function symbol that encloses a given location.
245-
Defined *InputSectionBase::getEnclosingFunction(uint64_t offset) {
244+
// Find a symbol that encloses a given location.
245+
Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset, uint8_t type) {
246246
for (Symbol *b : file->getSymbols())
247247
if (Defined *d = dyn_cast<Defined>(b))
248-
if (d->section == this && d->type == STT_FUNC && d->value <= offset &&
249-
offset < d->value + d->size)
248+
if (d->section == this && d->value <= offset &&
249+
offset < d->value + d->size && (type == 0 || type == d->type))
250250
return d;
251251
return nullptr;
252252
}
@@ -296,10 +296,8 @@ std::string InputSectionBase::getObjMsg(uint64_t off) {
296296
// Find a symbol that encloses a given location. getObjMsg may be called
297297
// before ObjFile::initSectionsAndLocalSyms where local symbols are
298298
// initialized.
299-
for (Symbol *b : file->getSymbols())
300-
if (auto *d = dyn_cast_or_null<Defined>(b))
301-
if (d->section == this && d->value <= off && off < d->value + d->size)
302-
return filename + ":(" + toString(*d) + ")" + archive;
299+
if (Defined *d = getEnclosingSymbol(off))
300+
return filename + ":(" + toString(*d) + ")" + archive;
303301

304302
// If there's no symbol, print out the offset in the section.
305303
return (filename + ":(" + name + "+0x" + utohexstr(off) + ")" + archive)

lld/ELF/InputSection.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,12 @@ class InputSectionBase : public SectionBase {
189189

190190
InputSection *getLinkOrderDep() const;
191191

192-
// Get the function symbol that encloses this offset from within the
193-
// section.
194-
Defined *getEnclosingFunction(uint64_t offset);
192+
// Get a symbol that encloses this offset from within the section. If type is
193+
// not zero, return a symbol with the specified type.
194+
Defined *getEnclosingSymbol(uint64_t offset, uint8_t type = 0);
195+
Defined *getEnclosingFunction(uint64_t offset) {
196+
return getEnclosingSymbol(offset, llvm::ELF::STT_FUNC);
197+
}
195198

196199
// Returns a source location string. Used to construct an error message.
197200
std::string getLocation(uint64_t offset);

0 commit comments

Comments
 (0)