Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceELFSection.cpp - Representation of ELF sections -----===// | 1 //===- subzero/src/IceELFSection.cpp - Representation of ELF sections -----===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file defines how ELF sections are represented. | 10 // This file defines how ELF sections are represented. |
| 11 // | 11 // |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 #include "llvm/Support/MathExtras.h" | |
| 15 | |
| 14 #include "IceDefs.h" | 16 #include "IceDefs.h" |
| 15 #include "IceELFSection.h" | 17 #include "IceELFSection.h" |
| 16 #include "IceELFStreamer.h" | 18 #include "IceELFStreamer.h" |
| 17 | 19 |
| 18 using namespace llvm::ELF; | 20 using namespace llvm::ELF; |
| 19 | 21 |
| 20 namespace Ice { | 22 namespace Ice { |
| 21 | 23 |
| 24 void ELFSection::padToAlignment(ELFStreamer &Str, bool WritePadding, | |
| 25 Elf64_Xword Align) { | |
| 26 assert(llvm::isPowerOf2_32(Align)); | |
| 27 Elf64_Xword Mod = Header.sh_size & (Align - 1); | |
| 28 if (Mod == 0) | |
| 29 return; | |
| 30 Elf64_Xword AlignDiff = Align - Mod; | |
| 31 if (WritePadding) | |
| 32 Str.writeZeroPadding(AlignDiff); | |
| 33 Header.sh_size += AlignDiff; | |
| 34 assert((Header.sh_size & (Align - 1)) == 0); | |
| 35 } | |
| 36 | |
| 22 // Text sections. | 37 // Text sections. |
| 23 | 38 |
| 24 void ELFTextSection::appendData(ELFStreamer &Str, | 39 void ELFTextSection::appendData(ELFStreamer &Str, |
| 25 const llvm::StringRef MoreData) { | 40 const llvm::StringRef MoreData) { |
| 26 Str.writeBytes(MoreData); | 41 Str.writeBytes(MoreData); |
| 27 Header.sh_size += MoreData.size(); | 42 Header.sh_size += MoreData.size(); |
| 28 } | 43 } |
| 29 | 44 |
| 30 // Data sections. | 45 // Data sections. |
| 31 | 46 |
| 32 void ELFDataSection::appendData(ELFStreamer &Str, | 47 void ELFDataSection::appendData(ELFStreamer &Str, |
| 33 const llvm::StringRef MoreData) { | 48 const llvm::StringRef MoreData) { |
| 34 Str.writeBytes(MoreData); | 49 Str.writeBytes(MoreData); |
| 35 Header.sh_size += MoreData.size(); | 50 Header.sh_size += MoreData.size(); |
| 36 } | 51 } |
| 37 | 52 |
| 53 void ELFDataSection::appendZeros(ELFStreamer &Str, SizeT NumBytes) { | |
| 54 Str.writeZeroPadding(NumBytes); | |
| 55 Header.sh_size += NumBytes; | |
| 56 } | |
| 57 | |
| 58 void ELFDataSection::appendRelocationOffset(ELFStreamer &Str, bool IsRela, | |
| 59 RelocOffsetT RelocOffset) { | |
| 60 if (IsRela) { | |
| 61 appendZeros(Str, RelocAddrSize); | |
| 62 return; | |
| 63 } | |
| 64 Str.writeLE32(RelocOffset); | |
| 65 Header.sh_size += RelocAddrSize; | |
| 66 } | |
| 67 | |
| 38 // Relocation sections. | 68 // Relocation sections. |
| 39 | 69 |
| 40 void ELFRelocationSection::addRelocations(RelocOffsetT BaseOff, | 70 void ELFRelocationSection::addRelocations(RelocOffsetT BaseOff, |
| 41 const FixupRefList &FixupRefs) { | 71 const FixupRefList &FixupRefs) { |
| 42 for (const AssemblerFixup *FR : FixupRefs) { | 72 for (const AssemblerFixup *FR : FixupRefs) { |
| 43 Fixups.push_back(*FR); | 73 Fixups.push_back(*FR); |
| 44 AssemblerFixup &F = Fixups.back(); | 74 AssemblerFixup &F = Fixups.back(); |
| 45 F.set_position(BaseOff + F.position()); | 75 F.set_position(BaseOff + F.position()); |
| 46 } | 76 } |
| 47 } | 77 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 66 uint8_t Type, uint8_t Binding, | 96 uint8_t Type, uint8_t Binding, |
| 67 ELFSection *Section, | 97 ELFSection *Section, |
| 68 RelocOffsetT Offset, SizeT Size) { | 98 RelocOffsetT Offset, SizeT Size) { |
| 69 ELFSym NewSymbol = ELFSym(); | 99 ELFSym NewSymbol = ELFSym(); |
| 70 NewSymbol.Sym.setBindingAndType(Binding, Type); | 100 NewSymbol.Sym.setBindingAndType(Binding, Type); |
| 71 NewSymbol.Sym.st_value = Offset; | 101 NewSymbol.Sym.st_value = Offset; |
| 72 NewSymbol.Sym.st_size = Size; | 102 NewSymbol.Sym.st_size = Size; |
| 73 NewSymbol.Section = Section; | 103 NewSymbol.Section = Section; |
| 74 NewSymbol.Number = ELFSym::UnknownNumber; | 104 NewSymbol.Number = ELFSym::UnknownNumber; |
| 75 bool Unique; | 105 bool Unique; |
| 76 if (Type == STB_LOCAL) | 106 if (Binding == STB_LOCAL) |
|
jvoung (off chromium)
2015/01/27 01:46:28
oops
Jim Stichnoth
2015/01/27 16:44:55
Hmm. Too bad LLVM didn't name the enums that defi
jvoung (off chromium)
2015/01/28 17:46:21
Yeah, and unfortunately LLVM doesn't have a second
| |
| 77 Unique = LocalSymbols.insert(std::make_pair(Name, NewSymbol)).second; | 107 Unique = LocalSymbols.insert(std::make_pair(Name, NewSymbol)).second; |
| 78 else | 108 else |
| 79 Unique = GlobalSymbols.insert(std::make_pair(Name, NewSymbol)).second; | 109 Unique = GlobalSymbols.insert(std::make_pair(Name, NewSymbol)).second; |
| 80 assert(Unique); | 110 assert(Unique); |
| 81 (void)Unique; | 111 (void)Unique; |
| 82 } | 112 } |
| 83 | 113 |
| 84 void ELFSymbolTableSection::noteUndefinedSym(const IceString &Name, | 114 void ELFSymbolTableSection::noteUndefinedSym(const IceString &Name, |
| 85 ELFSection *NullSection) { | 115 ELFSection *NullSection) { |
| 86 ELFSym NewSymbol = ELFSym(); | 116 ELFSym NewSymbol = ELFSym(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 continue; | 214 continue; |
| 185 } | 215 } |
| 186 StringIndex.second = StringData.size(); | 216 StringIndex.second = StringData.size(); |
| 187 std::copy(Cur.begin(), Cur.end(), back_inserter(StringData)); | 217 std::copy(Cur.begin(), Cur.end(), back_inserter(StringData)); |
| 188 StringData.push_back(0); | 218 StringData.push_back(0); |
| 189 Prev = Cur; | 219 Prev = Cur; |
| 190 } | 220 } |
| 191 } | 221 } |
| 192 | 222 |
| 193 } // end of namespace Ice | 223 } // end of namespace Ice |
| OLD | NEW |