Problems creating a driver (relocatable linking)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Problems creating a driver (relocatable linking)

Post 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"
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problems creating a driver (relocatable linking)

Post 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.
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: Problems creating a driver (relocatable linking)

Post 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
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: Problems creating a driver (relocatable linking)

Post 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. :)
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
Post Reply