libc dependency

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 20 05:31:27 PDT 2017


On 6/19/17 7:47 PM, H. S. Teoh via Digitalmars-d-learn wrote:
> On Mon, Jun 19, 2017 at 07:29:46PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
>> On 6/19/17 5:45 PM, Moritz Maxeiner wrote:
>>> On Monday, 19 June 2017 at 21:35:56 UTC, Steven Schveighoffer wrote:
>>>> IIRC, Tango did not depend on libc at all. It only used system
>>>> calls. So it certainly is possible.
>>>
>>> How did they invoke those system calls? They are usually access via
>>> libc on POSIX systems, so you don't have to implement accessing e.g.
>>> vdso on Linux yourself.
>>
>> I may have misspoke. I mean they didn't depend on the library itself.
>> I think they do depend on the C wrappers.
>>
>> So for instance, they didn't use FILE *, but instead used
>> read/write/recv/send.
>>
>> I don't know what's involved in creating those wrappers, but I can't
>> imagine it's difficult to do with D (it's probably actually easier
>> than in C/assembly).
> [...]
> 
> The downside of that is that then we can no longer leverage the work
> done by libc authors to interface with that particular OS / platform.
> Meaning we have to maintain this low-level code ourselves, which
> includes potentially keeping up with OS-level changes that would
> otherwise be transparent had we used the libc wrappers. Sadly, we're not
> yet in the day when libd authors would do this for us with every new OS
> that comes out. :-D

Of course! It would not be a small task. But D has some rather nice 
generational features.

One of my favorite Dconf talks of all time is still Mike Franklin's talk 
from 2014 (http://dconf.org/2014/talks/franklin.html), which has a part 
in it where he wrote D code to parse the pdf spec of a microcontroller 
and AUTOMATICALLY GENERATE the correct register mappings. Think about 
that -- 0 effort to maintain hundreds or thousands of registers, with no 
mistakes! I'm frankly disappointed that D did not service Mike enough to 
continue using D, as he seemed a very bright and motivated user.

I think we could do something similar in D for the OS calls.

What is the point, you might ask? The only true point is to have control 
over every part of the userspace call chains. You don't need a FILE * 
for stdout? Fine, just use this small wrapper. Who knows what magic can 
be performed if the compiler has full access to the system calls for 
inlining and optimization.

I'm not saying I want to do this or that it's really important. But 
there are possible reasons to do it, even if it's just for the coolness 
factor :)

-Steve


More information about the Digitalmars-d-learn mailing list