Skip to content

Commit d0606c2

Browse files
committed
[ELF] Make .comment have a non-full file
This ensures that SectionBase::file is non-null except InputSection::discarded.
1 parent c331332 commit d0606c2

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
31473147

31483148
// This adds a .comment section containing a version string.
31493149
if (!ctx.arg.relocatable)
3150-
ctx.inputSections.push_back(createCommentSection());
3150+
ctx.inputSections.push_back(createCommentSection(ctx));
31513151

31523152
// Split SHF_MERGE and .eh_frame sections into pieces in preparation for garbage collection.
31533153
splitSections<ELFT>(ctx);

lld/ELF/InputSection.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,6 @@ std::string InputSectionBase::getLocation(uint64_t offset) const {
299299
std::string secAndOffset =
300300
(name + "+0x" + Twine::utohexstr(offset) + ")").str();
301301

302-
// We don't have file for synthetic sections.
303-
if (file == nullptr)
304-
return (ctx.arg.outputFile + ":(" + secAndOffset).str();
305-
306302
std::string filename = toString(file);
307303
if (Defined *d = getEnclosingFunction(offset))
308304
return filename + ":(function " + toString(*d) + ": " + secAndOffset;
@@ -1430,11 +1426,12 @@ MergeInputSection::MergeInputSection(ObjFile<ELFT> &f,
14301426
StringRef name)
14311427
: InputSectionBase(f, header, name, InputSectionBase::Merge) {}
14321428

1433-
MergeInputSection::MergeInputSection(uint64_t flags, uint32_t type,
1429+
MergeInputSection::MergeInputSection(Ctx &ctx, uint64_t flags, uint32_t type,
14341430
uint64_t entsize, ArrayRef<uint8_t> data,
14351431
StringRef name)
1436-
: InputSectionBase(nullptr, flags, type, entsize, /*Link*/ 0, /*Info*/ 0,
1437-
/*Alignment*/ entsize, data, name, SectionBase::Merge) {}
1432+
: InputSectionBase(ctx.internalFile, flags, type, entsize, /*link=*/0,
1433+
/*info=*/0,
1434+
/*alignment=*/entsize, data, name, SectionBase::Merge) {}
14381435

14391436
// This function is called after we obtain a complete list of input sections
14401437
// that need to be linked. This is responsible to split section contents

lld/ELF/InputSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class MergeInputSection : public InputSectionBase {
316316
template <class ELFT>
317317
MergeInputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header,
318318
StringRef name);
319-
MergeInputSection(uint64_t flags, uint32_t type, uint64_t entsize,
319+
MergeInputSection(Ctx &, uint64_t flags, uint32_t type, uint64_t entsize,
320320
ArrayRef<uint8_t> data, StringRef name);
321321

322322
static bool classof(const SectionBase *s) { return s->kind() == Merge; }

lld/ELF/SyntheticSections.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ static ArrayRef<uint8_t> getVersion() {
8787
// With this feature, you can identify LLD-generated binaries easily
8888
// by "readelf --string-dump .comment <file>".
8989
// The returned object is a mergeable string section.
90-
MergeInputSection *elf::createCommentSection() {
91-
auto *sec = make<MergeInputSection>(SHF_MERGE | SHF_STRINGS, SHT_PROGBITS, 1,
92-
getVersion(), ".comment");
90+
MergeInputSection *elf::createCommentSection(Ctx &ctx) {
91+
auto *sec = make<MergeInputSection>(
92+
ctx, SHF_MERGE | SHF_STRINGS, SHT_PROGBITS, 1, getVersion(), ".comment");
9393
sec->splitIntoPieces();
9494
return sec;
9595
}

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ class MemtagGlobalDescriptors final : public SyntheticSection {
14291429

14301430
template <class ELFT> void createSyntheticSections(Ctx &);
14311431
InputSection *createInterpSection(Ctx &);
1432-
MergeInputSection *createCommentSection();
1432+
MergeInputSection *createCommentSection(Ctx &);
14331433
template <class ELFT> void splitSections(Ctx &);
14341434
void combineEhSections(Ctx &);
14351435

0 commit comments

Comments
 (0)