[lld] Revert "[lld][Webassembly] Avoid a signed overflow on large sections … (PR #181807)

Omair Javaid via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 17 03:56:52 PST 2026


https://github.com/omjavaid created https://github.com/llvm/llvm-project/pull/181807


Reverts llvm/llvm-project#178287
I have reverted this change as it was failing lld arm 32bit buildbot. 
https://lab.llvm.org/staging/#/builders/160/builds/1189

>From aa95a8f9bb287eedf6c2d8237f147d35b8b699cb Mon Sep 17 00:00:00 2001
From: Omair Javaid <omair.javaid at linaro.org>
Date: Tue, 17 Feb 2026 15:45:24 +0500
Subject: [PATCH] Revert "[lld][Webassembly] Avoid a signed overflow on large
 sections (#178287)"

This reverts commit c703f5a1632973dd6eade473614dfbed1b088d9e.
---
 lld/test/wasm/large-debug-section.test | 29 ---------------------
 lld/test/wasm/large-section.test       | 35 --------------------------
 lld/test/wasm/section-too-large.test   | 21 ----------------
 lld/wasm/InputChunks.h                 |  6 +----
 lld/wasm/OutputSections.cpp            | 13 ----------
 5 files changed, 1 insertion(+), 103 deletions(-)
 delete mode 100644 lld/test/wasm/large-debug-section.test
 delete mode 100644 lld/test/wasm/large-section.test
 delete mode 100644 lld/test/wasm/section-too-large.test

diff --git a/lld/test/wasm/large-debug-section.test b/lld/test/wasm/large-debug-section.test
deleted file mode 100644
index 5483132d7732d..0000000000000
--- a/lld/test/wasm/large-debug-section.test
+++ /dev/null
@@ -1,29 +0,0 @@
-# RUN: split-file %s %t
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/debug1.s -o %t/debug1.o
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/debug2.s -o %t/debug2.o
-# --no-gc-sections to prevent the linker from optimizing the chunk away, otherwise it produces a tiny output
-# RUN: wasm-ld --no-entry --no-gc-sections %t/debug1.o %t/debug2.o -o %t/combined.wasm
-# RUN: llvm-readobj --sections %t/combined.wasm | FileCheck %s
-
-# Check that the linker doesn't crash with large debug sections that together exceed 2GB.
-# CHECK: Type: CUSTOM (0x0)
-# Total size: 2214592520 + 134217728 = 2348810248
-# CHECK-NEXT: Size: 2348810248
-# CHECK: Name: .debug_info
-
-# A 2GB + some extra bytes debug section to make sure we go over 2G
-#--- debug1.s
-.section .debug_info,"",@
-  .int32 0xAAAAAAAA
-  .int32 0xBBBBBBBB
-  .zero 2214592504
-  .int32 0xCCCCCCCC
-  .int32 0xDDDDDDDD
-
-#--- debug2.s
-.section .debug_info,"",@
-  .int32 0x11111111
-  .int32 0x22222222
-  .zero 134217712
-  .int32 0x44444444
-  .int32 0x55555555
diff --git a/lld/test/wasm/large-section.test b/lld/test/wasm/large-section.test
deleted file mode 100644
index ad3148a24139c..0000000000000
--- a/lld/test/wasm/large-section.test
+++ /dev/null
@@ -1,35 +0,0 @@
-# RUN: split-file %s %t
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk1.s -o %t/chunk1.o
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk2.s -o %t/chunk2.o
-# --no-gc-sections to prevent the linker from optimizing the chunk away, otherwise it produces a tiny output
-# RUN: wasm-ld --no-entry --no-gc-sections %t/chunk1.o %t/chunk2.o -o %t/combined.wasm
-# RUN: llvm-readobj --sections %t/combined.wasm | FileCheck %s
-
-# Check that the linker doesn't crash with large data sections that together exceed 2GB.
-# CHECK: Type: DATA (0xB)
-# CHECK-NEXT: Size: 2348810260
-
-# A 2GB + some extra bytes of data to make sure we go over 2G 
-#--- chunk1.s
-.section .data.chunk1,"",@
-.globl chunk1_start
-.type chunk1_start, at object
-chunk1_start:
-  .int32 0xAAAAAAAA
-  .int32 0xBBBBBBBB
-  .zero 2214592504
-  .int32 0xCCCCCCCC
-  .int32 0xDDDDDDDD
-.size chunk1_start, 2214592512
-
-#--- chunk2.s
-.section .data.chunk2,"",@
-.globl chunk2_start
-.type chunk2_start, at object
-chunk2_start:
-  .int32 0x11111111
-  .int32 0x22222222
-  .zero 134217712
-  .int32 0x44444444
-  .int32 0x55555555
-.size chunk2_start, 134217728
diff --git a/lld/test/wasm/section-too-large.test b/lld/test/wasm/section-too-large.test
deleted file mode 100644
index a4e6007de9746..0000000000000
--- a/lld/test/wasm/section-too-large.test
+++ /dev/null
@@ -1,21 +0,0 @@
-# RUN: split-file %s %t
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk1.s -o %t/chunk1.o
-# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/chunk2.s -o %t/chunk2.o
-# --no-gc-sections to prevent the linker from optimizing the chunk away, otherwise it produces a tiny output
-# RUN: not wasm-ld --no-entry --no-gc-sections %t/chunk1.o %t/chunk2.o -o %t/combined.wasm 2>&1 | FileCheck %s
-
-# Check that the linker fails gracefully when a section exceeds 4GB.
-# CHECK: error: section '.debug_info' too large to encode:
-
-# Two chunks that together exceed 4GB
-#--- chunk1.s
-.section .debug_info,"",@
-  .int32 0xAAAAAAAA
-  .zero 2147483640
-  .int32 0xBBBBBBBB
-
-#--- chunk2.s
-.section .debug_info,"",@
-  .int32 0x11111111
-  .zero 2147483640
-  .int32 0x22222222
diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
index e772894d95456..1fe78d76631f1 100644
--- a/lld/wasm/InputChunks.h
+++ b/lld/wasm/InputChunks.h
@@ -97,11 +97,7 @@ class InputChunk {
 
   // After assignAddresses is called, this represents the offset from
   // the beginning of the output section this chunk was assigned to.
-  //
-  // WASM sections can be up to 4GB. We use a larger, signed integer here to
-  // be able to detect section size overflow instead of a silent wrap-around
-  // and corrupted output sections.
-  int64_t outSecOff = 0;
+  int32_t outSecOff = 0;
 
   uint8_t sectionKind : 3;
 
diff --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp
index 22c001eaa43b7..d6348e459d31e 100644
--- a/lld/wasm/OutputSections.cpp
+++ b/lld/wasm/OutputSections.cpp
@@ -59,10 +59,6 @@ void CodeSection::finalizeContents() {
     bodySize += func->getSize();
   }
 
-  if (bodySize > UINT32_MAX) {
-    error("section too large to encode: " + Twine(bodySize) + " bytes");
-  }
-
   createHeader(bodySize);
 }
 
@@ -161,10 +157,6 @@ void DataSection::finalizeContents() {
     }
   }
 
-  if (bodySize > UINT32_MAX) {
-    error("section too large to encode: " + Twine(bodySize) + " bytes");
-  }
-
   createHeader(bodySize);
 }
 
@@ -257,11 +249,6 @@ void CustomSection::finalizeContents() {
     payloadSize += section->getSize();
   }
 
-  if (payloadSize > UINT32_MAX) {
-    error("section '" + name + "' too large to encode: " + Twine(payloadSize) +
-          " bytes");
-  }
-
   createHeader(payloadSize + nameData.size());
 }
 



More information about the llvm-commits mailing list