glob_static.c (921B)
1 /* glob: a function-local `static` that persists across calls. The static lives 2 * in .data (initialized nonzero to dodge the .bss SHT_NOBITS assembler gap) and 3 * is addressed with the same adrp/add+ldr/str symbolic pair as a file-scope 4 * global, but through a local symbol. noinline keeps `bump` a real call so the 5 * accumulation actually happens across 6 invocations. 6 * 7 * NOTE: currently SKIPPED. The compiler mangles the static-local symbol as 8 * `acc.1`, and the assembler's :lo12: operand parser stops at the `.`, so 9 * `ldr w9, [x16, :lo12:acc.1]` fails to assemble (`expected ']'`). See 10 * glob_static.skip. Exit when the gap is fixed: bump returns 6 + 6*6 = 42. */ 11 __attribute__((noinline)) static int bump(void) { 12 static int acc = 6; /* nonzero -> .data, not .bss */ 13 acc += 6; 14 return acc; 15 } 16 int test_main(void) { 17 int r = 0; 18 for (int i = 0; i < 6; ++i) r = bump(); 19 return r; /* 6 + 6*6 = 42 */ 20 }