[PATCH] D114749: [JITLink][ELF] Don't skip sections of size 0

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 29 15:27:00 PST 2021


steven_wu created this revision.
steven_wu added reviewers: lhames, dexonsmith.
Herald added subscribers: ributzka, hiraditya.
steven_wu requested review of this revision.
Herald added a project: LLVM.

Size 0 sections can have symbols that have size 0. Build those sections
and symbols into the LinkGraph so they can be used properly if needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114749

Files:
  llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
  llvm/test/ExecutionEngine/JITLink/X86/ELF_empty_section.s


Index: llvm/test/ExecutionEngine/JITLink/X86/ELF_empty_section.s
===================================================================
--- /dev/null
+++ 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
Index: llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
===================================================================
--- llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
+++ 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<char>(Sec);
       if (!Data)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114749.390494.patch
Type: text/x-patch
Size: 1322 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211129/b670f505/attachment.bin>


More information about the llvm-commits mailing list