[PATCH] D135223: [BOLT] Fix writing out unmarked .eh_frame section

Maksim Panchenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 11:20:18 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b213c909036: [BOLT] Fix writing out unmarked .eh_frame section (authored by maksfb).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135223/new/

https://reviews.llvm.org/D135223

Files:
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/X86/dummy-eh-frame-bug.s


Index: bolt/test/X86/dummy-eh-frame-bug.s
===================================================================
--- /dev/null
+++ bolt/test/X86/dummy-eh-frame-bug.s
@@ -0,0 +1,27 @@
+# REQUIRES: system-linux
+
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe -q
+# RUN: llvm-bolt %t.exe -o %t.bolt.exe --funcs=nocfi_function
+# RUN: llvm-readelf --section-headers %t.bolt.exe | FileCheck %s
+
+## Check that llvm-bolt does not allocate unmarked space for original .eh_frame
+## after .text when no update is needed to .eh_frame.
+
+# CHECK: {{ .text}} PROGBITS [[#%x,ADDR:]] [[#%x,OFFSET:]] [[#%x,SIZE:]]
+# CHECK-NEXT: 0000000000000000 [[#%x, OFFSET + SIZE]]
+
+  .text
+  .globl nocfi_function
+  .type nocfi_function, at function
+nocfi_function:
+  ret
+  .size nocfi_function, .-nocfi_function
+
+  .globl _start
+  .type _start, at function
+_start:
+  .cfi_startproc
+  call nocfi_function
+  .size _start, .-_start
+  .cfi_endproc
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -3798,6 +3798,16 @@
   if (RuntimeLibrary *RtLibrary = BC->getRuntimeLibrary())
     RtLibrary->addRuntimeLibSections(Sections);
 
+  if (!EHFrameSection || !EHFrameSection->isFinalized()) {
+    ErrorOr<BinarySection &> OldEHFrameSection =
+        BC->getUniqueSectionByName(Twine(getOrgSecPrefix(), ".eh_frame").str());
+    if (OldEHFrameSection) {
+      RTDyld.reassignSectionAddress(OldEHFrameSection->getSectionID(),
+                                    NextAvailableAddress);
+      BC->deregisterSection(*OldEHFrameSection);
+    }
+  }
+
   for (std::string &SectionName : Sections) {
     ErrorOr<BinarySection &> Section = BC->getUniqueSectionByName(SectionName);
     if (!Section || !Section->isAllocatable() || !Section->isFinalized())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135223.466129.patch
Type: text/x-patch
Size: 1931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221007/dc4e3418/attachment.bin>


More information about the llvm-commits mailing list