diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 4b4d7d6db93cd5..e83cca31105d48 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -348,7 +348,7 @@ static std::string createFileLineMsg(StringRef path, unsigned line) { template static std::string getSrcMsgAux(ObjFile &file, const Symbol &sym, - InputSectionBase &sec, uint64_t offset) { + const InputSectionBase &sec, uint64_t offset) { // In DWARF, functions and variables are stored to different places. // First, look up a function for a given offset. if (std::optional info = file.getDILineInfo(&sec, offset)) @@ -363,7 +363,7 @@ static std::string getSrcMsgAux(ObjFile &file, const Symbol &sym, return std::string(file.sourceFile); } -std::string InputFile::getSrcMsg(const Symbol &sym, InputSectionBase &sec, +std::string InputFile::getSrcMsg(const Symbol &sym, const InputSectionBase &sec, uint64_t offset) { if (kind() != ObjKind) return ""; @@ -474,8 +474,8 @@ ObjFile::getVariableLoc(StringRef name) { // Returns source line information for a given offset // using DWARF debug info. template -std::optional ObjFile::getDILineInfo(InputSectionBase *s, - uint64_t offset) { +std::optional +ObjFile::getDILineInfo(const InputSectionBase *s, uint64_t offset) { // Detect SectionIndex for specified section. uint64_t sectionIndex = object::SectionedAddress::UndefSection; ArrayRef sections = s->file->getSections(); @@ -1822,7 +1822,7 @@ template void ObjFile::parseLazy() { } } -bool InputFile::shouldExtractForCommon(StringRef name) { +bool InputFile::shouldExtractForCommon(StringRef name) const { if (isa(this)) return isBitcodeNonCommonDef(mb, name, archiveName); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 41c2ba4e307b36..ab98d78fcf1455 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -101,7 +101,7 @@ class InputFile { // Check if a non-common symbol should be extracted to override a common // definition. - bool shouldExtractForCommon(StringRef name); + bool shouldExtractForCommon(StringRef name) const; // .got2 in the current file. This is used by PPC32 -fPIC/-fPIE to compute // offsets in PLT call stubs. @@ -133,7 +133,7 @@ class InputFile { // True if this is an argument for --just-symbols. Usually false. bool justSymbols = false; - std::string getSrcMsg(const Symbol &sym, InputSectionBase &sec, + std::string getSrcMsg(const Symbol &sym, const InputSectionBase &sec, uint64_t offset); // On PPC64 we need to keep track of which files contain small code model @@ -255,7 +255,8 @@ template class ObjFile : public ELFFileBase { return getSymbol(symIndex); } - std::optional getDILineInfo(InputSectionBase *, uint64_t); + std::optional getDILineInfo(const InputSectionBase *, + uint64_t); std::optional> getVariableLoc(StringRef name); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index e4ce050a789dfb..e6942a928787a5 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -242,7 +242,8 @@ InputSection *InputSectionBase::getLinkOrderDep() const { } // Find a symbol that encloses a given location. -Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset, uint8_t type) { +Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset, + uint8_t type) const { for (Symbol *b : file->getSymbols()) if (Defined *d = dyn_cast(b)) if (d->section == this && d->value <= offset && @@ -252,7 +253,7 @@ Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset, uint8_t type) { } // Returns an object file location string. Used to construct an error message. -std::string InputSectionBase::getLocation(uint64_t offset) { +std::string InputSectionBase::getLocation(uint64_t offset) const { std::string secAndOffset = (name + "+0x" + Twine::utohexstr(offset) + ")").str(); @@ -273,7 +274,8 @@ std::string InputSectionBase::getLocation(uint64_t offset) { // foo.c:42 (/home/alice/possibly/very/long/path/foo.c:42) // // Returns an empty string if there's no way to get line info. -std::string InputSectionBase::getSrcMsg(const Symbol &sym, uint64_t offset) { +std::string InputSectionBase::getSrcMsg(const Symbol &sym, + uint64_t offset) const { return file->getSrcMsg(sym, *this, offset); } @@ -286,7 +288,7 @@ std::string InputSectionBase::getSrcMsg(const Symbol &sym, uint64_t offset) { // or // // path/to/foo.o:(function bar) in archive path/to/bar.a -std::string InputSectionBase::getObjMsg(uint64_t off) { +std::string InputSectionBase::getObjMsg(uint64_t off) const { std::string filename = std::string(file->getName()); std::string archive; diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 7570901b4ef942..fbaea57bd586b0 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -191,15 +191,15 @@ class InputSectionBase : public SectionBase { // 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) { + Defined *getEnclosingSymbol(uint64_t offset, uint8_t type = 0) const; + Defined *getEnclosingFunction(uint64_t offset) const { return getEnclosingSymbol(offset, llvm::ELF::STT_FUNC); } // Returns a source location string. Used to construct an error message. - std::string getLocation(uint64_t offset); - std::string getSrcMsg(const Symbol &sym, uint64_t offset); - std::string getObjMsg(uint64_t offset); + std::string getLocation(uint64_t offset) const; + std::string getSrcMsg(const Symbol &sym, uint64_t offset) const; + std::string getObjMsg(uint64_t offset) const; // Each section knows how to relocate itself. These functions apply // relocations, assuming that Buf points to this section's copy in