From 9816f9eac902b84ec044bc11f6243d9e9400f3ef Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 15 Oct 2015 06:41:45 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250371 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 14 +++++++------- .../RuntimeDyld/X86/{COFF_x86_64 => COFF_x86_64.s} | 5 ++++- 2 files changed, 11 insertions(+), 8 deletions(-) rename test/ExecutionEngine/RuntimeDyld/X86/{COFF_x86_64 => COFF_x86_64.s} (88%) diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index b2f017c94cb..27cd09834df 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -182,8 +182,6 @@ RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) { 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(const ObjectFile &Obj, 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 diff --git a/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64 b/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s similarity index 88% rename from test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64 rename to test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s index 7029cf437c5..fc0f3e85147 100644 --- a/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64 +++ b/test/ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s @@ -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 -- 2.34.1