Writing a Linux driver in the D ecosystem

Eduard Staniloiu edi33416 at gmail.com
Thu Nov 22 14:51:03 UTC 2018


On Tuesday, 30 October 2018 at 13:22:16 UTC, Radu wrote:
> On Tuesday, 30 October 2018 at 09:10:02 UTC, Eduard Staniloiu 
> wrote:
>> On Tuesday, 30 October 2018 at 07:24:51 UTC, sarn wrote:
>>> [...]
>>
>> Yes, this is working as expected.
>>
>>> [...]
>>
>>
>> Here is the result of running `make`
>> ```
>> make -C /lib/modules/`uname -r`/build M=`pwd`
>> make[1]: Entering directory 
>> '/usr/src/linux-headers-4.10.0-28-generic'
>>   LD      /home/fawkes/ws/dlang/hello/built-in.o
>>   LD [M]  /home/fawkes/ws/dlang/hello/hellomod.o
>>   Building modules, stage 2.
>>   MODPOST 1 modules
>> WARNING: could not find 
>> /home/fawkes/ws/dlang/hello/.dsrc.o_shipped.cmd for 
>> /home/fawkes/ws/dlang/hello/dsrc.o_shipped
>>   CC      /home/fawkes/ws/dlang/hello/hellomod.mod.o
>>   LD [M]  /home/fawkes/ws/dlang/hello/hellomod.ko
>> make[1]: Leaving directory 
>> '/usr/src/linux-headers-4.10.0-28-generic'
>> ```
>>
>> [...]
>
> Have you tried to build it with LDC? You might need to tweak 
> the code generation, for example `-betterC -m64 -nodefaultlib 
> --disable-red-zone -output-o -code-model=large 
> -relocation-model=static`

I've come back with an update.
I've managed to make it work with both `dmd` and `ldc`.

The issue was how I wrote the `Kbuild` file
// Bad Kbuild
```
EXTRA_CFLAGS = -Wall -g

obj-m = hellomod.o

hellomod-y = dsrc.o_shipped
```

I was under the false impression that `hellomod-y = 
dsrc.o_shipped` will add the dsrc.o object to the `hellomod.o` 
object and create the .ko. It doesn't do that. I believe it will 
only link the dsrc.o and omit the `hellomod.o`.

The correct `Kbuild` is
// Bad Kbuild
```
EXTRA_CFLAGS = -Wall -g

obj-m = mydriver.o

hellomod-y = hellomod.o dsrc.o_shipped
```

Now everything works as expected.

Thank you all for your support!

Edi


More information about the Digitalmars-d mailing list