Skip to content

[NFC][ELF] Rename some ELFWriter methods #109332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions llvm/lib/MC/ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ struct ELFWriter {
: llvm::endianness::big),
Mode(Mode) {}

void WriteWord(uint64_t Word) {
void writeWord(uint64_t Word) {
if (is64Bit())
W.write<uint64_t>(Word);
else
Expand Down Expand Up @@ -197,20 +197,20 @@ struct ELFWriter {
MCSectionELF *createRelocationSection(MCContext &Ctx,
const MCSectionELF &Sec);

void writeSectionHeader(const MCAssembler &Asm);
void writeSectionHeaders(const MCAssembler &Asm);

void writeSectionData(const MCAssembler &Asm, MCSection &Sec);

void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
uint64_t Address, uint64_t Offset, uint64_t Size,
uint32_t Link, uint32_t Info, MaybeAlign Alignment,
uint64_t EntrySize);
void writeSectionHeaderEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
uint64_t Address, uint64_t Offset, uint64_t Size,
uint32_t Link, uint32_t Info,
MaybeAlign Alignment, uint64_t EntrySize);

void writeRelocations(const MCAssembler &Asm, const MCSectionELF &Sec);

uint64_t writeObject(MCAssembler &Asm);
void writeSection(uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
const MCSectionELF &Section);
void writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t Offset,
uint64_t Size, const MCSectionELF &Section);
};
} // end anonymous namespace

Expand Down Expand Up @@ -317,9 +317,9 @@ void ELFWriter::writeHeader(const MCAssembler &Asm) {
W.write<uint16_t>(OWriter.TargetObjectWriter->getEMachine()); // e_machine = target

W.write<uint32_t>(ELF::EV_CURRENT); // e_version
WriteWord(0); // e_entry, no entry point in .o file
WriteWord(0); // e_phoff, no program header for .o
WriteWord(0); // e_shoff = sec hdr table off in bytes
writeWord(0); // e_entry, no entry point in .o file
writeWord(0); // e_phoff, no program header for .o
writeWord(0); // e_shoff = sec hdr table off in bytes

// e_flags = whatever the target wants
W.write<uint32_t>(OWriter.getELFHeaderEFlags());
Expand Down Expand Up @@ -791,20 +791,22 @@ void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec) {
W.OS << toStringRef(Compressed);
}

void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
uint64_t Address, uint64_t Offset,
uint64_t Size, uint32_t Link, uint32_t Info,
MaybeAlign Alignment, uint64_t EntrySize) {
void ELFWriter::writeSectionHeaderEntry(uint32_t Name, uint32_t Type,
uint64_t Flags, uint64_t Address,
uint64_t Offset, uint64_t Size,
uint32_t Link, uint32_t Info,
MaybeAlign Alignment,
uint64_t EntrySize) {
W.write<uint32_t>(Name); // sh_name: index into string table
W.write<uint32_t>(Type); // sh_type
WriteWord(Flags); // sh_flags
WriteWord(Address); // sh_addr
WriteWord(Offset); // sh_offset
WriteWord(Size); // sh_size
writeWord(Flags); // sh_flags
writeWord(Address); // sh_addr
writeWord(Offset); // sh_offset
writeWord(Size); // sh_size
W.write<uint32_t>(Link); // sh_link
W.write<uint32_t>(Info); // sh_info
WriteWord(Alignment ? Alignment->value() : 0); // sh_addralign
WriteWord(EntrySize); // sh_entsize
writeWord(Alignment ? Alignment->value() : 0); // sh_addralign
writeWord(EntrySize); // sh_entsize
}

template <bool Is64>
Expand Down Expand Up @@ -888,8 +890,8 @@ void ELFWriter::writeRelocations(const MCAssembler &Asm,
}
}

void ELFWriter::writeSection(uint32_t GroupSymbolIndex, uint64_t Offset,
uint64_t Size, const MCSectionELF &Section) {
void ELFWriter::writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t Offset,
uint64_t Size, const MCSectionELF &Section) {
uint64_t sh_link = 0;
uint64_t sh_info = 0;

Expand Down Expand Up @@ -936,19 +938,20 @@ void ELFWriter::writeSection(uint32_t GroupSymbolIndex, uint64_t Offset,
sh_link = Sym->getSection().getOrdinal();
}

WriteSecHdrEntry(StrTabBuilder.getOffset(Section.getName()),
Section.getType(), Section.getFlags(), 0, Offset, Size,
sh_link, sh_info, Section.getAlign(),
Section.getEntrySize());
writeSectionHeaderEntry(StrTabBuilder.getOffset(Section.getName()),
Section.getType(), Section.getFlags(), 0, Offset,
Size, sh_link, sh_info, Section.getAlign(),
Section.getEntrySize());
}

void ELFWriter::writeSectionHeader(const MCAssembler &Asm) {
void ELFWriter::writeSectionHeaders(const MCAssembler &Asm) {
const unsigned NumSections = SectionTable.size();

// Null section first.
uint64_t FirstSectionSize =
(NumSections + 1) >= ELF::SHN_LORESERVE ? NumSections + 1 : 0;
WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, std::nullopt, 0);
writeSectionHeaderEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, std::nullopt,
0);

for (const MCSectionELF *Section : SectionTable) {
uint32_t GroupSymbolIndex;
Expand Down Expand Up @@ -1003,7 +1006,7 @@ void ELFWriter::writeSectionHeader(const MCAssembler &Asm) {
}
}

writeSection(GroupSymbolIndex, Offsets.first, Size, *Section);
writeSectionHeader(GroupSymbolIndex, Offsets.first, Size, *Section);
}
}

Expand Down Expand Up @@ -1126,7 +1129,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm) {
const uint64_t SectionHeaderOffset = align(is64Bit() ? Align(8) : Align(4));

// ... then the section header table ...
writeSectionHeader(Asm);
writeSectionHeaders(Asm);

uint16_t NumSections = support::endian::byte_swap<uint16_t>(
(SectionTable.size() + 1 >= ELF::SHN_LORESERVE) ? (uint16_t)ELF::SHN_UNDEF
Expand Down
Loading