Page 1 of 1
Mac OSX ld won't accept -Ttext
Posted: Tue Nov 11, 2014 3:56 pm
by ThisMayWork
I am running Mac OSX Yosemite, using Xcodeutils and i am trying to link my kernel with this command
Code: Select all
ld -Ttext 0x1000 -o kernel.bin loader.o main.o
I get the following error
.
After googling for a little while I found out
ld in OSX isn't based on GNU
ld. Is there any other way I could link my kernel correctly without
-Ttext?
Re: Mac OSX ld won't accept -Ttext
Posted: Tue Nov 11, 2014 4:01 pm
by Kazinsal
Welcome to OSDev.org. Developing a kernel with your host OS's toolchain is a bad idea, and I'm not quite sure why it's not listed under Beginner Mistakes.
You're going to need to build a
GCC Cross-Compiler toolchain. This will include a "generic" gcc, as, ld, and the rest of binutils suitable for developing an operating system kernel.
Re: Mac OSX ld won't accept -Ttext
Posted: Tue Nov 11, 2014 4:02 pm
by max
- don't use LLVM (that's the default fake "gcc" that Apple ships).
- don't just install the GCC that homebrew/macports have, because they are Mac OS X specific.-
-
build and use a cross compiler. see the "why" section there for a list of good reasons
- use a proper linker script,
see Bare Bones
EDIT: race conditions
well using a cross compiler is the second headline in the Bare Bones tutorial. we could add it there, though.
Re: Mac OSX ld won't accept -Ttext
Posted: Tue Nov 11, 2014 4:04 pm
by ThisMayWork
Thank you for your reply. I understand why using my host's compiler can be a bad idea, but why is the linker OS-related? I mean, of course in this case it's missing an option and god knows what else, but generally it's not OS specific, right?
Re: Mac OSX ld won't accept -Ttext
Posted: Tue Nov 11, 2014 4:06 pm
by Kazinsal
The linker links OS-specific crap in, more often than not, and like max said, LLVM is shipped with Xcode or whatever it's called nowadays and pretends its a gcc-based toolchain (very badly, I might add).
Re: Mac OSX ld won't accept -Ttext
Posted: Tue Nov 11, 2014 4:08 pm
by max
ThisMayWork wrote:Thank you for your reply. I understand why using my host's compiler can be a bad idea, but why is the linker OS-related? I mean, of course in this case it's missing an option and god knows what else, but generally it's not OS specific, right?
A linker must not be OS specific in general, but the linker that you for your system get most probably is. You should really build your own, because the bare i686-elf toolchain that you make builds clean elf binaries without including anything that you don't want to be included.
Your OS X linker will most probably link the
CRT objects (required so that the program can even start on the OS) and some system libraries to your binary. This can only be bypassed by passing a lot of ugly flags to your compiler & linker - you will not need to do that if you make a cross toolchain.
For example you later will also want modify the LD it so that it includes things you want, like libraries specific to your OS - this is then called a
OS specific toolchain. For the beginning, a simple cross compiler is enough, later you can do a lot of cool stuff by using that
Re: Mac OSX ld won't accept -Ttext
Posted: Tue Nov 11, 2014 4:27 pm
by ThisMayWork
Back with my cross-compiler, now having another problem. Ld complains about my loader.o because
Code: Select all
file not recognized: File format not recognized
. After running
file loader.o i get
Code: Select all
loader.o: Linux/i386 impure executable (OMAGIC)
. Any idea what's happening/what should be happening?
EDIT: Solved, I
obviously used a wrong format when assemblying it.