[PATCH] add targethandler callbacks from DefaultLayout/Writer
Shankar Kalpathi Easwaran
shankarke at gmail.com
Tue Jan 29 22:17:24 PST 2013
================
Comment at: DefaultLayout.h:396
@@ -392,2 +395,3 @@
ErrorOr<const AtomLayout &> DefaultLayout<ELFT>::addAtom(const Atom *atom) {
+ bool isTargetSection = false;
if (const DefinedAtom *definedAtom = dyn_cast<DefinedAtom>(atom)) {
----------------
Michael Spencer wrote:
> The scope of this var is too large.
Removed all occurences of isTargetSection
================
Comment at: DefaultLayout.h:412-415
@@ +411,6 @@
+
+ sectionName = isTargetSection ?
+ _targetHandler.targetLayout().getSectionName(
+ sectionName, contentType, permissions) :
+ getSectionName(sectionName, contentType, permissions);
+
----------------
Michael Spencer wrote:
> Just make getSectionName virtual. TargetLayouts are derived from DefaultTargetLayout. The derived class can just forward to the base class for things it doesn't want to handle.
Done.
================
Comment at: DefaultLayout.h:421-424
@@ -408,3 +420,6 @@
if (_sectionMap.find(sectionKey) == _sectionMap.end()) {
SectionOrder section_order =
+ isTargetSection ? _targetHandler.targetLayout().getSectionOrder(
+ sectionName, contentType, permissions) :
getSectionOrder(sectionName, contentType, permissions);
+
----------------
Michael Spencer wrote:
> Same.
Done.
================
Comment at: DefaultLayout.h:426-430
@@ +425,7 @@
+
+ section =
+ isTargetSection ?
+ _targetHandler.targetLayout().getSection(sectionName, permissions) :
+ new (_allocator) Section<ELFT>(_targetInfo, sectionName, contentType,
+ permissions, section_order);
+
----------------
Michael Spencer wrote:
> Same.
Done.
================
Comment at: DefaultLayout.h:487
@@ -463,3 +486,3 @@
std::stable_sort(_sections.begin(), _sections.end(),
- [](Chunk<ELFT> *A, Chunk<ELFT> *B) {
+ [](Chunk<ELFT> * A, Chunk<ELFT> * B) {
return A->order() < B->order();
----------------
Michael Spencer wrote:
> clang-format messes up here sometimes. No space after *.
Done.
================
Comment at: SectionChunks.h:64
@@ +63,3 @@
+ virtual bool hasOutputSegment() {
+ assert(_sectionKind != K_Target);
+ return false;
----------------
Michael Spencer wrote:
> Needs a message.
Done.
================
Comment at: TargetLayout.h:47
@@ -59,1 +46,3 @@
+ virtual Section<ELFT> *getSection(
+ const StringRef name, DefinedAtom::ContentPermissions permissions) = 0;
----------------
Michael Spencer wrote:
> Don't const qualify StringRef.
Removed all occurences of const StringRef
================
Comment at: Writer.cpp:267-288
@@ -262,19 +266,24 @@
- _Header->e_ident(ELF::EI_CLASS, _targetInfo.is64Bits() ? ELF::ELFCLASS64
- : ELF::ELFCLASS32);
- _Header->e_ident(ELF::EI_DATA, _targetInfo.isLittleEndian()
- ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
- _Header->e_ident(ELF::EI_VERSION, 1);
- _Header->e_ident(ELF::EI_OSABI, 0);
- _Header->e_type(_targetInfo.getOutputType());
- _Header->e_machine(_targetInfo.getOutputMachine());
- _Header->e_version(1);
- _Header->e_entry(0ULL);
- _Header->e_phoff(_programHeader->fileOffset());
- _Header->e_shoff(_shdrtab->fileOffset());
- _Header->e_phentsize(_programHeader->entsize());
- _Header->e_phnum(_programHeader->numHeaders());
- _Header->e_shentsize(_shdrtab->entsize());
- _Header->e_shnum(_shdrtab->numHeaders());
- _Header->e_shstrndx(_shstrtab->ordinal());
+ if (!_targetHandler.doesOverrideHeader()) {
+ _Header->e_ident(ELF::EI_CLASS, _targetInfo.is64Bits() ? ELF::ELFCLASS64 :
+ ELF::ELFCLASS32);
+ _Header->e_ident(ELF::EI_DATA, _targetInfo.isLittleEndian() ?
+ ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
+ _Header->e_ident(ELF::EI_VERSION, 1);
+ _Header->e_ident(ELF::EI_OSABI, 0);
+ _Header->e_type(_targetInfo.getOutputType());
+ _Header->e_machine(_targetInfo.getOutputMachine());
+ _Header->e_version(1);
+ _Header->e_entry(0ULL);
+ _Header->e_phoff(_programHeader->fileOffset());
+ _Header->e_shoff(_shdrtab->fileOffset());
+ _Header->e_phentsize(_programHeader->entsize());
+ _Header->e_phnum(_programHeader->numHeaders());
+ _Header->e_shentsize(_shdrtab->entsize());
+ _Header->e_shnum(_shdrtab->numHeaders());
+ _Header->e_shstrndx(_shstrtab->ordinal());
+ } else {
+ // override the contents of the ELF Header
+ _targetHandler.setHeaderInfo(_Header);
+ }
uint64_t virtualAddr = 0;
----------------
Michael Spencer wrote:
> Same thing about virtual functions here.
This cant be virtual, because its part of the writer.
http://llvm-reviews.chandlerc.com/D350
More information about the llvm-commits
mailing list