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

Side by Side Diff: src/IceELFObjectWriter.cpp

Issue 948943004: Handle ffunction-sections w/ filetype=obj. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: one dash Created 5 years, 9 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 | « no previous file | tests_lit/llvm2ice_tests/elf_function_sections.ll » ('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/IceELFObjectWriter.cpp - ELF object file writer --------===// 1 //===- subzero/src/IceELFObjectWriter.cpp - ELF object file writer --------===//
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 the writer for ELF relocatable object files. 10 // This file defines the writer for ELF relocatable object files.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 Str.writeZeroPadding(AlignDiff); 211 Str.writeZeroPadding(AlignDiff);
212 OffsetInFile += AlignDiff; 212 OffsetInFile += AlignDiff;
213 return OffsetInFile; 213 return OffsetInFile;
214 } 214 }
215 215
216 void ELFObjectWriter::writeFunctionCode(const IceString &FuncName, 216 void ELFObjectWriter::writeFunctionCode(const IceString &FuncName,
217 bool IsInternal, const Assembler *Asm) { 217 bool IsInternal, const Assembler *Asm) {
218 assert(!SectionNumbersAssigned); 218 assert(!SectionNumbersAssigned);
219 ELFTextSection *Section = nullptr; 219 ELFTextSection *Section = nullptr;
220 ELFRelocationSection *RelSection = nullptr; 220 ELFRelocationSection *RelSection = nullptr;
221 if (TextSections.empty()) { 221 const bool FunctionSections = Ctx.getFlags().getFunctionSections();
222 // TODO(jvoung): handle ffunction-sections. 222 if (TextSections.empty() || FunctionSections) {
223 IceString SectionName = ".text"; 223 IceString SectionName = ".text";
224 if (FunctionSections)
225 SectionName += "." + FuncName;
224 bool IsELF64 = isELF64(Ctx.getTargetArch()); 226 bool IsELF64 = isELF64(Ctx.getTargetArch());
225 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR; 227 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR;
226 // TODO(jvoung): Should be bundle size. Grab it from that target? 228 // TODO(jvoung): Should be bundle size. Grab it from that target?
227 const Elf64_Xword ShAlign = 32; 229 const Elf64_Xword ShAlign = 32;
228 Section = createSection<ELFTextSection>(SectionName, SHT_PROGBITS, ShFlags, 230 Section = createSection<ELFTextSection>(SectionName, SHT_PROGBITS, ShFlags,
229 ShAlign, 0); 231 ShAlign, 0);
230 Elf64_Off OffsetInFile = alignFileOffset(Section->getSectionAlign()); 232 Elf64_Off OffsetInFile = alignFileOffset(Section->getSectionAlign());
231 Section->setFileOffset(OffsetInFile); 233 Section->setFileOffset(OffsetInFile);
232 TextSections.push_back(Section); 234 TextSections.push_back(Section);
233 RelSection = createRelocationSection(IsELF64, Section); 235 RelSection = createRelocationSection(IsELF64, Section);
(...skipping 13 matching lines...) Expand all
247 SymbolType = STT_NOTYPE; 249 SymbolType = STT_NOTYPE;
248 SymbolBinding = STB_LOCAL; 250 SymbolBinding = STB_LOCAL;
249 } else { 251 } else {
250 SymbolType = STT_FUNC; 252 SymbolType = STT_FUNC;
251 SymbolBinding = STB_GLOBAL; 253 SymbolBinding = STB_GLOBAL;
252 } 254 }
253 SymTab->createDefinedSym(FuncName, SymbolType, SymbolBinding, Section, 255 SymTab->createDefinedSym(FuncName, SymbolType, SymbolBinding, Section,
254 OffsetInSection, SymbolSize); 256 OffsetInSection, SymbolSize);
255 StrTab->add(FuncName); 257 StrTab->add(FuncName);
256 258
257 // Create a relocation section for the text section if needed, and copy the 259 // Copy the fixup information from per-function Assembler memory to the
258 // fixup information from per-function Assembler memory to the object 260 // object writer's memory, for writing later.
259 // writer's memory, for writing later.
260 if (!Asm->fixups().empty()) { 261 if (!Asm->fixups().empty()) {
261 RelSection->addRelocations(OffsetInSection, Asm->fixups()); 262 RelSection->addRelocations(OffsetInSection, Asm->fixups());
262 } 263 }
263 } 264 }
264 265
265 namespace { 266 namespace {
266 267
267 ELFObjectWriter::SectionType 268 ELFObjectWriter::SectionType
268 classifyGlobalSection(const VariableDeclaration *Var) { 269 classifyGlobalSection(const VariableDeclaration *Var) {
269 if (Var->getIsConstant()) 270 if (Var->getIsConstant())
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 if (IsELF64) { 610 if (IsELF64) {
610 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), 611 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(),
611 AllSections.size()); 612 AllSections.size());
612 } else { 613 } else {
613 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), 614 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(),
614 AllSections.size()); 615 AllSections.size());
615 } 616 }
616 } 617 }
617 618
618 } // end of namespace Ice 619 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/elf_function_sections.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698