[llvm] r250371 - [RuntimeDyld] Don't try to get the contents of sections that don't have any

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 23:41:46 PDT 2015


Author: lhames
Date: Thu Oct 15 01:41:45 2015
New Revision: 250371

URL: http://llvm.org/viewvc/llvm-project?rev=250371&view=rev
Log:
[RuntimeDyld] Don't try to get the contents of sections that don't have any
(e.g. bss sections).

MachO and ELF have been silently letting this pass, but COFFObjectFile contains
an assertion to catch this kind of (ab)use of the getSectionContents, and this
was causing the JIT to crash on COFF objects with BSS sections. This patch
should fix that.

Added:
    llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s
      - copied, changed from r250363, llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64
Removed:
    llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64
Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=250371&r1=250370&r2=250371&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Thu Oct 15 01:41:45 2015
@@ -182,8 +182,6 @@ RuntimeDyldImpl::loadObjectImpl(const ob
           continue;
         uint64_t SectOffset;
         Check(getOffset(*I, *SI, SectOffset));
-        StringRef SectionData;
-        Check(SI->getContents(SectionData));
         bool IsCode = SI->isText();
         unsigned SectionID =
             findOrEmitSection(Obj, *SI, IsCode, LocalSections);
@@ -568,12 +566,14 @@ unsigned RuntimeDyldImpl::emitSection(co
   uint8_t *Addr;
   const char *pData = nullptr;
 
-  // In either case, set the location of the unrelocated section in memory,
-  // since we still process relocations for it even if we're not applying them.
-  Check(Section.getContents(data));
-  // Virtual sections have no data in the object image, so leave pData = 0
-  if (!IsVirtual)
+  // If this section contains any bits (i.e. isn't a virtual or bss section),
+  // grab a reference to them.
+  if (!IsVirtual && !IsZeroInit) {
+    // In either case, set the location of the unrelocated section in memory,
+    // since we still process relocations for it even if we're not applying them.
+    Check(Section.getContents(data));
     pData = data.data();
+  }
 
   // Code section alignment needs to be at least as high as stub alignment or
   // padding calculations may by incorrect when the section is remapped to a

Removed: llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64?rev=250370&view=auto
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64 (original)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64 (removed)
@@ -1,31 +0,0 @@
-# RUN: llvm-mc -triple=x86_64-pc-win32 -filetype=obj -o %T/COFF_x86_64.o %s
-# RUN: llvm-rtdyld -triple=x86_64-pc-win32 -verify -check=%s %/T/COFF_x86_64.o
-        	.text
-	.def	 F;
-	.scl	2;
-	.type	32;
-	.endef
-	.globl	__real400921f9f01b866e
-	.section	.rdata,"dr",discard,__real400921f9f01b866e
-	.align	8
-__real400921f9f01b866e:
-	.quad	4614256650576692846     # double 3.1415899999999999
-	.text
-	.globl	F
-        .global inst1
-	.align	16, 0x90
-F:                                      # @F
-.Ltmp0:
-.seh_proc F
-# BB#0:                                 # %entry
-.Ltmp1:
-	.seh_endprologue
-# rtdyld-check: decode_operand(inst1, 4) = __real400921f9f01b866e - next_pc(inst1)
-inst1:
-	movsd	__real400921f9f01b866e(%rip), %xmm0 # xmm0 = mem[0],zero
-	retq
-.Leh_func_end0:
-.Ltmp2:
-	.seh_endproc
-
-

Copied: llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s (from r250363, llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s?p2=llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s&p1=llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64&r1=250363&r2=250371&rev=250371&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64 (original)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s Thu Oct 15 01:41:45 2015
@@ -28,4 +28,7 @@ inst1:
 .Ltmp2:
 	.seh_endproc
 
-
+# Make sure the JIT doesn't bail out on BSS sections.
+        .bss
+bss_check:
+        .fill 8, 1, 0




More information about the llvm-commits mailing list