Writing a Linux driver in the D ecosystem

Eduard Staniloiu edi33416 at gmail.com
Tue Oct 30 09:10:02 UTC 2018


On Tuesday, 30 October 2018 at 07:24:51 UTC, sarn wrote:
> On Monday, 29 October 2018 at 15:51:49 UTC, Eduard Staniloiu 
> wrote:
>> I know it's a long post, but any suggestions?
>
> Do you have the basic hello world module working?  (Basically 
> your C code minus the call to D code.)

Yes, this is working as expected.

>
> If that works, I'd confirm that the module contains what I 
> expect using some basic binary analysis.
>
> This will do a disassembly of your module, resolving 
> relocations:
>
> objdump -dr hellomod.ko
>
> All the functions you've defined should be in the .text 
> section.  You should see a call to call_d() in the disassembly 
> of dummy_init().


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'
```

And the result of the disassembly, result of `objdump -dr 
hellomod.ko`
```

hellomod.ko:     file format elf64-x86-64


Disassembly of section .text.call_d:

0000000000000000 <call_d>:
    0:	55                   	push   %rbp
    1:	48 8b ec             	mov    %rsp,%rbp
    4:	b8 0a 00 00 00       	mov    $0xa,%eax
    9:	5d                   	pop    %rbp
    a:	c3                   	retq
	...
```


More information about the Digitalmars-d mailing list