llvm.org GIT mirror llvm / 96ddcce
[RuntimeDyld] Don't allocate unnecessary stub buffer space Summary: For relocation types that are known to not require stub functions, there is no need to allocate extra space for the stub functions. Reviewers: lhames, reames, maksfb Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14676 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253920 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 3 years ago
7 changed file(s) with 81 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
431431 if (!(RelSecI == Section))
432432 continue;
433433
434 for (const RelocationRef &Reloc : SI->relocations()) {
435 (void)Reloc;
436 StubBufSize += StubSize;
437 }
434 for (const RelocationRef &Reloc : SI->relocations())
435 if (relocationNeedsStub(Reloc))
436 StubBufSize += StubSize;
438437 }
439438
440439 // Get section data size and alignment
18501850 return Obj.isELF();
18511851 }
18521852
1853 bool RuntimeDyldELF::relocationNeedsStub(const RelocationRef &R) const {
1854 if (Arch != Triple::x86_64)
1855 return true; // Conservative answer
1856
1857 switch (R.getType()) {
1858 default:
1859 return true; // Conservative answer
1860
1861
1862 case ELF::R_X86_64_GOTPCREL:
1863 case ELF::R_X86_64_PC32:
1864 case ELF::R_X86_64_PC64:
1865 case ELF::R_X86_64_64:
1866 // We know that these reloation types won't need a stub function. This list
1867 // can be extended as needed.
1868 return false;
1869 }
1870 }
1871
18531872 } // namespace llvm
151151 SmallVector UnregisteredEHFrameSections;
152152 SmallVector RegisteredEHFrameSections;
153153
154 bool relocationNeedsStub(const RelocationRef &R) const override;
155
154156 public:
155157 RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr,
156158 RuntimeDyld::SymbolResolver &Resolver);
415415 // \brief Implementation of the generic part of the loadObject algorithm.
416416 ObjSectionToIDMap loadObjectImpl(const object::ObjectFile &Obj);
417417
418 // \brief Return true if the relocation R may require allocating a stub.
419 virtual bool relocationNeedsStub(const RelocationRef &R) const {
420 return true; // Conservative answer
421 }
422
418423 public:
419424 RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr,
420425 RuntimeDyld::SymbolResolver &Resolver)
0 # RUN: llvm-mc -triple=x86_64-apple-macosx10.10.0 -filetype=obj -o %T/test_ELF_x86_64_StubBuf.o %s
1 # RUN: llvm-rtdyld -print-alloc-requests -triple=x86_64-pc-linux -dummy-extern _g=196608 -verify %T/test_ELF_x86_64_StubBuf.o
2
3 # Compiled from Inputs/ELF/ELF_x86_64_StubBuf.ll
4
5 # CHECK: allocateCodeSection(Size = 42, Alignment = 16, SectionName = __text)
6
7 .section __TEXT,__text,regular,pure_instructions
8 .macosx_version_min 10, 10
9 .globl _f
10 .align 4, 0x90
11 _f: ## @f
12 .cfi_startproc
13 ## BB#0: ## %entry
14 pushq %rax
15 Ltmp0:
16 .cfi_def_cfa_offset 16
17 callq _g
18 callq _g
19 callq _g
20 popq %rax
21 retq
22 .cfi_endproc
23
24
25 .subsections_via_symbols
0 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
1 target triple = "x86_64-apple-macosx10.10.0"
2
3 declare void @g()
4
5 define void @f() {
6 entry:
7 call void @g()
8 call void @g()
9 call void @g()
10 ret void
11 }
131131 cl::ZeroOrMore,
132132 cl::Hidden);
133133
134 static cl::opt
135 PrintAllocationRequests("print-alloc-requests",
136 cl::desc("Print allocation requests made to the memory "
137 "manager by RuntimeDyld"),
138 cl::Hidden);
139
134140 /* *** */
135141
136142 // A trivial memory manager that doesn't do anything fancy, just uses the
210216 unsigned Alignment,
211217 unsigned SectionID,
212218 StringRef SectionName) {
219 if (PrintAllocationRequests)
220 outs() << "allocateCodeSection(Size = " << Size << ", Alignment = "
221 << Alignment << ", SectionName = " << SectionName << ")\n";
222
213223 if (UsePreallocation)
214224 return allocateFromSlab(Size, Alignment, true /* isCode */);
215225
226236 unsigned SectionID,
227237 StringRef SectionName,
228238 bool IsReadOnly) {
239 if (PrintAllocationRequests)
240 outs() << "allocateDataSection(Size = " << Size << ", Alignment = "
241 << Alignment << ", SectionName = " << SectionName << ")\n";
242
229243 if (UsePreallocation)
230244 return allocateFromSlab(Size, Alignment, false /* isCode */);
231245