Skip to content

Commit ae7fb21

Browse files
committed
[ELF] Make some InputSection/InputFile member functions const. NFC
1 parent b034da7 commit ae7fb21

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static std::string createFileLineMsg(StringRef path, unsigned line) {
348348

349349
template <class ELFT>
350350
static std::string getSrcMsgAux(ObjFile<ELFT> &file, const Symbol &sym,
351-
InputSectionBase &sec, uint64_t offset) {
351+
const InputSectionBase &sec, uint64_t offset) {
352352
// In DWARF, functions and variables are stored to different places.
353353
// First, look up a function for a given offset.
354354
if (std::optional<DILineInfo> info = file.getDILineInfo(&sec, offset))
@@ -363,7 +363,7 @@ static std::string getSrcMsgAux(ObjFile<ELFT> &file, const Symbol &sym,
363363
return std::string(file.sourceFile);
364364
}
365365

366-
std::string InputFile::getSrcMsg(const Symbol &sym, InputSectionBase &sec,
366+
std::string InputFile::getSrcMsg(const Symbol &sym, const InputSectionBase &sec,
367367
uint64_t offset) {
368368
if (kind() != ObjKind)
369369
return "";
@@ -474,8 +474,8 @@ ObjFile<ELFT>::getVariableLoc(StringRef name) {
474474
// Returns source line information for a given offset
475475
// using DWARF debug info.
476476
template <class ELFT>
477-
std::optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *s,
478-
uint64_t offset) {
477+
std::optional<DILineInfo>
478+
ObjFile<ELFT>::getDILineInfo(const InputSectionBase *s, uint64_t offset) {
479479
// Detect SectionIndex for specified section.
480480
uint64_t sectionIndex = object::SectionedAddress::UndefSection;
481481
ArrayRef<InputSectionBase *> sections = s->file->getSections();
@@ -1822,7 +1822,7 @@ template <class ELFT> void ObjFile<ELFT>::parseLazy() {
18221822
}
18231823
}
18241824

1825-
bool InputFile::shouldExtractForCommon(StringRef name) {
1825+
bool InputFile::shouldExtractForCommon(StringRef name) const {
18261826
if (isa<BitcodeFile>(this))
18271827
return isBitcodeNonCommonDef(mb, name, archiveName);
18281828

lld/ELF/InputFiles.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class InputFile {
101101

102102
// Check if a non-common symbol should be extracted to override a common
103103
// definition.
104-
bool shouldExtractForCommon(StringRef name);
104+
bool shouldExtractForCommon(StringRef name) const;
105105

106106
// .got2 in the current file. This is used by PPC32 -fPIC/-fPIE to compute
107107
// offsets in PLT call stubs.
@@ -133,7 +133,7 @@ class InputFile {
133133
// True if this is an argument for --just-symbols. Usually false.
134134
bool justSymbols = false;
135135

136-
std::string getSrcMsg(const Symbol &sym, InputSectionBase &sec,
136+
std::string getSrcMsg(const Symbol &sym, const InputSectionBase &sec,
137137
uint64_t offset);
138138

139139
// On PPC64 we need to keep track of which files contain small code model
@@ -255,7 +255,8 @@ template <class ELFT> class ObjFile : public ELFFileBase {
255255
return getSymbol(symIndex);
256256
}
257257

258-
std::optional<llvm::DILineInfo> getDILineInfo(InputSectionBase *, uint64_t);
258+
std::optional<llvm::DILineInfo> getDILineInfo(const InputSectionBase *,
259+
uint64_t);
259260
std::optional<std::pair<std::string, unsigned>>
260261
getVariableLoc(StringRef name);
261262

lld/ELF/InputSection.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ InputSection *InputSectionBase::getLinkOrderDep() const {
242242
}
243243

244244
// Find a symbol that encloses a given location.
245-
Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset, uint8_t type) {
245+
Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset,
246+
uint8_t type) const {
246247
for (Symbol *b : file->getSymbols())
247248
if (Defined *d = dyn_cast<Defined>(b))
248249
if (d->section == this && d->value <= offset &&
@@ -252,7 +253,7 @@ Defined *InputSectionBase::getEnclosingSymbol(uint64_t offset, uint8_t type) {
252253
}
253254

254255
// Returns an object file location string. Used to construct an error message.
255-
std::string InputSectionBase::getLocation(uint64_t offset) {
256+
std::string InputSectionBase::getLocation(uint64_t offset) const {
256257
std::string secAndOffset =
257258
(name + "+0x" + Twine::utohexstr(offset) + ")").str();
258259

@@ -273,7 +274,8 @@ std::string InputSectionBase::getLocation(uint64_t offset) {
273274
// foo.c:42 (/home/alice/possibly/very/long/path/foo.c:42)
274275
//
275276
// Returns an empty string if there's no way to get line info.
276-
std::string InputSectionBase::getSrcMsg(const Symbol &sym, uint64_t offset) {
277+
std::string InputSectionBase::getSrcMsg(const Symbol &sym,
278+
uint64_t offset) const {
277279
return file->getSrcMsg(sym, *this, offset);
278280
}
279281

@@ -286,7 +288,7 @@ std::string InputSectionBase::getSrcMsg(const Symbol &sym, uint64_t offset) {
286288
// or
287289
//
288290
// path/to/foo.o:(function bar) in archive path/to/bar.a
289-
std::string InputSectionBase::getObjMsg(uint64_t off) {
291+
std::string InputSectionBase::getObjMsg(uint64_t off) const {
290292
std::string filename = std::string(file->getName());
291293

292294
std::string archive;

lld/ELF/InputSection.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ class InputSectionBase : public SectionBase {
191191

192192
// Get a symbol that encloses this offset from within the section. If type is
193193
// 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) {
194+
Defined *getEnclosingSymbol(uint64_t offset, uint8_t type = 0) const;
195+
Defined *getEnclosingFunction(uint64_t offset) const {
196196
return getEnclosingSymbol(offset, llvm::ELF::STT_FUNC);
197197
}
198198

199199
// Returns a source location string. Used to construct an error message.
200-
std::string getLocation(uint64_t offset);
201-
std::string getSrcMsg(const Symbol &sym, uint64_t offset);
202-
std::string getObjMsg(uint64_t offset);
200+
std::string getLocation(uint64_t offset) const;
201+
std::string getSrcMsg(const Symbol &sym, uint64_t offset) const;
202+
std::string getObjMsg(uint64_t offset) const;
203203

204204
// Each section knows how to relocate itself. These functions apply
205205
// relocations, assuming that Buf points to this section's copy in

0 commit comments

Comments
 (0)