diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -299,12 +299,13 @@ else Prot = MemProt::Read | MemProt::Write; - // For now we just use this to skip the "undefined" section, probably need - // to revist. - if (Sec.sh_size == 0) - continue; + // Look for existing sections first. + auto *GraphSec = G->findSectionByName(*Name); + if (!GraphSec) + GraphSec = &G->createSection(*Name, Prot); + assert(GraphSec->getMemProt() == Prot && "MemProt should match"); - auto &GraphSec = G->createSection(*Name, Prot); + Block *B = nullptr; if (Sec.sh_type != ELF::SHT_NOBITS) { auto Data = Obj.template getSectionContentsAsArray(Sec); if (!Data) diff --git a/llvm/test/ExecutionEngine/JITLink/X86/ELF_empty_section.s b/llvm/test/ExecutionEngine/JITLink/X86/ELF_empty_section.s new file mode 100644 --- /dev/null +++ b/llvm/test/ExecutionEngine/JITLink/X86/ELF_empty_section.s @@ -0,0 +1,12 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t +// RUN: llvm-jitlink -noexec %t + +.section .foo,"ax" +.globl zero +zero: + + +.text +.globl main +main: +nop