Page 1 of 1

Problems creating a driver (relocatable linking)

Posted: Fri Feb 11, 2022 5:01 am
by devc1
I posted about that in stack overflow https://stackoverflow.com/questions/710 ... oc-section

Hello, this is my first question here. I'm writing a kernel, and looking for running drivers. The kernel can run some simple user applications in pe32+ format that loads on a fixed virtual address, however i need to load drivers in kernel space and that needs a compatible relocatable image.

I can read the dll import table, the subsystem and section headers of the driver image i created using msvc cl. But it seems to not have a ".reloc" section even though i specified in linker options /DYNAMICBASE and /FIXED:NO. The dll i created for the driver api seems to have the same problem and when i read hexadecimal output in HexDecoder. there is no reloc section. I've also seen the data directories and the relocation base entry is clear.

Here is the compiling options for the driver:

Code: Select all

cl /I inc /I ../../libc/inc /I ../../libc/drv/inc /Fo:obj/x86_64/ /Fe:osdwm.sys src/*.c "../gdk.lib" /link /machine:x64 /subsystem:native /fixed:no /dynamicbase 
copy /b osdwm.sys "../../kernel/iso/os/system"
Here is for the dll driver kit

Code: Select all

 cl src/*.c /dll /dynamicbase  /I ../inc /I ../drv/inc /Fe:gdk.dll /link /dll /fixed:no /dynamicbase /subsystem:native /machine:x64

 copy /b gdk.dll "../../kernel/iso/os/system"
 copy /b gdk.lib "../../drivers/gdk.lib"

Re: Problems creating a driver (relocatable linking)

Posted: Sat Feb 12, 2022 5:35 pm
by Octocontrabass
devc1 wrote:

Code: Select all

/machine:x64
So you're generating x64 code?

Most x64 code is position-independent without any relocations. When you write code that requires relocations, you'll see a .reloc section.

Re: Problems creating a driver (relocatable linking)

Posted: Sun Feb 13, 2022 7:38 am
by devc1
Thanks. That's true, I writed an article about what i discovered. Now my os is able to run driver and dll's !

You can read it in https://stackoverflow.com/questions/710 ... oc-section

Re: Problems creating a driver (relocatable linking)

Posted: Sun Feb 13, 2022 4:11 pm
by zaval
that's funny, right? :D on many modern 64 bit architectures (x64, ARM64 and RV64), you need to try hard to make relocations appear. :D finally PC-related addressing was embraced.

anyway, just a note - you don't need hex editor to check sections, there is dumpbin utility in MSVC so you can use it for checking different PE stuff, for example, dumpbin /headers will show you info about headers and section headers as well. :)