digitalmars.D - Creating weak symbols with D
- Andrei Alexandrescu (4/4) Aug 08 2020 Weak symbols (https://en.wikipedia.org/wiki/Weak_symbol) are not often
- Stefan Koch (7/12) Aug 08 2020 pragma(weak) sounds better to me.
- kinke (4/14) Aug 08 2020 E.g.,
- Johan (10/21) Aug 08 2020 This argumentation doesn't make sense to me. Not all pragmas
- Petar Kirov [ZombineDev] (5/22) Aug 08 2020 Another important advantage is that they can be easily
- sarn (4/17) Aug 08 2020 Maybe the ship has already sailed, but existing linker-related
- Johan (8/26) Aug 09 2020 DMD simply doesn't have a lot of linker-related functionality
- Jacob Carlborg (9/11) Aug 09 2020 I don't know about Andrei's use case, but weak linkage is vital to be
- Manu (3/7) Aug 10 2020 I feel like you're not the first person that's said this...
Weak symbols (https://en.wikipedia.org/wiki/Weak_symbol) are not often needed, but they are, they're needed badly. C and C++ define __attribute__((weak)) to introduce weak symbols. It would be great if D could have a corresponding weak attribute.
Aug 08 2020
On Saturday, 8 August 2020 at 17:59:08 UTC, Andrei Alexandrescu wrote:Weak symbols (https://en.wikipedia.org/wiki/Weak_symbol) are not often needed, but they are, they're needed badly. C and C++ define __attribute__((weak)) to introduce weak symbols. It would be great if D could have a corresponding weak attribute.pragma(weak) sounds better to me. pragmas are suppose to change codgen, and the usecase is seldom enough that you wouldn't want to take name for it. Out of interested where do you find yourself needing to specify weak linkage?
Aug 08 2020
On Saturday, 8 August 2020 at 18:14:34 UTC, Stefan Koch wrote:On Saturday, 8 August 2020 at 17:59:08 UTC, Andrei Alexandrescu wrote:LDC has weak, even working for MSVC targets since v1.22.Weak symbols (https://en.wikipedia.org/wiki/Weak_symbol) are not often needed, but they are, they're needed badly. C and C++ define __attribute__((weak)) to introduce weak symbols. It would be great if D could have a corresponding weak attribute.Out of interested where do you find yourself needing to specify weak linkage?E.g., https://github.com/ldc-developers/druntime/commit/2eee5ffb17ff15fab20fa18b85bb6a696b7a2213.
Aug 08 2020
On Saturday, 8 August 2020 at 18:14:34 UTC, Stefan Koch wrote:On Saturday, 8 August 2020 at 17:59:08 UTC, Andrei Alexandrescu wrote:This argumentation doesn't make sense to me. Not all pragmas change codegen, and there are many things that change codegen that are not pragmas. LDC has the ldc.attributes.weak magic UDA (in https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/attributes.d), and I'm sure GDC has something very similar. (LDC also has the (very old) pragma(LDC_extern_weak), which should be changed to a magic UDA.) LDC chose to implement these things as UDAs because it offers a few benefits over pragmas, one of which is that it doesn't need compiler surgery. -JohanWeak symbols (https://en.wikipedia.org/wiki/Weak_symbol) are not often needed, but they are, they're needed badly. C and C++ define __attribute__((weak)) to introduce weak symbols. It would be great if D could have a corresponding weak attribute.pragma(weak) sounds better to me. pragmas are suppose to change codgen, and the usecase is seldom enough that you wouldn't want to take name for it.
Aug 08 2020
On Saturday, 8 August 2020 at 18:43:31 UTC, Johan wrote:On Saturday, 8 August 2020 at 18:14:34 UTC, Stefan Koch wrote:Another important advantage is that they can be easily introspected and enabled conditionally as they're just tuples. I think that the design of UDAs in D is one of the underrated language design success stories :)On Saturday, 8 August 2020 at 17:59:08 UTC, Andrei Alexandrescu wrote:This argumentation doesn't make sense to me. Not all pragmas change codegen, and there are many things that change codegen that are not pragmas. LDC has the ldc.attributes.weak magic UDA (in https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/attributes.d), and I'm sure GDC has something very similar. (LDC also has the (very old) pragma(LDC_extern_weak), which should be changed to a magic UDA.) LDC chose to implement these things as UDAs because it offers a few benefits over pragmas, one of which is that it doesn't need compiler surgery. -Johan[...]pragma(weak) sounds better to me. pragmas are suppose to change codgen, and the usecase is seldom enough that you wouldn't want to take name for it.
Aug 08 2020
On Saturday, 8 August 2020 at 18:43:31 UTC, Johan wrote:On Saturday, 8 August 2020 at 18:14:34 UTC, Stefan Koch wrote:Maybe the ship has already sailed, but existing linker-related tweaks in standard D are done with pragmas (or extern). E.g., pragma(mangle) and pragma(crt_constructor).On Saturday, 8 August 2020 at 17:59:08 UTC, Andrei Alexandrescu wrote:This argumentation doesn't make sense to me. Not all pragmas change codegen, and there are many things that change codegen that are not pragmas.C and C++ define __attribute__((weak)) to introduce weak symbols. It would be great if D could have a corresponding weak attribute.pragma(weak) sounds better to me. pragmas are suppose to change codgen, and the usecase is seldom enough that you wouldn't want to take name for it.
Aug 08 2020
On Sunday, 9 August 2020 at 02:30:22 UTC, sarn wrote:On Saturday, 8 August 2020 at 18:43:31 UTC, Johan wrote:DMD simply doesn't have a lot of linker-related functionality (no: weak, section, alias). GDC and LDC both do these things with magic UDAs, because UDAs fit much better in the language. (introspection, combining into AliasSeq, things like https://github.com/ldc-developers/druntime/blob/2eee5ffb17ff15fab20fa18b85bb6a696b7a2213/src/core/stdcpp/ xception.d#L21-L22, etc.) (Btw, pragma(mangle) and `extern` are not _linker_ related. ) -JohanOn Saturday, 8 August 2020 at 18:14:34 UTC, Stefan Koch wrote:Maybe the ship has already sailed, but existing linker-related tweaks in standard D are done with pragmas (or extern). E.g., pragma(mangle) and pragma(crt_constructor).On Saturday, 8 August 2020 at 17:59:08 UTC, Andrei Alexandrescu wrote:This argumentation doesn't make sense to me. Not all pragmas change codegen, and there are many things that change codegen that are not pragmas.C and C++ define __attribute__((weak)) to introduce weak symbols. It would be great if D could have a corresponding weak attribute.pragma(weak) sounds better to me. pragmas are suppose to change codgen, and the usecase is seldom enough that you wouldn't want to take name for it.
Aug 09 2020
On 2020-08-08 20:14, Stefan Koch wrote:Out of interested where do you find yourself needing to specify weak linkage?I don't know about Andrei's use case, but weak linkage is vital to be able to create proper bindings to Apple's SDks. The SDK use weak linkage for most symbols. This allows to link with the latest version of the SDK, which might have added new symbols, while still targeting older versions of the platform. The application then needs to check if a symbol is available or not on the currently running platform. -- /Jacob Carlborg
Aug 09 2020
On Sun, 9 Aug 2020, 4:00 am Andrei Alexandrescu via Digitalmars-d, < digitalmars-d puremagic.com> wrote:Weak symbols (https://en.wikipedia.org/wiki/Weak_symbol) are not often needed, but they are, they're needed badly. C and C++ define __attribute__((weak)) to introduce weak symbols. It would be great if D could have a corresponding weak attribute.I feel like you're not the first person that's said this...
Aug 10 2020