[lld] [ELF] Prevent .eh_frame_hdr size oscillation in address assignment (PR #216248)

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 22:14:14 PDT 2026


https://github.com/tmsri created https://github.com/llvm/llvm-project/pull/216248

When .eh_frame_hdr size shifts, section addresses can change whether FDEs evaluate to identical PC-relative offsets, causing FDE deduplication count to toggle and section size to oscillate infinitely between passes.

Prevent .eh_frame_hdr from shrinking during iterative address assignment passes (matching .relr.dyn) to ensure monotonic convergence.

>From 15a50ff78dabe283ed7fb7416cab2429abe69b95 Mon Sep 17 00:00:00 2001
From: Sriraman Tallam <tmsriram at google.com>
Date: Fri, 14 Aug 2026 04:30:55 +0000
Subject: [PATCH] [ELF] Prevent .eh_frame_hdr size oscillation in address
 assignment

When .eh_frame_hdr size shifts, section addresses can change whether FDEs
evaluate to identical PC-relative offsets, causing FDE deduplication count
to toggle and section size to oscillate infinitely between passes.

Prevent .eh_frame_hdr from shrinking during iterative address assignment passes
(matching .relr.dyn) to ensure monotonic convergence.
---
 lld/ELF/SyntheticSections.cpp           |  6 +++++
 lld/test/ELF/eh-frame-hdr-oscillation.s | 34 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 lld/test/ELF/eh-frame-hdr-oscillation.s

diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 6bac881446fd0..d2891ac781617 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -491,6 +491,12 @@ bool EhFrameHeader::updateAllocSize(Ctx &ctx) {
   // Compute size.
   size_t oldSize = size;
   finalizeContents();
+
+  // Don't allow the section to shrink; otherwise the size of the section can
+  // oscillate infinitely.
+  if (size < oldSize)
+    size = oldSize;
+
   return size != oldSize;
 }
 
diff --git a/lld/test/ELF/eh-frame-hdr-oscillation.s b/lld/test/ELF/eh-frame-hdr-oscillation.s
new file mode 100644
index 0000000000000..4a024a2fafb57
--- /dev/null
+++ b/lld/test/ELF/eh-frame-hdr-oscillation.s
@@ -0,0 +1,34 @@
+# REQUIRES: aarch64
+# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
+# RUN: echo "SECTIONS { \
+# RUN:   . = 0x10000; \
+# RUN:   .text : { *(.text) } \
+# RUN:   .eh_frame_hdr : { *(.eh_frame_hdr) } \
+# RUN:   .eh_frame : { *(.eh_frame) } \
+# RUN:   .text.c 0x20000 : { *(.text.c) } \
+# RUN:   . = (SIZEOF(.eh_frame_hdr) == 36) ? 0x20000 : 0x20008; \
+# RUN:   .text.b . : { *(.text.b) } \
+# RUN: }" > %t.lds
+# RUN: ld.lld -T %t.lds --eh-frame-hdr %t.o -o %t.so --shared
+# RUN: llvm-readelf -S %t.so | FileCheck %s
+
+# CHECK: .eh_frame_hdr
+
+.globl func_a, func_b, func_c
+
+.text
+func_a:
+    .cfi_startproc
+    nop
+    .cfi_endproc
+
+.section .text.c, "ax", @progbits
+func_c:
+    .cfi_startproc
+    .cfi_endproc
+
+.section .text.b, "ax", @progbits
+func_b:
+    .cfi_startproc
+    nop
+    .cfi_endproc



More information about the llvm-commits mailing list