Bug 20144 – standard pragma for weak linkage

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-19T23:16:19Z
Last change time
2022-06-09T15:54:19Z
Keywords
industry, link-failure
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2019-08-19T23:16:19Z
Marking symbols with weak linkage is common, and necessary in a lot of designs. Currently, describing weak linkage is implementation dependent, and also platform dependent. Since D doesn't have a preprocessor, and we have no aliasing mechanism for attributes or pragmas, it's impossible to wrangle all of this into one expression. The language needs to specify a weak linkage pragma, which can be mapped appropriately everywhere. `pragma(weak, true) void fun() {}` for instance; please choose you preferred name. GDC/LDC will map this to their backend directly (where they currently expose implementation defined attributes), DMD needs to implement this, which is mostly trivial. Posix just flags it in the output, and MS/Windows does this by embedding a linker directive in the output. We need this. It is time.
Comment #1 by maxhaton — 2022-06-09T00:22:32Z
A UDA seems like a better option
Comment #2 by kinke — 2022-06-09T15:38:17Z
(In reply to mhh from comment #1) > A UDA seems like a better option Yep, and even better, it already exists - core.attribute.weak, incl. support by DMD, GDC and LDC. => closing
Comment #3 by kinke — 2022-06-09T15:40:23Z
Well, I guess it doesn't work with DMD on Windows. But LDC supports it with the linker directive emulation. Anyway, that should be filed as a separate issue then.
Comment #4 by maxhaton — 2022-06-09T15:54:19Z
I wasn't aware dmd had it but ok