[llvm] [Object] Fix irsymtab CommonSize truncation past 4 GiB (PR #209085)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 12 22:25:05 PDT 2026
https://github.com/ejose02 created https://github.com/llvm/llvm-project/pull/209085
Fixes #208669
Issue :
With -flto, Fortran COMMON blocks larger than 4 GiB were silently miscompiled. The linker reserved only the low 32 bits of the declared size, so stores past that boundary could segfault with no diagnostic.
Root Cause :
storage::Uncommon::CommonSize in the LTO irsymtab was stored as 32-bit (Word). Sizes above 2^32 bytes were truncated when the symtab was written and read back at link time.
Fix :
Widen CommonSize to 64-bit and bump irsymtab format version to 4. Added test to verify symtab records the full size.
>From 361e68598b574c59ee2f9d2d17c085cd878b1a47 Mon Sep 17 00:00:00 2001
From: ejose <ejose at amd.com>
Date: Mon, 13 Jul 2026 04:55:31 +0000
Subject: [PATCH] [Object] Fix irsymtab CommonSize truncation past 4 GiB
Fixes #208669
Issue :
With -flto, Fortran COMMON blocks larger than 4 GiB were silently miscompiled. The linker reserved only the low 32 bits of the declared size, so stores past that boundary could segfault with no diagnostic.
Root Cause :
storage::Uncommon::CommonSize in the LTO irsymtab was stored as 32-bit (Word). Sizes above 2^32 bytes were truncated when the symtab was written and read back at link time.
Fix :
Widen CommonSize to 64-bit and bump irsymtab format version to 4. Added test to verify symtab records the full size.
---
llvm/include/llvm/Object/IRSymtab.h | 8 +++---
llvm/test/Object/X86/irsymtab-large-common.ll | 26 +++++++++++++++++++
llvm/test/Object/X86/irsymtab.ll | 4 +--
3 files changed, 33 insertions(+), 5 deletions(-)
create mode 100644 llvm/test/Object/X86/irsymtab-large-common.ll
diff --git a/llvm/include/llvm/Object/IRSymtab.h b/llvm/include/llvm/Object/IRSymtab.h
index 0b7d6e0734e82..f59ad293d61ae 100644
--- a/llvm/include/llvm/Object/IRSymtab.h
+++ b/llvm/include/llvm/Object/IRSymtab.h
@@ -121,7 +121,8 @@ struct Symbol {
/// This data structure contains rarely used symbol fields and is optionally
/// referenced by a Symbol.
struct Uncommon {
- Word CommonSize, CommonAlign;
+ support::ulittle64_t CommonSize;
+ Word CommonAlign;
/// COFF-specific: the name of the symbol that a weak external resolves to
/// if not defined.
@@ -137,7 +138,7 @@ struct Header {
/// when the format changes, but it does not need to be incremented if a
/// change to LLVM would cause it to create a different symbol table.
Word Version;
- enum { kCurrentVersion = 3 };
+ enum { kCurrentVersion = 4 };
/// The producer's version string (LLVM_VERSION_STRING " " LLVM_REVISION).
/// Consumers should rebuild the symbol table from IR if the producer's
@@ -177,7 +178,8 @@ struct Symbol {
uint32_t Flags;
// Copied from storage::Uncommon.
- uint32_t CommonSize, CommonAlign;
+ uint64_t CommonSize;
+ uint32_t CommonAlign;
StringRef COFFWeakExternFallbackName;
StringRef SectionName;
diff --git a/llvm/test/Object/X86/irsymtab-large-common.ll b/llvm/test/Object/X86/irsymtab-large-common.ll
new file mode 100644
index 0000000000000..246af6d1f1768
--- /dev/null
+++ b/llvm/test/Object/X86/irsymtab-large-common.ll
@@ -0,0 +1,26 @@
+; The symtab must record the full 64-bit size; a 32-bit field would store 1.
+
+; RUN: env LLVM_OVERRIDE_PRODUCER=producer opt -o %t %s
+; RUN: env LLVM_OVERRIDE_PRODUCER=producer llvm-lto2 dump-symtab %t | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+source_filename = "irsymtab-large-common.ll"
+
+; 4294967297 bytes = 4 GiB + 1 (low 32 bits are 1 if truncated)
+ at big = common global [4294967297 x i8] zeroinitializer, align 1
+
+define void @use() {
+ %p = getelementptr i8, ptr @big, i64 4294967296
+ store i8 1, ptr %p, align 1
+ ret void
+}
+
+; CHECK: version: 4
+; CHECK-NEXT: producer: producer
+; CHECK-NEXT: target triple: x86_64-unknown-linux-gnu
+; CHECK-NEXT: source filename: irsymtab-large-common.ll
+; CHECK-NEXT: dependent libraries:
+; CHECK-DAG: D-C----- big
+; CHECK-DAG: size 4294967297 align 1
+; CHECK-DAG: D------X use
diff --git a/llvm/test/Object/X86/irsymtab.ll b/llvm/test/Object/X86/irsymtab.ll
index 8fd7d19ca5ed8..f477b12e7aaa4 100644
--- a/llvm/test/Object/X86/irsymtab.ll
+++ b/llvm/test/Object/X86/irsymtab.ll
@@ -9,13 +9,13 @@
; BCA: <SYMTAB_BLOCK
; Version stored at offset 0.
-; BCA-NEXT: <BLOB abbrevid=4/> blob data = '\x03\x00\x00\x00\x06\x00\x00\x00\x08\x00\x00\x00L\x00\x00\x00\x01\x00\x00\x00X\x00\x00\x00\x00\x00\x00\x00X\x00\x00\x00\x02\x00\x00\x00\x88\x00\x00\x00\x00\x00\x00\x00\x0E\x00\x00\x00\x18\x00\x00\x00&\x00\x00\x00\x0B\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x88\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x00$\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x08$\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00'
+; BCA-NEXT: <BLOB abbrevid=4/> blob data = '\x04\x00\x00\x00\x06\x00\x00\x00\x08\x00\x00\x00L\x00\x00\x00\x01\x00\x00\x00X\x00\x00\x00\x00\x00\x00\x00X\x00\x00\x00\x02\x00\x00\x00\x88\x00\x00\x00\x00\x00\x00\x00\x0E\x00\x00\x00\x18\x00\x00\x00&\x00\x00\x00\x0B\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x88\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x00$\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\xFF\xFF\xFF\xFF\x08$\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00'
; BCA-NEXT: </SYMTAB_BLOCK>
; BCA-NEXT: <STRTAB_BLOCK
; BCA-NEXT: <BLOB abbrevid=4/> blob data = 'foobarproducerx86_64-unknown-linux-gnuirsymtab.ll'
; BCA-NEXT: </STRTAB_BLOCK>
-; SYMTAB: version: 3
+; SYMTAB: version: 4
; SYMTAB-NEXT: producer: producer
; SYMTAB-NEXT: target triple: x86_64-unknown-linux-gnu
; SYMTAB-NEXT: source filename: irsymtab.ll
More information about the llvm-commits
mailing list