Writing x86_64 linux kernel module in assembler

What I did was write a small C wrapper using the standard module macros and link it with the main module code that's written in asm. Use the normal kernel build system to build it.

module.c:

    #include <linux/module.h>
    MODULE_AUTHOR("A. U. Thor");
    MODULE_DESCRIPTION("Description");
    MODULE_LICENSE("GPL");
    extern int asm_init(void);
    int main_init(void)
    {
        return asm_init();
    }
    module_init(main_init);

main.asm:

    [bits 64]
    global asm_init
    asm_init:
        xor rax, rax
        ret

Makefile:

obj-m += test.o
test-objs := module.o main.o
$(KBUILD_EXTMOD)/main.o: main.asm
        nasm -f elf64 -o $@ $^

obj-m += memory_asm.o
memory_asm-objs := module.o main.o
$(KBUILD_EXTMOD)/main.o: $(src)/main.asm
    nasm -f elf64 -o $@ $^ && echo "" > $(src)/.main.o.cmd

Build using command: make -C <path_to_kernel_src> M=$PWD