Mac OSX ld won't accept -Ttext

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
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Mac OSX ld won't accept -Ttext

Post 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

Code: Select all

ld: unknown option: -Ttext
.
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?
"Programming is an art form that fights back."
-Kudzu
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Mac OSX ld won't accept -Ttext

Post 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.
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Mac OSX ld won't accept -Ttext

Post 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 :P well using a cross compiler is the second headline in the Bare Bones tutorial. we could add it there, though.
Last edited by max on Tue Nov 11, 2014 4:06 pm, edited 1 time in total.
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Re: Mac OSX ld won't accept -Ttext

Post 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?
"Programming is an art form that fights back."
-Kudzu
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Mac OSX ld won't accept -Ttext

Post 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).
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Mac OSX ld won't accept -Ttext

Post 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 :)
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Re: Mac OSX ld won't accept -Ttext

Post 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.
"Programming is an art form that fights back."
-Kudzu
Post Reply