| 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 |
| 22 // Text sections. | 24 // Text sections. |
| 23 | 25 |
| 24 void ELFTextSection::appendData(ELFStreamer &Str, | 26 void ELFTextSection::appendData(ELFStreamer &Str, |
| 25 const llvm::StringRef MoreData) { | 27 const llvm::StringRef MoreData) { |
| 26 Str.writeBytes(MoreData); | 28 Str.writeBytes(MoreData); |
| 27 Header.sh_size += MoreData.size(); | 29 Header.sh_size += MoreData.size(); |
| 28 } | 30 } |
| 29 | 31 |
| 30 // Data sections. | 32 // Data sections. |
| 31 | 33 |
| 32 void ELFDataSection::appendData(ELFStreamer &Str, | 34 void ELFDataSection::appendData(ELFStreamer &Str, |
| 33 const llvm::StringRef MoreData) { | 35 const llvm::StringRef MoreData) { |
| 34 Str.writeBytes(MoreData); | 36 Str.writeBytes(MoreData); |
| 35 Header.sh_size += MoreData.size(); | 37 Header.sh_size += MoreData.size(); |
| 36 } | 38 } |
| 37 | 39 |
| 40 void ELFDataSection::appendZeros(ELFStreamer &Str, SizeT NumBytes) { |
| 41 Str.writeZeroPadding(NumBytes); |
| 42 Header.sh_size += NumBytes; |
| 43 } |
| 44 |
| 45 void ELFDataSection::appendRelocationOffset(ELFStreamer &Str, bool IsRela, |
| 46 RelocOffsetT RelocOffset) { |
| 47 if (IsRela) { |
| 48 appendZeros(Str, RelocAddrSize); |
| 49 return; |
| 50 } |
| 51 static_assert(RelocAddrSize == 4, " writeLE32 assumes RelocAddrSize is 4"); |
| 52 Str.writeLE32(RelocOffset); |
| 53 Header.sh_size += RelocAddrSize; |
| 54 } |
| 55 |
| 56 void ELFDataSection::padToAlignment(ELFStreamer &Str, Elf64_Xword Align) { |
| 57 assert(llvm::isPowerOf2_32(Align)); |
| 58 Elf64_Xword AlignDiff = Utils::OffsetToAlignment(Header.sh_size, Align); |
| 59 if (AlignDiff == 0) |
| 60 return; |
| 61 if (Header.sh_type != llvm::ELF::SHT_NOBITS) |
| 62 Str.writeZeroPadding(AlignDiff); |
| 63 Header.sh_size += AlignDiff; |
| 64 } |
| 65 |
| 38 // Relocation sections. | 66 // Relocation sections. |
| 39 | 67 |
| 40 void ELFRelocationSection::addRelocations(RelocOffsetT BaseOff, | 68 void ELFRelocationSection::addRelocations(RelocOffsetT BaseOff, |
| 41 const FixupRefList &FixupRefs) { | 69 const FixupRefList &FixupRefs) { |
| 42 for (const AssemblerFixup *FR : FixupRefs) { | 70 for (const AssemblerFixup *FR : FixupRefs) { |
| 43 Fixups.push_back(*FR); | 71 Fixups.push_back(*FR); |
| 44 AssemblerFixup &F = Fixups.back(); | 72 AssemblerFixup &F = Fixups.back(); |
| 45 F.set_position(BaseOff + F.position()); | 73 F.set_position(BaseOff + F.position()); |
| 46 } | 74 } |
| 47 } | 75 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 uint8_t Type, uint8_t Binding, | 94 uint8_t Type, uint8_t Binding, |
| 67 ELFSection *Section, | 95 ELFSection *Section, |
| 68 RelocOffsetT Offset, SizeT Size) { | 96 RelocOffsetT Offset, SizeT Size) { |
| 69 ELFSym NewSymbol = ELFSym(); | 97 ELFSym NewSymbol = ELFSym(); |
| 70 NewSymbol.Sym.setBindingAndType(Binding, Type); | 98 NewSymbol.Sym.setBindingAndType(Binding, Type); |
| 71 NewSymbol.Sym.st_value = Offset; | 99 NewSymbol.Sym.st_value = Offset; |
| 72 NewSymbol.Sym.st_size = Size; | 100 NewSymbol.Sym.st_size = Size; |
| 73 NewSymbol.Section = Section; | 101 NewSymbol.Section = Section; |
| 74 NewSymbol.Number = ELFSym::UnknownNumber; | 102 NewSymbol.Number = ELFSym::UnknownNumber; |
| 75 bool Unique; | 103 bool Unique; |
| 76 if (Type == STB_LOCAL) | 104 if (Binding == STB_LOCAL) |
| 77 Unique = LocalSymbols.insert(std::make_pair(Name, NewSymbol)).second; | 105 Unique = LocalSymbols.insert(std::make_pair(Name, NewSymbol)).second; |
| 78 else | 106 else |
| 79 Unique = GlobalSymbols.insert(std::make_pair(Name, NewSymbol)).second; | 107 Unique = GlobalSymbols.insert(std::make_pair(Name, NewSymbol)).second; |
| 80 assert(Unique); | 108 assert(Unique); |
| 81 (void)Unique; | 109 (void)Unique; |
| 82 } | 110 } |
| 83 | 111 |
| 84 void ELFSymbolTableSection::noteUndefinedSym(const IceString &Name, | 112 void ELFSymbolTableSection::noteUndefinedSym(const IceString &Name, |
| 85 ELFSection *NullSection) { | 113 ELFSection *NullSection) { |
| 86 ELFSym NewSymbol = ELFSym(); | 114 ELFSym NewSymbol = ELFSym(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 continue; | 212 continue; |
| 185 } | 213 } |
| 186 StringIndex.second = StringData.size(); | 214 StringIndex.second = StringData.size(); |
| 187 std::copy(Cur.begin(), Cur.end(), back_inserter(StringData)); | 215 std::copy(Cur.begin(), Cur.end(), back_inserter(StringData)); |
| 188 StringData.push_back(0); | 216 StringData.push_back(0); |
| 189 Prev = Cur; | 217 Prev = Cur; |
| 190 } | 218 } |
| 191 } | 219 } |
| 192 | 220 |
| 193 } // end of namespace Ice | 221 } // end of namespace Ice |
| OLD | NEW |