Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: src/IceELFSection.cpp

Issue 874353006: Write out global initializers and data rel directly to ELF file. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: misc stuff Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceELFSection.cpp
diff --git a/src/IceELFSection.cpp b/src/IceELFSection.cpp
index 5dcc206df8d61849ba2cd529ceed6967fa366a23..e56137f5548b8deb198c40865e284fcce4b44ee9 100644
--- a/src/IceELFSection.cpp
+++ b/src/IceELFSection.cpp
@@ -11,6 +11,8 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Support/MathExtras.h"
+
#include "IceDefs.h"
#include "IceELFSection.h"
#include "IceELFStreamer.h"
@@ -35,6 +37,34 @@ void ELFDataSection::appendData(ELFStreamer &Str,
Header.sh_size += MoreData.size();
}
+void ELFDataSection::appendZeros(ELFStreamer &Str, SizeT NumBytes) {
+ Str.writeZeroPadding(NumBytes);
+ Header.sh_size += NumBytes;
+}
+
+void ELFDataSection::appendRelocationOffset(ELFStreamer &Str, bool IsRela,
+ RelocOffsetT RelocOffset) {
+ if (IsRela) {
+ appendZeros(Str, RelocAddrSize);
+ return;
+ }
+ static_assert(RelocAddrSize == 4, " writeLE32 assumes RelocAddrSize is 4");
+ Str.writeLE32(RelocOffset);
+ Header.sh_size += RelocAddrSize;
+}
+
+void ELFDataSection::padToAlignment(ELFStreamer &Str, Elf64_Xword Align) {
+ assert(llvm::isPowerOf2_32(Align));
+ Elf64_Xword Mod = Header.sh_size & (Align - 1);
+ if (Mod == 0)
+ return;
+ Elf64_Xword AlignDiff = Align - Mod;
Jim Stichnoth 2015/01/27 16:44:55 I've seen this pattern (which I think takes a bit
jvoung (off chromium) 2015/01/28 17:46:22 How about having something like OffsetToAlignment(
+ if (Header.sh_type != llvm::ELF::SHT_NOBITS)
+ Str.writeZeroPadding(AlignDiff);
+ Header.sh_size += AlignDiff;
+ assert((Header.sh_size & (Align - 1)) == 0);
+}
+
// Relocation sections.
void ELFRelocationSection::addRelocations(RelocOffsetT BaseOff,
@@ -73,7 +103,7 @@ void ELFSymbolTableSection::createDefinedSym(const IceString &Name,
NewSymbol.Section = Section;
NewSymbol.Number = ELFSym::UnknownNumber;
bool Unique;
- if (Type == STB_LOCAL)
+ if (Binding == STB_LOCAL)
Unique = LocalSymbols.insert(std::make_pair(Name, NewSymbol)).second;
else
Unique = GlobalSymbols.insert(std::make_pair(Name, NewSymbol)).second;

Powered by Google App Engine
This is Rietveld 408576698