ldc icon indicating copy to clipboard operation
ldc copied to clipboard

There should be a CLI switch to disable module info / typeinfo generation

Open Geod24 opened this issue 4 years ago • 11 comments

@lolp1 recently raised the issue that they have to add:

version(LDC)
{
    version(protection) { pragma(inline, true): }
    version(protection) { pragma(LDC_no_typeinfo): }
    version(production) { pragma(LDC_no_moduleinfo); }
}

To every single one of their module to avoid typeinfo / moduleinfo generation. I have my doubt about the pragma(inline, true): usage, but since LDC exposes the ability to selectively disable typeinfo / moduleinfo at the module level, it sounds like it should also allow doing it globally - currently it's only possible via betterC.

Geod24 avatar Jun 14 '21 03:06 Geod24

The way to disable them globally is to customize druntime, getting rid of classes ModuleInfo and TypeInfo in object.d. That should work for DMD as well. Some rationale as to why they don't simply use -betterC would be nice as well, as the functionality is severely crippled this way anyway.

kinke avatar Jun 14 '21 11:06 kinke

The way to disable them globally is to customize druntime, getting rid of classes ModuleInfo and TypeInfo in object.d. That should work for DMD as well. Some rationale as to why they don't simply use -betterC would be nice as well, as the functionality is severely crippled this way anyway.

Are you asking me why I am not using -betterC with the described sceniro?

lolp1 avatar Jun 15 '21 19:06 lolp1

Yes (as the scenario isn't described at all).

kinke avatar Jun 15 '21 21:06 kinke

Yes (as the scenario isn't described at all).

So, it is part of a project which one of the important components is it being difficult to reverse engineer. Naturally, what is described here is one of many dozens of components added for this reason. The reason the GC is used with this project is that it uses lots of the standard D library and in general standard D coding in addition to rare or unconventional code usage. It makes little sense to disable the GC in our context.

lolp1 avatar Jun 19 '21 05:06 lolp1

So how do you use the GC without TypeInfos?

Edit: Or are you saying you're only suppressing Type- and ModuleInfos for some parts of the code, for stuff which isn't GC-allocated (edit: and doesn't need dynamic casting, doesn't have module ctors/dtors, ...)? Note that such parts can be separately compiled with -betterC (edit: if cleanly separated from the other modules) and then linked against a regular D executable/library just fine.

kinke avatar Jun 19 '21 09:06 kinke

So how do you use the GC without TypeInfos?

Edit: Or are you saying you're only suppressing Type- and ModuleInfos for some parts of the code, for stuff which isn't GC-allocated (edit: and doesn't need dynamic casting, doesn't have module ctors/dtors, ...)? Note that such parts can be separately compiled with -betterC (edit: if cleanly separated from the other modules) and then linked against a regular D executable/library just fine.

I can give proper information writeup today on this, as I didn't make this issue report but i certainly can give a in depth reply on our exact usage and why GC is useful for us here

lolp1 avatar Jun 19 '21 13:06 lolp1

Well from what I gathered so far, this seems like an extremely rare use case, so a bigger write-up will almost certainly not convince me to tackle this. PRs are welcome though.

kinke avatar Jun 19 '21 19:06 kinke

See https://github.com/ldc-developers/ldc/blob/738b05a13bf5f5edefb0c5b2688bbaabb7c721be/ir/iraggr.cpp#L48-L51 for TypeInfo suppression, and https://github.com/ldc-developers/ldc/blob/738b05a13bf5f5edefb0c5b2688bbaabb7c721be/gen/modules.cpp#L613-L620 for ModuleInfo suppression.

kinke avatar Jun 19 '21 19:06 kinke

Well from what I gathered so far, this seems like an extremely rare use case, so a bigger write-up will almost certainly not convince me to tackle this. PRs are welcome though.

Keep in mind I did not make this ticket and it is indeed a very extremely rare use case. I worked around it in various ways to my satisfaction.

lolp1 avatar Jun 26 '21 02:06 lolp1

Some rationale as to why they don't simply use -betterC

That was actually my reasoning for opening the issue. What's the use case for the pragma in the first place ?

I assumed that if there was a use case for disabling typeinfo and/or moduleinfo separately, on a per-module basis, then functionality wise it would make sense to have this available as a switch. If the right way is to use -betterC, then I'm not sure what use case those pragmas support ?

In any case, feel free to close this.

Geod24 avatar Jun 27 '21 09:06 Geod24

The pragmas were there way before -betterC was a thing. The TypeInfo suppression wasn't designed to be per-module, but per-aggregate.

kinke avatar Jun 27 '21 09:06 kinke