OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 30, 2017 4:51 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Building 64-bit native subsystem PE executable with clang
PostPosted: Sun Feb 26, 2017 5:35 pm 
Offline

Joined: Sun Feb 26, 2017 4:42 pm
Posts: 15
My OS second stage boot loader, kernel and drivers (which I haven't done anything for the last 3 years) is currently built using the windows driver kit and are 64-bit PE images. I did this for several reasons, at the time I started it, I was working on the Windows Kernel team at Microsoft and just wanted to try something in spare time. The compiler & assembler made it easy for me to write the necessary code and get it to compile and produce a bootable operating system (although still very limited in functionality).

I left about 4 years ago to do a PhD which I'm hoping to complete this year.

While I was permitted to use the ms tool chain for my hobby as an employee, I'm no longer allowed to use some of the tools I had access to and need replacements. One of these is the compiler and so I've been looking around to figure out how I can build the second stage boot loader and the kernel, drivers etc.

I have considered moving to ELF or another format, however, I've also written a kernel debug interface and a kernel debugger that connected across serial and was starting to read PDB files for debug info. I would prefer not to have to throw all this away. As I'm currently traveling I don't have access to my usual development systems to check if I can build a native subsystem no default lib 64-bit PE image either on Linux or perhaps on Windows - although I recall the Linux tool chain for windows seemed to want to link in a helper library to bridge the gap. I don't have a default lib because I also wrote my own Runtime library for the boot loader, kernel and boot/other drivers.

So does anyone know if this is possible with clang or I guess GCC (although I don't like GCC much)?

Thanks.


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Sun Feb 26, 2017 5:55 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 36
Location: Ukraine, Bachmut
So you say you cannot use WDK, SDK, VS compiler for your purpose? Why? I genuinely am interested, because I thought it's possible. I need PE/COFF support too, and tbh I just think MS compilers are of better quality. but since my project first deals with arm/mips, I just hope to use what is available (Linaro toolchain for arm) and then translate ELFs into PE/COFFs. Just like edk guys do. They use both GCC and Clang and Arm compiler I guess. For arm, they don't support mips. But if you are talking about x64, why can't you use available tools from MS? Both free and commercial? Has it something to do with legal concerns (MS doesn't allow compiling other OSs and its components by their compiler?)
Or are you just kidding? :D

_________________
Image


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Sun Feb 26, 2017 5:58 pm 
Offline

Joined: Sun Feb 26, 2017 4:42 pm
Posts: 15
Not kidding, if you read the license terms it says that the compiler etc. can only be used to build programs, drivers etc. for Windows.


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Sun Feb 26, 2017 6:07 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 36
Location: Ukraine, Bachmut
x64dev wrote:
Not kidding, if you read the license terms it says that the compiler etc. can only be used to build programs, drivers etc. for Windows.

But how Tianocore uses it for Uefi builds then?

_________________
Image


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Sun Feb 26, 2017 6:23 pm 
Offline

Joined: Sun Feb 26, 2017 4:42 pm
Posts: 15
zaval wrote:
But how Tianocore uses it for Uefi builds then?


They likely have permission since this will also be used in booting Windows etc.


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Sun Feb 26, 2017 6:34 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 36
Location: Ukraine, Bachmut
x64dev wrote:
zaval wrote:
But how Tianocore uses it for Uefi builds then?


They likely have permission since this will also be used in booting Windows etc.

emmm, something is telling me, you worry in vain, but i'm not a lawyer so.

anyway, clang/llvm, it seems, doesn't support PDB yet. gcc supports PE/COFF. theoretically.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Sun Feb 26, 2017 7:01 pm 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 181
The only reason to worry about legal stuff is if you plan to sell your OS...

If this is the case, then I would worry more about the legals related to using the Windows Driver Kit more.... pretty sure those would be restricted as well....

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Mon Feb 27, 2017 12:53 am 
Offline

Joined: Sun Feb 26, 2017 4:42 pm
Posts: 15
dchapiesky wrote:
The only reason to worry about legal stuff is if you plan to sell your OS...

If this is the case, then I would worry more about the legals related to using the Windows Driver Kit more.... pretty sure those would be restricted as well....


That's why I'm looking at clang or another compiler - since the WDK also has restrictions.

If I have to I'll change the first stage boot loader to make it load ELF and change the second stage boot loader, kernel, boot and other drivers to ELF and then write DWARF version 4/5 debug support into my boot/kernel debugger.

But was hoping to avoid that if possible :)

