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

Side by Side Diff: src/IceELFSection.cpp

Issue 828873002: Subzero: Start writing out some relocation sections (text) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: review fixes 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 unified diff | Download patch
« no previous file with comments | « src/IceELFSection.h ('k') | src/IceFixups.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 19 matching lines...) Expand all
30 // Data sections. 30 // Data sections.
31 31
32 void ELFDataSection::appendData(ELFStreamer &Str, 32 void ELFDataSection::appendData(ELFStreamer &Str,
33 const llvm::StringRef MoreData) { 33 const llvm::StringRef MoreData) {
34 Str.writeBytes(MoreData); 34 Str.writeBytes(MoreData);
35 Header.sh_size += MoreData.size(); 35 Header.sh_size += MoreData.size();
36 } 36 }
37 37
38 // Relocation sections. 38 // Relocation sections.
39 39
40 void ELFRelocationSection::addRelocations(RelocOffsetT BaseOff,
41 const FixupRefList &FixupRefs) {
42 for (const AssemblerFixup *FR : FixupRefs) {
43 Fixups.push_back(*FR);
44 AssemblerFixup &F = Fixups.back();
45 F.set_position(BaseOff + F.position());
46 }
47 }
48
49 size_t ELFRelocationSection::getSectionDataSize(
50 const GlobalContext &Ctx, const ELFSymbolTableSection *SymTab) const {
51 size_t NumWriteableRelocs = 0;
52 for (const AssemblerFixup &Fixup : Fixups) {
53 const ELFSym *Symbol = SymTab->findSymbol(Fixup.symbol(&Ctx));
54 // TODO(jvoung): When the symbol table finally tracks everything,
55 // just use the Fixups.size() as the count, and remove the
56 // SymTab and Ctx params.
57 if (Symbol)
58 ++NumWriteableRelocs;
59 }
60 return NumWriteableRelocs * Header.sh_entsize;
61 }
62
40 // Symbol tables. 63 // Symbol tables.
41 64
42 void ELFSymbolTableSection::createDefinedSym(const IceString &Name, 65 void ELFSymbolTableSection::createDefinedSym(const IceString &Name,
43 uint8_t Type, uint8_t Binding, 66 uint8_t Type, uint8_t Binding,
44 ELFSection *Section, 67 ELFSection *Section,
45 RelocOffsetT Offset, SizeT Size) { 68 RelocOffsetT Offset, SizeT Size) {
46 ELFSym NewSymbol = ELFSym(); 69 ELFSym NewSymbol = ELFSym();
47 NewSymbol.Sym.setBindingAndType(Binding, Type); 70 NewSymbol.Sym.setBindingAndType(Binding, Type);
48 NewSymbol.Sym.st_value = Offset; 71 NewSymbol.Sym.st_value = Offset;
49 NewSymbol.Sym.st_size = Size; 72 NewSymbol.Sym.st_size = Size;
73 NewSymbol.Section = Section;
50 NewSymbol.Number = ELFSym::UnknownNumber; 74 NewSymbol.Number = ELFSym::UnknownNumber;
51 SymtabKey Key = {Name, Section};
52 bool Unique; 75 bool Unique;
53 if (Type == STB_LOCAL) 76 if (Type == STB_LOCAL)
54 Unique = LocalSymbols.insert(std::make_pair(Key, NewSymbol)).second; 77 Unique = LocalSymbols.insert(std::make_pair(Name, NewSymbol)).second;
55 else 78 else
56 Unique = GlobalSymbols.insert(std::make_pair(Key, NewSymbol)).second; 79 Unique = GlobalSymbols.insert(std::make_pair(Name, NewSymbol)).second;
57 assert(Unique); 80 assert(Unique);
58 (void)Unique; 81 (void)Unique;
59 } 82 }
60 83
61 void ELFSymbolTableSection::noteUndefinedSym(const IceString &Name, 84 void ELFSymbolTableSection::noteUndefinedSym(const IceString &Name,
62 ELFSection *NullSection) { 85 ELFSection *NullSection) {
63 ELFSym NewSymbol = ELFSym(); 86 ELFSym NewSymbol = ELFSym();
64 NewSymbol.Sym.setBindingAndType(STB_GLOBAL, STT_NOTYPE); 87 NewSymbol.Sym.setBindingAndType(STB_GLOBAL, STT_NOTYPE);
88 NewSymbol.Section = NullSection;
65 NewSymbol.Number = ELFSym::UnknownNumber; 89 NewSymbol.Number = ELFSym::UnknownNumber;
66 SymtabKey Key = {Name, NullSection}; 90 GlobalSymbols.insert(std::make_pair(Name, NewSymbol));
67 GlobalSymbols.insert(std::make_pair(Key, NewSymbol)); 91 }
92
93 const ELFSym *ELFSymbolTableSection::findSymbol(const IceString &Name) const {
94 auto I = LocalSymbols.find(Name);
95 if (I != LocalSymbols.end())
96 return &I->second;
97 I = GlobalSymbols.find(Name);
98 if (I != GlobalSymbols.end())
99 return &I->second;
100 return nullptr;
68 } 101 }
69 102
70 void ELFSymbolTableSection::updateIndices(const ELFStringTableSection *StrTab) { 103 void ELFSymbolTableSection::updateIndices(const ELFStringTableSection *StrTab) {
71 SizeT SymNumber = 0; 104 SizeT SymNumber = 0;
72 for (auto &KeyValue : LocalSymbols) { 105 for (auto &KeyValue : LocalSymbols) {
73 const IceString &Name = KeyValue.first.first; 106 const IceString &Name = KeyValue.first;
74 ELFSection *Section = KeyValue.first.second; 107 ELFSection *Section = KeyValue.second.Section;
75 Elf64_Sym &SymInfo = KeyValue.second.Sym; 108 Elf64_Sym &SymInfo = KeyValue.second.Sym;
76 if (!Name.empty()) 109 if (!Name.empty())
77 SymInfo.st_name = StrTab->getIndex(Name); 110 SymInfo.st_name = StrTab->getIndex(Name);
78 SymInfo.st_shndx = Section->getNumber(); 111 SymInfo.st_shndx = Section->getNumber();
79 KeyValue.second.setNumber(SymNumber++); 112 KeyValue.second.setNumber(SymNumber++);
80 } 113 }
81 for (auto &KeyValue : GlobalSymbols) { 114 for (auto &KeyValue : GlobalSymbols) {
82 const IceString &Name = KeyValue.first.first; 115 const IceString &Name = KeyValue.first;
83 ELFSection *Section = KeyValue.first.second; 116 ELFSection *Section = KeyValue.second.Section;
84 Elf64_Sym &SymInfo = KeyValue.second.Sym; 117 Elf64_Sym &SymInfo = KeyValue.second.Sym;
85 if (!Name.empty()) 118 if (!Name.empty())
86 SymInfo.st_name = StrTab->getIndex(Name); 119 SymInfo.st_name = StrTab->getIndex(Name);
87 SymInfo.st_shndx = Section->getNumber(); 120 SymInfo.st_shndx = Section->getNumber();
88 KeyValue.second.setNumber(SymNumber++); 121 KeyValue.second.setNumber(SymNumber++);
89 } 122 }
90 } 123 }
91 124
92 void ELFSymbolTableSection::writeData(ELFStreamer &Str, bool IsELF64) { 125 void ELFSymbolTableSection::writeData(ELFStreamer &Str, bool IsELF64) {
93 if (IsELF64) { 126 if (IsELF64) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 continue; 184 continue;
152 } 185 }
153 StringIndex.second = StringData.size(); 186 StringIndex.second = StringData.size();
154 std::copy(Cur.begin(), Cur.end(), back_inserter(StringData)); 187 std::copy(Cur.begin(), Cur.end(), back_inserter(StringData));
155 StringData.push_back(0); 188 StringData.push_back(0);
156 Prev = Cur; 189 Prev = Cur;
157 } 190 }
158 } 191 }
159 192
160 } // end of namespace Ice 193 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceELFSection.h ('k') | src/IceFixups.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698