mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-07-23 01:30:19 +00:00
[yaml2obj][ELF] Align section contents in the output.
The improperly aligned section content in the output was causing buildbot failures. This should fix them. Incidentally, this results in a simpler and more robust API for ContiguousBlobAccumulator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184621 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
529616299f
commit
e766884193
@ -72,11 +72,23 @@ class ContiguousBlobAccumulator {
|
|||||||
SmallVector<char, 128> Buf;
|
SmallVector<char, 128> Buf;
|
||||||
raw_svector_ostream OS;
|
raw_svector_ostream OS;
|
||||||
|
|
||||||
|
/// \returns The new offset.
|
||||||
|
uint64_t padToAlignment(unsigned Align) {
|
||||||
|
uint64_t CurrentOffset = InitialOffset + OS.tell();
|
||||||
|
uint64_t AlignedOffset = RoundUpToAlignment(CurrentOffset, Align);
|
||||||
|
for (; CurrentOffset != AlignedOffset; ++CurrentOffset)
|
||||||
|
OS.write('\0');
|
||||||
|
return AlignedOffset; // == CurrentOffset;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContiguousBlobAccumulator(uint64_t InitialOffset_)
|
ContiguousBlobAccumulator(uint64_t InitialOffset_)
|
||||||
: InitialOffset(InitialOffset_), Buf(), OS(Buf) {}
|
: InitialOffset(InitialOffset_), Buf(), OS(Buf) {}
|
||||||
raw_ostream &getOS() { return OS; }
|
template <class Integer>
|
||||||
uint64_t currentOffset() const { return InitialOffset + OS.tell(); }
|
raw_ostream &getOSAndAlignedOffset(Integer &Offset, unsigned Align = 16) {
|
||||||
|
Offset = padToAlignment(Align);
|
||||||
|
return OS;
|
||||||
|
}
|
||||||
void writeBlobToStream(raw_ostream &Out) { Out << OS.str(); }
|
void writeBlobToStream(raw_ostream &Out) { Out << OS.str(); }
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
@ -128,9 +140,8 @@ static void createStringTableSectionHeader(Elf_Shdr &SHeader,
|
|||||||
StringTableBuilder &STB,
|
StringTableBuilder &STB,
|
||||||
ContiguousBlobAccumulator &CBA) {
|
ContiguousBlobAccumulator &CBA) {
|
||||||
SHeader.sh_type = ELF::SHT_STRTAB;
|
SHeader.sh_type = ELF::SHT_STRTAB;
|
||||||
SHeader.sh_offset = CBA.currentOffset();
|
STB.writeToStream(CBA.getOSAndAlignedOffset(SHeader.sh_offset));
|
||||||
SHeader.sh_size = STB.size();
|
SHeader.sh_size = STB.size();
|
||||||
STB.writeToStream(CBA.getOS());
|
|
||||||
SHeader.sh_addralign = 1;
|
SHeader.sh_addralign = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,9 +235,8 @@ static void handleSymtabSectionHeader(
|
|||||||
addSymbols(Sec.Symbols.Weak, State, Syms, ELF::STB_WEAK);
|
addSymbols(Sec.Symbols.Weak, State, Syms, ELF::STB_WEAK);
|
||||||
|
|
||||||
ContiguousBlobAccumulator &CBA = State.getSectionContentAccum();
|
ContiguousBlobAccumulator &CBA = State.getSectionContentAccum();
|
||||||
SHeader.sh_offset = CBA.currentOffset();
|
writeVectorData(CBA.getOSAndAlignedOffset(SHeader.sh_offset), Syms);
|
||||||
SHeader.sh_size = vectorDataSize(Syms);
|
SHeader.sh_size = vectorDataSize(Syms);
|
||||||
writeVectorData(CBA.getOS(), Syms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
@ -309,9 +319,8 @@ static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) {
|
|||||||
SHeader.sh_flags = Sec.Flags;
|
SHeader.sh_flags = Sec.Flags;
|
||||||
SHeader.sh_addr = Sec.Address;
|
SHeader.sh_addr = Sec.Address;
|
||||||
|
|
||||||
SHeader.sh_offset = CBA.currentOffset();
|
Sec.Content.writeAsBinary(CBA.getOSAndAlignedOffset(SHeader.sh_offset));
|
||||||
SHeader.sh_size = Sec.Content.binary_size();
|
SHeader.sh_size = Sec.Content.binary_size();
|
||||||
Sec.Content.writeAsBinary(CBA.getOS());
|
|
||||||
|
|
||||||
if (!Sec.Link.empty()) {
|
if (!Sec.Link.empty()) {
|
||||||
unsigned Index;
|
unsigned Index;
|
||||||
|
Loading…
Reference in New Issue
Block a user