Bug 22428 – importC: static variables/functions emit global symbols

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2021-10-19T13:18:19Z
Last change time
2023-04-02T04:53:54Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Dennis
See also
https://issues.dlang.org/show_bug.cgi?id=23014

Comments

Comment #0 by dkorpel — 2021-10-19T13:18:19Z
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
Comment #2 by bugzilla — 2021-11-19T07:41:55Z
Fix for static functions: https://github.com/dlang/dmd/pull/13304
Comment #3 by dlang-bot — 2021-11-19T20:28:41Z
dlang/dmd pull request #13322 "fix Issue 22428 - importC: static variables/functions emit global sym…" was merged into stable: - 68dde7735b02d962b29ad470a42d0fd32e2346b4 by Walter Bright: fix Issue 22428 - importC: static variables/functions emit global symbols https://github.com/dlang/dmd/pull/13322
Comment #4 by dlang-bot — 2021-12-14T10:34:19Z
dlang/dmd pull request #13421 "merge stable" was merged into master: - b0f76aaa1e8cacbb2c64f9ad80805f8ea3a1d9de by Walter Bright: fix Issue 22428 - importC: static variables/functions emit global symbols https://github.com/dlang/dmd/pull/13421