Run clang-format for PECOFF reader/writer code. No other changes.

llvm-svn: 197039
This commit is contained in:
Rui Ueyama 2013-12-11 14:10:25 +00:00
parent 93961d8e2a
commit bb08e62dd6
7 changed files with 62 additions and 65 deletions

View File

@ -93,7 +93,8 @@ private:
class COFFBaseDefinedAtom : public DefinedAtom {
public:
enum class Kind {
File, Internal
File,
Internal
};
virtual const File &file() const { return _file; }
@ -102,7 +103,7 @@ public:
virtual Merge merge() const { return mergeNo; }
virtual Alignment alignment() const { return Alignment(0); }
virtual SectionChoice sectionChoice() const = 0;
virtual StringRef customSectionName() const { return ""; };
virtual StringRef customSectionName() const { return ""; }
virtual SectionPosition sectionPosition() const { return sectionPositionAny; }
virtual DeadStripKind deadStrip() const { return deadStripNormal; }
virtual bool isAlias() const { return false; }
@ -140,7 +141,7 @@ private:
const File &_file;
StringRef _name;
Kind _kind;
std::vector<std::unique_ptr<COFFReference>> _references;
std::vector<std::unique_ptr<COFFReference> > _references;
};
/// This is the root class of the atom read from a file. This class have two
@ -158,10 +159,10 @@ public:
return atom->getKind() == Kind::File;
}
void setAlignment(Alignment val) { _alignment = val; };
void setAlignment(Alignment val) { _alignment = val; }
virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
virtual StringRef customSectionName() const { return _sectionName; };
virtual StringRef customSectionName() const { return _sectionName; }
virtual Scope scope() const { return _scope; }
virtual ContentType contentType() const { return _contentType; }
virtual ContentPermissions permissions() const { return _permissions; }
@ -175,7 +176,7 @@ private:
ContentPermissions _permissions;
uint64_t _ordinal;
Alignment _alignment;
std::vector<std::unique_ptr<COFFReference>> _references;
std::vector<std::unique_ptr<COFFReference> > _references;
};
// A COFFDefinedAtom represents an atom read from a file and has contents.
@ -254,8 +255,8 @@ public:
COFFSharedLibraryAtom(const File &file, uint16_t hint, StringRef symbolName,
StringRef importName, StringRef dllName)
: _file(file), _hint(hint), _mangledName(addImpPrefix(symbolName)),
_importName(importName), _dllName(dllName),
_importTableEntry(nullptr) {}
_importName(importName), _dllName(dllName), _importTableEntry(nullptr) {
}
virtual const File &file() const { return _file; }
uint16_t hint() const { return _hint; }
@ -276,9 +277,7 @@ public:
_importTableEntry = atom;
}
const DefinedAtom *getImportTableEntry() const {
return _importTableEntry;
}
const DefinedAtom *getImportTableEntry() const { return _importTableEntry; }
private:
/// Mangle the symbol name by adding "__imp_" prefix. See the file comment of
@ -303,15 +302,14 @@ private:
//
//===----------------------------------------------------------------------===//
template<typename T, typename U>
template <typename T, typename U>
void addLayoutEdge(T *a, U *b, lld::Reference::Kind kind) {
auto ref = new COFFReference(kind);
ref->setTarget(b);
a->addReference(std::unique_ptr<COFFReference>(ref));
}
template<typename T, typename U>
void connectWithLayoutEdge(T *a, U *b) {
template <typename T, typename U> void connectWithLayoutEdge(T *a, U *b) {
addLayoutEdge(a, b, lld::Reference::kindLayoutAfter);
addLayoutEdge(b, a, lld::Reference::kindLayoutBefore);
}
@ -327,8 +325,7 @@ void connectWithLayoutEdge(T *a, U *b) {
/// GC'ed.
/// - To preserve the order of atmos. We want to emit the atoms in the
/// same order as they appeared in the input object file.
template<typename T>
void connectAtomsWithLayoutEdge(std::vector<T *> &atoms) {
template <typename T> void connectAtomsWithLayoutEdge(std::vector<T *> &atoms) {
if (atoms.size() < 2)
return;
for (auto it = atoms.begin(), e = atoms.end(); it + 1 != e; ++it)

View File

@ -43,11 +43,11 @@ static bool compare(const DefinedAtom *left, const DefinedAtom *right) {
return left->customSectionName().compare(right->customSectionName()) < 0;
}
return left->sectionChoice() == DefinedAtom::sectionCustomRequired &&
right->sectionChoice() != DefinedAtom::sectionCustomRequired;
right->sectionChoice() != DefinedAtom::sectionCustomRequired;
}
class GroupedSectionsPass : public lld::Pass {
public:
public:
virtual void perform(std::unique_ptr<MutableFile> &file) {
auto definedAtoms = file->definedAtoms();
std::stable_sort(definedAtoms.begin(), definedAtoms.end(), compare);

View File

@ -57,7 +57,7 @@ struct Context {
class IdataAtom : public COFFLinkerInternalAtom {
public:
virtual SectionChoice sectionChoice() const { return sectionCustomRequired; }
virtual StringRef customSectionName() const { return ".idata"; };
virtual StringRef customSectionName() const { return ".idata"; }
virtual ContentType contentType() const { return typeData; }
virtual ContentPermissions permissions() const { return permR__; }
@ -98,7 +98,9 @@ public:
: IdataAtom(context, assembleRawContent(contents)),
_sectionName(sectionName) {}
virtual StringRef customSectionName() const { return _sectionName; };
virtual StringRef customSectionName() const {
return _sectionName;
};
private:
std::vector<uint8_t> assembleRawContent(uint32_t contents);

View File

@ -62,8 +62,8 @@ private:
SectionToAtomsT;
public:
FileCOFF(const PECOFFLinkingContext &context, std::unique_ptr<MemoryBuffer> mb,
error_code &ec);
FileCOFF(const PECOFFLinkingContext &context,
std::unique_ptr<MemoryBuffer> mb, error_code &ec);
virtual const atom_collection<DefinedAtom> &defined() const {
return _definedAtoms;
@ -601,9 +601,9 @@ FileCOFF::AtomizeDefinedSymbolsInSection(const coff_section *section,
// Create an atom for the entire section.
if (symbols.empty()) {
ArrayRef<uint8_t> data(secData.data(), secData.size());
auto *atom = new (_alloc)
COFFDefinedAtom(*this, "", sectionName, Atom::scopeTranslationUnit,
type, isComdat, perms, _merge[section], data, _ordinal++);
auto *atom = new (_alloc) COFFDefinedAtom(
*this, "", sectionName, Atom::scopeTranslationUnit, type, isComdat,
perms, _merge[section], data, _ordinal++);
atoms.push_back(atom);
_definedAtomLocations[section][0].push_back(atom);
return error_code::success();
@ -631,8 +631,8 @@ FileCOFF::AtomizeDefinedSymbolsInSection(const coff_section *section,
if (!alias.empty()) {
auto *atom = new (_alloc) COFFDefinedAtom(
*this, alias, sectionName, getScope(*si), type, isComdat,
perms, DefinedAtom::mergeAsWeak, ArrayRef<uint8_t>(), _ordinal++);
*this, alias, sectionName, getScope(*si), type, isComdat, perms,
DefinedAtom::mergeAsWeak, ArrayRef<uint8_t>(), _ordinal++);
atoms.push_back(atom);
_symbolAtom[*si] = atom;
_definedAtomLocations[section][(*si)->Value].push_back(atom);
@ -965,7 +965,8 @@ ReaderCOFF::parseCOFFFile(std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File> > &result) const {
// Parse the memory buffer as PECOFF file.
error_code ec;
std::unique_ptr<FileCOFF> file(new FileCOFF(_PECOFFLinkingContext, std::move(mb), ec));
std::unique_ptr<FileCOFF> file(
new FileCOFF(_PECOFFLinkingContext, std::move(mb), ec));
if (ec)
return ec;

View File

@ -79,8 +79,8 @@
///
/// The above functions do the same thing. fn's content is a JMP instruction to
/// branch to the address pointed by _imp__fn. The latter may be a little bit
/// slower than the former because it will execute the extra JMP instruction, but
/// that's usually negligible.
/// slower than the former because it will execute the extra JMP instruction,
/// but that's usually negligible.
///
/// If a function is dllimport'ed, which is usually done in a header file,
/// mangled name will be used at compile time so the jump table will not be
@ -175,15 +175,14 @@ public:
class FileImportLibrary : public File {
public:
FileImportLibrary(const LinkingContext &context,
std::unique_ptr<MemoryBuffer> mb,
error_code &ec)
std::unique_ptr<MemoryBuffer> mb, error_code &ec)
: File(mb->getBufferIdentifier(), kindSharedLibrary), _context(context) {
const char *buf = mb->getBufferStart();
const char *end = mb->getBufferEnd();
// The size of the string that follows the header.
uint32_t dataSize = *reinterpret_cast<const support::ulittle32_t *>(
buf + offsetof(COFF::ImportHeader, SizeOfData));
buf + offsetof(COFF::ImportHeader, SizeOfData));
// Check if the total size is valid.
if (end - buf != sizeof(COFF::ImportHeader) + dataSize) {
@ -192,14 +191,14 @@ public:
}
uint16_t hint = *reinterpret_cast<const support::ulittle16_t *>(
buf + offsetof(COFF::ImportHeader, OrdinalHint));
buf + offsetof(COFF::ImportHeader, OrdinalHint));
StringRef symbolName(buf + sizeof(COFF::ImportHeader));
StringRef dllName(buf + sizeof(COFF::ImportHeader) + symbolName.size() + 1);
// TypeInfo is a bitfield. The least significant 2 bits are import
// type, followed by 3 bit import name type.
uint16_t typeInfo = *reinterpret_cast<const support::ulittle16_t *>(
buf + offsetof(COFF::ImportHeader, TypeInfo));
buf + offsetof(COFF::ImportHeader, TypeInfo));
int type = typeInfo & 0x3;
int nameType = (typeInfo >> 2) & 0x7;
@ -208,8 +207,8 @@ public:
// have name if it's imported by ordinal.
StringRef importName = symbolNameToImportName(symbolName, nameType);
const COFFSharedLibraryAtom *dataAtom = addSharedLibraryAtom(
hint, symbolName, importName, dllName);
const COFFSharedLibraryAtom *dataAtom =
addSharedLibraryAtom(hint, symbolName, importName, dllName);
if (type == llvm::COFF::IMPORT_CODE)
addDefinedAtom(symbolName, dllName, dataAtom);
@ -235,11 +234,12 @@ public:
virtual const LinkingContext &getLinkingContext() const { return _context; }
private:
const COFFSharedLibraryAtom *
addSharedLibraryAtom(uint16_t hint, StringRef symbolName,
StringRef importName, StringRef dllName) {
auto *atom = new (_alloc) COFFSharedLibraryAtom(
*this, hint, symbolName, importName, dllName);
const COFFSharedLibraryAtom *addSharedLibraryAtom(uint16_t hint,
StringRef symbolName,
StringRef importName,
StringRef dllName) {
auto *atom = new (_alloc)
COFFSharedLibraryAtom(*this, hint, symbolName, importName, dllName);
_sharedLibraryAtoms._atoms.push_back(atom);
return atom;
}
@ -298,7 +298,7 @@ private:
error_code parseCOFFImportLibrary(const LinkingContext &targetInfo,
std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File>> &result) {
std::vector<std::unique_ptr<File> > &result) {
// Check the file magic.
const char *buf = mb->getBufferStart();
const char *end = mb->getBufferEnd();

View File

@ -24,10 +24,9 @@ class File;
namespace coff {
error_code
parseCOFFImportLibrary(const LinkingContext &context,
std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File> > &result);
error_code parseCOFFImportLibrary(const LinkingContext &context,
std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File> > &result);
}
}

View File

@ -147,9 +147,7 @@ public:
_peHeader.SizeOfUninitializedData = size;
}
void setNumberOfSections(uint32_t num) {
_coffHeader.NumberOfSections = num;
}
void setNumberOfSections(uint32_t num) { _coffHeader.NumberOfSections = num; }
void setAddressOfEntryPoint(uint32_t address) {
_peHeader.AddressOfEntryPoint = address;
@ -274,8 +272,8 @@ private:
/// load-time relocation because it may conflict with other DLLs or the
/// executable.
class BaseRelocChunk : public SectionChunk {
typedef std::vector<std::unique_ptr<Chunk>> ChunkVectorT;
typedef std::map<uint64_t, std::vector<uint16_t>> PageOffsetT;
typedef std::vector<std::unique_ptr<Chunk> > ChunkVectorT;
typedef std::map<uint64_t, std::vector<uint16_t> > PageOffsetT;
public:
BaseRelocChunk(ChunkVectorT &chunks)
@ -504,8 +502,8 @@ void AtomChunk::applyRelocations(uint8_t *buffer,
// The 32-bit relative address from the beginning of the section that
// contains the target symbol.
for (int i = 0, e = sectionRva.size(); i < e; ++i) {
if (i == e - 1 ||
(sectionRva[i] <= targetAddr && targetAddr <= sectionRva[i + 1])) {
if (i == e - 1 || (sectionRva[i] <= targetAddr &&
targetAddr <= sectionRva[i + 1])) {
*relocSite32 = targetAddr - sectionRva[i];
break;
}
@ -600,16 +598,16 @@ uint32_t AtomChunk::getDefaultCharacteristics(
return bss | read | write;
assert(atoms.size() > 0);
switch (atoms[0]->permissions()) {
case DefinedAtom::permR__:
return data | read;
case DefinedAtom::permRW_:
return data | read | write;
case DefinedAtom::permR_X:
return code | execute | read;
case DefinedAtom::permRWX:
return code | execute | read | write;
default:
llvm_unreachable("Unsupported permission");
case DefinedAtom::permR__:
return data | read;
case DefinedAtom::permRW_:
return data | read | write;
case DefinedAtom::permR_X:
return code | execute | read;
case DefinedAtom::permRWX:
return code | execute | read | write;
default:
llvm_unreachable("Unsupported permission");
}
}
@ -773,7 +771,7 @@ private:
return calcSectionSize(llvm::COFF::IMAGE_SCN_CNT_CODE);
}
std::vector<std::unique_ptr<Chunk>> _chunks;
std::vector<std::unique_ptr<Chunk> > _chunks;
const PECOFFLinkingContext &_PECOFFLinkingContext;
uint32_t _numSections;