yaml2coff/elf: Touchup for compatibility.

* std::string::append(int, int) can be ambiguous.
* std::vector<>::data() is a C++11 feature, use ArrayRef abstraction.

llvm-svn: 192542
This commit is contained in:
Will Dietz 2013-10-12 21:29:16 +00:00
parent ebcc0a004b
commit 0b48c738e6
2 changed files with 10 additions and 8 deletions

View File

@ -32,7 +32,7 @@ struct COFFParser {
COFFParser(COFFYAML::Object &Obj) : Obj(Obj) { COFFParser(COFFYAML::Object &Obj) : Obj(Obj) {
// A COFF string table always starts with a 4 byte size field. Offsets into // A COFF string table always starts with a 4 byte size field. Offsets into
// it include this size, so allocate it now. // it include this size, so allocate it now.
StringTable.append(4, 0); StringTable.append(4, char(0));
} }
bool parseSections() { bool parseSections() {

View File

@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "yaml2obj.h" #include "yaml2obj.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ELFYAML.h" #include "llvm/Object/ELFYAML.h"
#include "llvm/Support/ELF.h" #include "llvm/Support/ELF.h"
@ -119,13 +120,13 @@ public:
} // end anonymous namespace } // end anonymous namespace
template <class T> template <class T>
static size_t vectorDataSize(const std::vector<T> &Vec) { static size_t arrayDataSize(ArrayRef<T> A) {
return Vec.size() * sizeof(T); return A.size() * sizeof(T);
} }
template <class T> template <class T>
static void writeVectorData(raw_ostream &OS, const std::vector<T> &Vec) { static void writeArrayData(raw_ostream &OS, ArrayRef<T> A) {
OS.write((const char *)Vec.data(), vectorDataSize(Vec)); OS.write((const char *)A.data(), arrayDataSize(A));
} }
template <class T> template <class T>
@ -235,8 +236,9 @@ handleSymtabSectionHeader(const ELFYAML::LocalGlobalWeakSymbols &Symbols,
addSymbols(Symbols.Weak, State, Syms, ELF::STB_WEAK); addSymbols(Symbols.Weak, State, Syms, ELF::STB_WEAK);
ContiguousBlobAccumulator &CBA = State.getSectionContentAccum(); ContiguousBlobAccumulator &CBA = State.getSectionContentAccum();
writeVectorData(CBA.getOSAndAlignedOffset(SHeader.sh_offset), Syms); writeArrayData(CBA.getOSAndAlignedOffset(SHeader.sh_offset),
SHeader.sh_size = vectorDataSize(Syms); makeArrayRef(Syms));
SHeader.sh_size = arrayDataSize(makeArrayRef(Syms));
} }
template <class ELFT> template <class ELFT>
@ -359,7 +361,7 @@ static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) {
SHeaders.push_back(SHStrTabSHeader); SHeaders.push_back(SHStrTabSHeader);
OS.write((const char *)&Header, sizeof(Header)); OS.write((const char *)&Header, sizeof(Header));
writeVectorData(OS, SHeaders); writeArrayData(OS, makeArrayRef(SHeaders));
CBA.writeBlobToStream(OS); CBA.writeBlobToStream(OS);
return 0; return 0;
} }