[opt] Hoist the call throuh SymbolBody::getReplacement out of the inline

method to get a SymbolBody and into the callers, and kill now dead
includes.

This removes the need to have the SymbolBody definition when we're
defining the inline method and makes it a better inline method. That was
the only reason for a lot of header includes here. Removing these and
using forward declarations actually uncovers a bunch of cross-header
dependencies that I've fixed while I'm here, and will allow me to
introduce some *important* inline code into Chunks.h that requires the
definition of ObjectFile.

No functionality changed at this point.

Differential Revision: http://reviews.llvm.org/D10789

llvm-svn: 240982
This commit is contained in:
Chandler Carruth 2015-06-29 18:50:11 +00:00
parent 80189d2d15
commit be6e80b012
4 changed files with 20 additions and 8 deletions

View File

@ -58,7 +58,8 @@ void SectionChunk::writeTo(uint8_t *Buf) {
// Apply relocations.
for (const coff_relocation &Rel : Relocs) {
uint8_t *Off = Buf + FileOff + Rel.VirtualAddress;
SymbolBody *Body = File->getSymbolBody(Rel.SymbolTableIndex);
SymbolBody *Body =
File->getSymbolBody(Rel.SymbolTableIndex)->getReplacement();
uint64_t S = cast<Defined>(Body)->getRVA();
uint64_t P = RVA + Rel.VirtualAddress;
switch (Rel.Type) {
@ -85,7 +86,7 @@ void SectionChunk::mark() {
// Mark all symbols listed in the relocation table for this section.
for (const coff_relocation &Rel : Relocs) {
SymbolBody *B = File->getSymbolBody(Rel.SymbolTableIndex);
SymbolBody *B = File->getSymbolBody(Rel.SymbolTableIndex)->getReplacement();
if (auto *D = dyn_cast<DefinedRegular>(B))
D->markLive();
}
@ -114,7 +115,8 @@ void SectionChunk::getBaserels(std::vector<uint32_t> *Res, Defined *ImageBase) {
// address never changes even if image is relocated.
if (Rel.Type != IMAGE_REL_AMD64_ADDR64)
continue;
SymbolBody *Body = File->getSymbolBody(Rel.SymbolTableIndex);
SymbolBody *Body =
File->getSymbolBody(Rel.SymbolTableIndex)->getReplacement();
if (Body == ImageBase)
continue;
Res->push_back(RVA + Rel.VirtualAddress);
@ -186,8 +188,9 @@ bool SectionChunk::equals(const SectionChunk *X) const {
return false;
if (R1.VirtualAddress != R2.VirtualAddress)
return false;
SymbolBody *B1 = File->getSymbolBody(R1.SymbolTableIndex);
SymbolBody *B2 = X->File->getSymbolBody(R2.SymbolTableIndex);
SymbolBody *B1 = File->getSymbolBody(R1.SymbolTableIndex)->getReplacement();
SymbolBody *B2 =
X->File->getSymbolBody(R2.SymbolTableIndex)->getReplacement();
if (B1 == B2)
return true;
auto *D1 = dyn_cast<DefinedRegular>(B1);

View File

@ -10,8 +10,6 @@
#ifndef LLD_COFF_INPUT_FILES_H
#define LLD_COFF_INPUT_FILES_H
#include "Chunks.h"
#include "Symbols.h"
#include "lld/Core/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/LTO/LTOModule.h"
@ -28,6 +26,10 @@ namespace coff {
using llvm::LTOModule;
using llvm::object::Archive;
using llvm::object::COFFObjectFile;
using llvm::object::COFFSymbolRef;
class Chunk;
class SymbolBody;
// The root class of input files.
class InputFile {
@ -102,7 +104,7 @@ public:
// Returns a SymbolBody object for the SymbolIndex'th symbol in the
// underlying object file.
SymbolBody *getSymbolBody(uint32_t SymbolIndex) {
return SparseSymbolBodies[SymbolIndex]->getReplacement();
return SparseSymbolBodies[SymbolIndex];
}
// Returns the underying COFF file.

View File

@ -11,6 +11,7 @@
#include "Driver.h"
#include "Error.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/LTO/LTOCodeGenerator.h"
#include "llvm/Support/Debug.h"

View File

@ -23,6 +23,12 @@ struct LTOCodeGenerator;
namespace lld {
namespace coff {
class Chunk;
class Defined;
class Lazy;
class SymbolBody;
struct Symbol;
// SymbolTable is a bucket of all known symbols, including defined,
// undefined, or lazy symbols (the last one is symbols in archive
// files whose archive members are not yet loaded).