[lld] r196890 - Remove data members used for relocations
Rui Ueyama
ruiu at google.com
Mon Dec 9 22:54:13 PST 2013
Author: ruiu
Date: Tue Dec 10 00:54:13 2013
New Revision: 196890
URL: http://llvm.org/viewvc/llvm-project?rev=196890&view=rev
Log:
Remove data members used for relocations
... because they are used only in the function for relocations.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=196890&r1=196889&r2=196890&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Tue Dec 10 00:54:13 2013
@@ -182,7 +182,7 @@ class AtomChunk : public Chunk {
public:
virtual void write(uint8_t *fileBuffer);
- void buildAtomToVirtualAddr(std::map<const Atom *, uint64_t> &atomRva) const;
+ void buildAtomRvaMap(std::map<const Atom *, uint64_t> &atomRva) const;
void applyRelocations(uint8_t *fileBuffer,
std::map<const Atom *, uint64_t> &atomRva,
std::vector<uint64_t> §ionRva,
@@ -491,8 +491,8 @@ void AtomChunk::write(uint8_t *fileBuffe
}
// Add all atoms to the given map. This data will be used to do relocation.
-void AtomChunk::buildAtomToVirtualAddr(
- std::map<const Atom *, uint64_t> &atomRva) const {
+void
+AtomChunk::buildAtomRvaMap(std::map<const Atom *, uint64_t> &atomRva) const {
for (const auto *layout : _atomLayouts)
atomRva[layout->_atom] = layout->_virtualAddr;
}
@@ -861,12 +861,6 @@ private:
// The size of the image on disk. This is basically the sum of all chunks in
// the output file with paddings between them.
uint32_t _imageSizeOnDisk;
-
- // The map from defined atoms to its RVAs. Will be used for relocation.
- std::map<const Atom *, uint64_t> atomRva;
-
- // List of section RVAs. Will be used for relocation.
- std::vector<uint64_t> sectionRva;
};
StringRef customSectionName(const DefinedAtom *atom) {
@@ -964,7 +958,6 @@ void ExecutableWriter::build(const File
setImageSizeOnDisk();
for (SectionChunk *section : sectionChunks) {
- sectionRva.push_back(section->getVirtualAddress());
if (section->getSectionName() == ".text") {
peHeader->setBaseOfCode(section->getVirtualAddress());
setAddressOfEntryPoint(section, peHeader);
@@ -1005,6 +998,20 @@ error_code ExecutableWriter::writeFile(c
/// address. In the second pass, we visit all relocation references to fix
/// up addresses in the buffer.
void ExecutableWriter::applyAllRelocations(uint8_t *bufferStart) {
+ std::map<const Atom *, uint64_t> atomRva;
+ std::vector<uint64_t> sectionRva;
+
+ // Create the list of section start addresses.
+ for (auto &cp : _chunks)
+ if (SectionChunk *section = dyn_cast<SectionChunk>(&*cp))
+ sectionRva.push_back(section->getVirtualAddress());
+
+ // Pass 1
+ for (auto &cp : _chunks)
+ if (AtomChunk *chunk = dyn_cast<AtomChunk>(&*cp))
+ chunk->buildAtomRvaMap(atomRva);
+
+ // Pass 2
for (auto &cp : _chunks)
if (AtomChunk *chunk = dyn_cast<AtomChunk>(&*cp))
chunk->applyRelocations(bufferStart, atomRva, sectionRva,
@@ -1032,7 +1039,6 @@ void ExecutableWriter::addSectionChunk(S
// memory. They are different from positions on disk because sections need
// to be sector-aligned on disk but page-aligned in memory.
chunk->setVirtualAddress(_imageSizeInMemory);
- chunk->buildAtomToVirtualAddr(atomRva);
_imageSizeInMemory =
llvm::RoundUpToAlignment(_imageSizeInMemory + chunk->size(), PAGE_SIZE);
}
More information about the llvm-commits
mailing list