glob_addr.c (594B)
1 /* glob: take the address of a file-scope global and pass it to a noinline 2 * function that mutates through the pointer. Codegen materializes &g with 3 * adrp/add (ADR_PREL_PG_HI21 + ADD_ABS_LO12_NC against `g`) into the arg 4 * register, and the callee does a plain indirect store. `g` is initialized 5 * nonzero to keep it in .data (a .bss global hits the SHT_NOBITS assembler gap 6 * — see glob_bss_write.skip). Exit: g set to 42. */ 7 int g = 1; 8 __attribute__((noinline)) static void set42(int* p) { *p = 42; } 9 int test_main(void) { 10 set42(&g); /* adrp/add &g -> x0, bl set42 */ 11 return g; 12 }