Bug 463 – [module] private module members have global bindings instead of local ones
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2006-10-26T05:09:21Z
Last change time
2019-05-28T07:16:40Z
Keywords
link-failure
Assigned to
Walter Bright
Creator
Thomas Kühne
Comments
Comment #0 by thomas-dloop — 2006-10-26T05:09:21Z
http://www.digitalmars.com/d/attribute.html
> Private means that only members of the enclosing class can access
> the member, or members and functions in the same module as the
> enclosing class. Private members cannot be overridden. Private
> module members are equivalent to static declarations in C programs.
=== d.d ===
private void foo(){
}
======
dmd -c d.d
readelf -s d.o
> Symbol table '.symtab' contains 11 entries:
> Num: Value Size Type Bind Vis Ndx Name
<snip>
> 10: 00000000 5 FUNC GLOBAL DEFAULT 12 _D1a3fooFZv
=== c.c ===
static void foo(){
}
======
gcc -c c.c
readelf -s c.o
> Symbol table '.symtab' contains 11 entries:
> Num: Value Size Type Bind Vis Ndx Name
<snip>
> 5: 00000000 6 FUNC LOCAL DEFAULT 1 foo
This becomes a problem if a private function with C calling convention
is defined:
=== bug.d ===
private extern(C) void foo(){
}
======
dmd -c bug.d
> Symbol table '.symtab' contains 11 entries:
> Num: Value Size Type Bind Vis Ndx Name
<snip>
> 10: 00000000 5 FUNC GLOBAL DEFAULT 12 foo
The last line should have been
> 10: 00000000 5 FUNC LOCAL DEFAULT 12 foo
Comment #1 by andrej.mitrovich — 2013-01-22T11:06:44Z
I could be wrong, but I don't think that "equivalent to static" meant it's equivalent in how the two are emitted to the object, but rather where they can be used from (i.e. from within a single module).
Comment #2 by razvan.nitu1305 — 2019-05-23T10:58:48Z
In D2, readelf now outputs WEAK for foo in all the examples in the original bug report. WEAK is like global but the symbol can be overriden. Is there a situation where this is a problem? If not, can we close this?
Comment #3 by razvan.nitu1305 — 2019-05-27T11:27:09Z
Closing as WORKSFORME.
Comment #4 by dfj1esp02 — 2019-05-28T07:16:40Z
AIU in C local symbols are used to declare functions with the same name in different modules - private functions. They shouldn't override each other and both should be called by their respective modules.
They have a pitfall when a public function is inlined and ends up calling private function from a different module, linker rejects such reference to local symbol from a different module.