Page 1 of 2
Linker in Mac OS X & OS Dev
Posted: Fri Aug 17, 2007 4:01 pm
by R2_
I was looking thru old topics and I saw that some people managed to fix the mac os x linker to work with flat binary files but I didn't see anyone post a step by step on how they did this. I've been googling for a couple of hours for the answer to this problem but I found nothing so any help would be greatly appreciated.
In the past I have been able to overcome this problem by emulating fedora and using its linker. (Which is a pain as it wastes my computers resources and causes me to lag a lot)
the error the mac os x linker gives me is:
ld: Pass 1
link.ld
ld: link.ld bad magic number (not a Mach-O file)
test.o
kernel.o
ld: kernel.o bad magic number (not a Mach-O file)
I tried rebuilding bin utils but that I get a couple errors
Posted: Fri Aug 17, 2007 5:08 pm
by Colonel Kernel
Build a GCC cross-compiler. The wiki has a tutorial. That's what I did on Mac OS X, and it worked great.
Posted: Fri Aug 17, 2007 5:24 pm
by R2_
Colonel Kernel wrote:Build a GCC cross-compiler. The wiki has a tutorial. That's what I did on Mac OS X, and it worked great.
but my compiler works fine the problem is with the linker complaining is not a mach-o file.. wouldn't this just reinstall gcc ? or does it also include the linker ?
Which cross-compiler article did you mean ? I see 3 on the wiki
thanks for responding
.
Posted: Fri Aug 17, 2007 5:31 pm
by R2_
Woops sorry I pressed wrong button I meant to press edit..
do you have the cross compiler binaries already compiled ?
Posted: Fri Aug 17, 2007 7:29 pm
by Colonel Kernel
If you read the tutorial, all will be explained. Everyone runs into this problem (although the error message is different on other platforms), and the solution suggested is always the same.
To get you started, I will clarify a bit: The tutorial covers building all the tools you'll need for compiling and linking your kernel -- so yes, ld is included. Also, here is the link:
http://www.osdev.org/wiki/GCC_Cross-Compiler
I could send you binaries, but I think building your own cross-compiler is a better long-term solution. You'll learn more about how the GNU toolchain works and how to use it, plus you'll be one step ahead when the day finally comes to make your OS self-hosted.
To put it more bluntly, it's a rite of passage. So get busy.
Posted: Fri Aug 17, 2007 7:49 pm
by R2_
Colonel Kernel wrote:If you read the tutorial, all will be explained. Everyone runs into this problem (although the error message is different on other platforms), and the solution suggested is always the same.
To get you started, I will clarify a bit: The tutorial covers building all the tools you'll need for compiling and linking your kernel -- so yes, ld is included. Also, here is the link:
http://www.osdev.org/wiki/GCC_Cross-Compiler
I could send you binaries, but I think building your own cross-compiler is a better long-term solution. You'll learn more about how the GNU toolchain works and how to use it, plus you'll be one step ahead when the day finally comes to make your OS self-hosted.
To put it more bluntly, it's a rite of passage. So get busy.
haha iight
If I fail to compile these I'll get back to you =]
Posted: Fri Aug 17, 2007 8:44 pm
by R2_
Ok I compiled the linker but it still says
abel-duartes-computer:~/Desktop/OS HD$ /Users/HD/Desktop/build/bin/i586-elf-ld -Tlink.ld -o kernel.bin test.o kernel.o
test.o: file not recognized: File format not recognized
Posted: Fri Aug 17, 2007 10:46 pm
by Colonel Kernel
Did you re-compile test.o using your new cross-compiler first...?
Posted: Sat Aug 18, 2007 6:34 am
by R2_
Colonel Kernel wrote:Did you re-compile test.o using your new cross-compiler first...?
Im compiling GCC right now but how can that be the problem when it isnt recognizing an assembly flat binary either ?
Does this have anything to do with the target parameter ?
Posted: Sat Aug 18, 2007 7:54 am
by Combuster
You can not use binary files as input to a linker. The linker will have no clue as what to link as binary files do not contain any such information. You'll need to assemble to an object format. For the cross-compiler, that's ELF.
Posted: Sat Aug 18, 2007 9:11 am
by R2_
Combuster wrote:You can not use binary files as input to a linker. The linker will have no clue as what to link as binary files do not contain any such information. You'll need to assemble to an object format. For the cross-compiler, that's ELF.
well now it works with nasm after I specified elf output format for it but gcc still fails to compile..
Thanks Combuster.
Posted: Sat Aug 18, 2007 9:35 am
by Brynet-Inc
Well then post the error R2_, We're not mind readers...
Posted: Sat Aug 18, 2007 10:04 am
by R2_
Brynet-Inc wrote:Well then post the error R2_, We're not mind readers...
haha sorry
They are makefile errors
crtstuff.c:116:Unknown pseudo-op: .weak
crtstuff.c:116:Rest of line ignored. 1st junk character valued 95 (_).
make[1]: *** [crtbegin.o] Error 1
make: *** [install-gcc] Error 2
I think I might stick with 100% assembly.. it might be harder to code but it will definitely avoid all these problems
Posted: Sat Aug 18, 2007 5:19 pm
by Combuster
Sounds like
wiki wrote:This, in combination with lots of other assembly-level error messages (like, Warning: .type pseudo-op used outside of .def/.endef ignored, or Error: unknown pseudo-op: '.local') results when you did not correctly set the --prefix=$PREFIX during the binutils configure.
I don't own a mac so if Colonel Kernel (or somebody else who has one) could test-build the cross-compiler according to the wiki instructions, we know wether it
should work or not. Since I do know is that those instructions work on both linux (gentoo) and cygwin, I think you missed something. Still, a check would be welcome.
Posted: Sat Aug 18, 2007 5:24 pm
by Brynet-Inc
I guess the best way for us to be sure is to know a few more things..
Did you download the latest GCC/binutils source from their "official" locations?
What ./configure arguments did you use for each? "make" commands as well..
All of this information would be somewhat helpful..