I don't have plans to sell the OS (currently - and may never do) but was considering building it for a university level course at some point. For that it would be best to have it be utilizing fully legal software.

You may wonder why I'd would do another OS, well, I spent 15 years working on Windows and there are a lot of things I like about it, but there are also things that I feel could be improved upon and which would be easier to improve in a new system.


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Mon Feb 27, 2017 1:12 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 2665
Location: Chichester, UK
I think a more likely concern is that, having worked on the Windows kernel, you are in danger of using information gleaned there in your own kernel!.


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Mon Feb 27, 2017 2:11 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 737
iansjack wrote:
I think a more likely concern is that, having worked on the Windows kernel, you are in danger of using information gleaned there in your own kernel!.


Then one shouldn't probably read books like Inside Windows NT and Windows Internals either. Not to mention viewing videos like the one on fighting global locks in the kernel. Wait, did Linux steal the idea from there? :)


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Mon Feb 27, 2017 2:38 am 
Offline

Joined: Sun Feb 26, 2017 4:42 pm
Posts: 15
alexfru wrote:
iansjack wrote:
I think a more likely concern is that, having worked on the Windows kernel, you are in danger of using information gleaned there in your own kernel!.


Then one shouldn't probably read books like Inside Windows NT and Windows Internals either. Not to mention viewing videos like the one on fighting global locks in the kernel. Wait, did Linux steal the idea from there? :)


Everything I would use has been openly documented anyway.

Heh, I remember that, I checked in a piece that removed another kernel Global kernel lock prior to Arun removing the dispatcher lock.

Been a while :)


Last edited by x64dev on Mon Feb 27, 2017 3:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Mon Feb 27, 2017 2:48 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 2665
Location: Chichester, UK
I suspect that those who have actually worked on the Windows kernel, and have had access to the source code for years, may know more about its workings than is revealed in those documents.

I doubt that either of these factors is a real concern for a personal project, but the possibility of inadvertently using Microsoft copyright material is probably greater than any danger inherent in using their compiler.


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with clan
PostPosted: Mon Feb 27, 2017 3:21 am 
Offline
Member
Member

Joined: Wed Oct 26, 2011 12:00 pm
Posts: 134
If you ever figure out how to use Clang to output PE files for bare targets, _please_ let me know. I don't know how much time I've spent trying to figure that out.

_________________
MollenOS Progress: Hybrid Microkernel Conversion.
GitHub


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with cla
PostPosted: Mon Feb 27, 2017 3:31 am 
Offline

Joined: Sun Feb 26, 2017 4:42 pm
Posts: 15
MollenOS wrote:
If you ever figure out how to use Clang to output PE files for bare targets, _please_ let me know. I don't know how much time I've spent trying to figure that out.


Sure :)

I may end up implementing a backend to produce the PE if I need to. In theory any linker that produces PE images could do the final stage linking of the clang compiled object code and produce a PE native subsystem image.


Top
 Profile  
 
 Post subject: Re: Building 64-bit native subsystem PE executable with cla
PostPosted: Mon Feb 27, 2017 3:37 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 737
x64dev wrote:
I may end up implementing a backend to produce the PE if I need to. In theory any linker that produces PE images could do the final stage linking of the clang compiled object code and produce a PE native subsystem image.


In theory, it's in there:
Quote:
LLD is a linker from the LLVM project. That is a drop-in replacement for system linkers and runs much faster than them. It also provides features that are useful for toolchain developers.

The linker supports ELF (Unix), PE/COFF (Windows) and Mach-O (macOS) in descending order of completeness. Internally, LLD consists of three different linkers. The ELF port is the one that will be described in this document. The PE/COFF port is almost complete except the lack of the Windows debug info (PDB) support.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: dennis95, Google [Bot], MSNbot Media, prasoc and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group