[PATCH] D33964: [LLVM][llvm-objcopy] Added basic plumbing to get things started
Jake Ehrlich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 5 15:28:04 PDT 2017
jakehehrlich updated this revision to Diff 105346.
jakehehrlich added a comment.
Fixed some small issues like the comments recommend by James.
Repository:
rL LLVM
https://reviews.llvm.org/D33964
Files:
tools/llvm-objcopy/Object.cpp
Index: tools/llvm-objcopy/Object.cpp
===================================================================
--- tools/llvm-objcopy/Object.cpp
+++ tools/llvm-objcopy/Object.cpp
@@ -55,7 +55,8 @@
}
void Section::writeSection(FileOutputBuffer &Out) const {
- if(Type == SHT_NOBITS) return;
+ if (Type == SHT_NOBITS)
+ return;
uint8_t *Buf = Out.getBufferStart() + Offset;
std::copy(std::begin(Contents), std::end(Contents), Buf);
}
@@ -104,7 +105,10 @@
void Object<ELFT>::readSectionHeaders(const ELFFile<ELFT> &ElfFile) {
uint32_t Index = 0;
for (const auto &Shdr : unwrapOrError(ElfFile.sections())) {
- if (Index == 0) { ++Index; continue; }
+ if (Index == 0) {
+ ++Index;
+ continue;
+ }
if (Shdr.sh_type == SHT_STRTAB)
continue;
ArrayRef<uint8_t> Data;
@@ -121,8 +125,7 @@
Sec->Info = Shdr.sh_info;
Sec->Align = Shdr.sh_addralign;
Sec->EntrySize = Shdr.sh_entsize;
- Sec->Index = Index;
- Index++;
+ Sec->Index = Index++;
SectionNames->addString(Sec->Name);
Sections.push_back(std::move(Sec));
}
@@ -155,7 +158,7 @@
}
template <class ELFT> void Object<ELFT>::sortSections() {
- // Put allocated sections in address order. Maintain ordering as closely as
+ // Put all sections in offset order. Maintain the ordering as closely as
// possible while meeting that demand however.
auto CompareSections = [](const SecPtr &A, const SecPtr &B) {
return A->Offset < B->Offset;
@@ -190,8 +193,10 @@
}
// 'offset' should now be just after all the section data so we should set the
// section header table offset to be exactly here. This spot might not be
- // aligned properlly however so we should align it as needed. This only takes
- // a little bit of tweaking to ensure that the sh_name is 4 byte aligned.
+ // aligned properly however so we should align it as needed. This only takes
+ // a little bit of tweaking to ensure that the sh_name is 4 byte aligned. By
+ // ensuring that that sh_name is aligned we ensure all fields of the section
+ // header are aligned as well.
Offset = alignTo(Offset, sizeof(typename ELFT::Word));
SHOffset = Offset;
}
@@ -245,7 +250,7 @@
template <class ELFT>
void Object<ELFT>::writeSectionHeaders(FileOutputBuffer &Out) const {
uint8_t *Buf = Out.getBufferStart() + SHOffset;
- Elf_Shdr &Shdr = *reinterpret_cast<Elf_Shdr*>(Buf);
+ Elf_Shdr &Shdr = *reinterpret_cast<Elf_Shdr *>(Buf);
Shdr.sh_name = 0;
Shdr.sh_type = SHT_NULL;
Shdr.sh_flags = 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33964.105346.patch
Type: text/x-patch
Size: 2527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170705/a04a42c9/attachment.bin>
More information about the llvm-commits
mailing list