fix(asm): reject an out-of-range GLOBL size with a diagnostic

Assisted-by: GLM 5.3 Flash
This commit is contained in:
petrbalvin committed 2026-10-07 01:13:40 +02:00
1 parent 14de1dd287
commit dd074dbafd
2 files changed
+12

No files matched your search

+1
View File
@@ -82,6 +82,7 @@ func FuzzAssembleAMD64(f *testing.F) {
// above never reach.
f.Add("TEXT ·f(SB), $0\n\tBOGUSINSTR AX, BX\n\tRET\n")
f.Add("GLOBL d(SB), $-8\n")
f.Add("GLOBL d(SB), $0x7FFFFFFFFFFFFFFF\n")
f.Add("DATA d+0(SB)/9, $1\nGLOBL d(SB), $8\n")
f.Add("TEXT ·f(SB), NOSPLIT, $0\n\tADJSP $16\n\tRET\n")
f.Add("#define A A\nA\n")
+11
View File
@@ -607,6 +607,14 @@ func checkDuplicateDecls(f *ast.File) error {
return nil
}
// maxSymbolSize is the ceiling on one GLOBL's declared size. The image
// materialises the symbol's bytes at assembly time, where the toolchain
// defers the cost to its linker, so the bound is the toolchain's own: obj
// rejects anything over 2,000,000,000 bytes as "symbol too large", and a
// negative size, which the toolchain's int64 field tolerates and its linker
// refuses, is diagnosed here rather than attempted.
const maxSymbolSize = 2_000_000_000
// collectData gathers the file's static symbols (GLOBL) and their initial
// contents (DATA) into byte buffers. Two passes: the Plan 9 convention puts
// every DATA line before its symbol's GLOBL, so the symbols are registered
@@ -631,6 +639,9 @@ func collectData(f *ast.File) ([]dataSym, error) {
size := 0
if gd.Size != nil && gd.Size.Imm.HasVal {
size = int(gd.Size.Imm.Val)
if size < 0 || size > maxSymbolSize {
return nil, fmt.Errorf("GLOBL %q: symbol too large (%d bytes > %d bytes)", name, size, maxSymbolSize)
}
}
index[name] = len(syms)
ds := dataSym{