dmd emits global symbols even for static variables / functions:
```
static int staticVar;
int globalVar;
static void staticFunc() {
static int staticVar;
}
```
```
dmd -c -betterC staticvar.c
nm staticvar.o
0000000000000000 t
0000000000000008 B _D9staticvar10staticFuncUY14staticLocalVari
0000000000000004 B globalVar
0000000000000000 W staticFunc
0000000000000000 B staticVar
```
B = global, BSS section
W = global, weak symbol
For reference, Clang doesn't emit those symbols and GCC emits local symbols.
```
0000000000000004 C globalVar
0000000000000000 t staticFunc
0000000000000004 b staticLocalVar.1959
0000000000000000 b staticVar
```
This is a wontfix for D (issue 7083), but for C this is essential for when there are multiple `static` functions with the same name but different implementations. For example `my_flush_events` for different audio backends in libsoundio:
https://github.com/andrewrk/libsoundio/search?q=my_flush_events
Comment #1 by dlang-bot — 2021-11-19T07:41:16Z
@WalterBright created dlang/dmd pull request #13322 "fix Issue 22428 - importC: static variables/functions emit global sym…" fixing this issue:
- fix Issue 22428 - importC: static variables/functions emit global symbols
https://github.com/dlang/dmd/pull/13322