OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Aug 07, 2020 9:37 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: LLVM/Clang Linker Scripts - Bare Bones Tutorial
PostPosted: Sat Dec 07, 2019 4:17 am 
Offline

Joined: Sat Dec 07, 2019 2:19 am
Posts: 1
Hi. It's my third time in kernel development. Previously I developed toy kernels with C (GCC) and Rust.
This time I want to give a try to LLVM/Clang, as it is much easier to cross-compile.
I followed Bare Bones tutorial. For cross-compiling Assembly and C source files I added
Code:
-target i686-none-elf
flags to clang. It compiled successfully.

But I stuck at linking step. First I run this command:
Code:
clang -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc

And It gave me this error
Code:
clang: warning: argument unused during compilation: '-T linker.ld' [-Wunused-command-line-argument]
boot.o : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2A0


After I tried -target i686-none-elf and -fuse-ld=lld-link flags. But it doesn't work.
Any idea about how can we link final kernel binary?


Top
 Profile  
 
 Post subject: Re: LLVM/Clang Linker Scripts - Bare Bones Tutorial
PostPosted: Sat Dec 07, 2019 12:09 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 10:35 pm
Posts: 38
Location: Eagle, ID (USA)
With clang, you will need to add
Code:
-Wl
to the linker options to fix that error. So for example,
Code:
-Wl,-T,linker.ld

Hope this helps.

_________________
"I think it may be time for some guru meditation"
"Barbarians don't do advanced wizardry"


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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