[Issue 22428] New: importC: static variables/functions emit global symbols

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 19 13:18:19 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22428

          Issue ID: 22428
           Summary: importC: static variables/functions emit global
                    symbols
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

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

--


More information about the Digitalmars-d-bugs mailing list