[lld] 56aa727 - [ELF] Add getEnclosingSymbol for code sharing. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 3 13:43:40 PDT 2023
Author: Fangrui Song
Date: 2023-11-03T13:43:28-07:00
New Revision: 56aa72790704a4fd919ac623c37f4c4eebf40919
URL: https://github.com/llvm/llvm-project/commit/56aa72790704a4fd919ac623c37f4c4eebf40919
DIFF: https://github.com/llvm/llvm-project/commit/56aa72790704a4fd919ac623c37f4c4eebf40919.diff
LOG: [ELF] Add getEnclosingSymbol for code sharing. NFC
Added:
Modified:
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
Removed:
################################################################################
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 02394cbae95d557..e4ce050a789dfbb 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -241,12 +241,12 @@ InputSection *InputSectionBase::getLinkOrderDep() const {
return cast<InputSection>(file->getSections()[link]);
}
-// Find a function symbol that encloses a given location.
-Defined *InputSectionBase::getEnclosingFunction(uint64_t offset) {
+// Find a symbol that encloses a given location.
+Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset, uint8_t type) {
for (Symbol *b : file->getSymbols())
if (Defined *d = dyn_cast<Defined>(b))
- if (d->section == this && d->type == STT_FUNC && d->value <= offset &&
- offset < d->value + d->size)
+ if (d->section == this && d->value <= offset &&
+ offset < d->value + d->size && (type == 0 || type == d->type))
return d;
return nullptr;
}
@@ -296,10 +296,8 @@ std::string InputSectionBase::getObjMsg(uint64_t off) {
// Find a symbol that encloses a given location. getObjMsg may be called
// before ObjFile::initSectionsAndLocalSyms where local symbols are
// initialized.
- for (Symbol *b : file->getSymbols())
- if (auto *d = dyn_cast_or_null<Defined>(b))
- if (d->section == this && d->value <= off && off < d->value + d->size)
- return filename + ":(" + toString(*d) + ")" + archive;
+ if (Defined *d = getEnclosingSymbol(off))
+ return filename + ":(" + toString(*d) + ")" + archive;
// If there's no symbol, print out the offset in the section.
return (filename + ":(" + name + "+0x" + utohexstr(off) + ")" + archive)
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 2b91711abba3d14..7570901b4ef9425 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -189,9 +189,12 @@ class InputSectionBase : public SectionBase {
InputSection *getLinkOrderDep() const;
- // Get the function symbol that encloses this offset from within the
- // section.
- Defined *getEnclosingFunction(uint64_t offset);
+ // Get a symbol that encloses this offset from within the section. If type is
+ // not zero, return a symbol with the specified type.
+ Defined *getEnclosingSymbol(uint64_t offset, uint8_t type = 0);
+ Defined *getEnclosingFunction(uint64_t offset) {
+ return getEnclosingSymbol(offset, llvm::ELF::STT_FUNC);
+ }
// Returns a source location string. Used to construct an error message.
std::string getLocation(uint64_t offset);
More information about the llvm-commits
mailing list