Avoiding the CRT

Windows specific forum
Everything
Enthusiast
Enthusiast
Posts: 224
Joined: Sat Jul 07, 2018 6:50 pm

Avoiding the CRT

Post by Everything »

Hi.
Is there way to avoid\reduce usage of msvcrt functions import?
I can replace some of it with /DEFAULTLIB (then internal PB function use my alternative inline functions) but not every function can be handled that way.
For example 'memset' call in app entry point cause 'memset' stay in IAT etc.

In VS we can just set /Oi (/O2 "maximize speed") flags and compiler inserts the whole code for the function in place at its call point.
Or we can select some exact functions to be inlined with #pragma intrinsic(memset, strlen)

How to handle this in PB?

P.S.
Also same questions about 'MultiByteToWideChar' import by 'PeekS' but it's not so important.
User avatar
mk-soft
Always Here
Always Here
Posts: 5398
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Avoiding the CRT

Post by mk-soft »

I think this does not work because Purebasic is not internally a C compiler.

PB works something like this:
PB code -> Translate macros -> ASM code -> ASM compiler -> Link libraries -> Execute
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Everything
Enthusiast
Enthusiast
Posts: 224
Joined: Sat Jul 07, 2018 6:50 pm

Re: Avoiding the CRT

Post by Everything »

Well, yes it's not so trivial. If we look inside of PureLibraries\String we will get there a lot of hardcoded stuff like:

Code: Select all

/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES"
__imp_WideCharToMultiByte etc
For example if we compile in PB one line of code:

Code: Select all

s.s = "s"
In IAT we will get:
msvcrt:memset import (I guess from LIBCMT > MainCRTStartup)
msvcrt:wcslen import (From PB 'String' lib)

So I don't see the way to totally remove CRT dependencies without reconstructing default PB libs.
Ok, lets back to "reduce" part. There is two ways (as I see it) first - replace what can be replaced with /DEFAULTLIB + own static lib linking and second one - provide own implementation of the PB functions.

Second part contain limited number of functions such as PeekS, Len etc.
The problem for now is that my implementation of PeekS is 2.5 times slower than PB native one. Maybe someone can suggest some asm (<= sse3!) or just optimized version?
User avatar
idle
Always Here
Always Here
Posts: 5094
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Avoiding the CRT

Post by idle »

Why do you want to avoid the CRT? It's a bit hard to avoid as pb is dependent on it.
It wouldn't be so bad if the standard c run time was just that but MS borked the standard up
moving functions to other libs and adding the ucrt and now its like some hydra head of c run time versions
and they're not version compatible which makes it a little hit and miss if you want to build static libs for PB
sometimes you can and sometimes you can't, unless you use the same crt version as PB is developed in
VS2013 crt libs.
Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply