Page 1 of 1
Developing on OSX
Posted: Thu Mar 17, 2011 5:42 pm
by brodeur235
I've always used linux to assemble/link my os modules but now it'd be a lot more convenient to do it on my mac. It's become pretty apparent that the versions of ld for linux and mac are different. For example, the mac version doesn't support linker scripts. However, this isn't my problem. My problem is that when I link, I get an output file that is much too large. I'm building from scratch, just a blank screen boot loader. Code
Code: Select all
%ifndef _BLS1_
%define _BLS1_
global _BLS1
_BLS1:
jmp $
; padding
times (0x200-2-($-$$)) db 0x00
; boot flags
db 0x55
db 0xaa
%endif
Here is the build script:
Code: Select all
echo
echo Now Assembling NOS
nasm ./../source/boot_loader/bls1.s -f macho -o ./../build/bls1.o
echo Completed
echo
echo Now Linking NOS
ld ./../build/bls1.o \
-e _BLS1 \
-arch i386 \
-o ./../build/nos.img
echo Completed
echo
And the output file is of size: 8 KB on disk (4,192 bytes)
...
...
How can I fiz this? More to the point, why is it even happening??
Brodeur235
Re: Developing on OSX
Posted: Thu Mar 17, 2011 6:21 pm
by Brynet-Inc
Fiz it? you want to add carbonation?
You need to build a cross compiler (..and linker), OS X doesn't use ELF executables.
Re: Developing on OSX
Posted: Thu Mar 17, 2011 7:49 pm
by Chandra
May be some problem with section alignment.
Ah, you said that it didn't support linker script which means there's not much you can do.
So, the only recommendation here, is a Cross Compiler.
Re: Developing on OSX
Posted: Fri Mar 18, 2011 6:45 am
by turdus
I suggest to use fasm it works perfectly under OSX (
http://board.flatassembler.net/download.php?id=3707). And forget llvm, you can download the usual toolchain for free from apple (gnu make, gcc and their friends, or, if you have purchased the OS with your machine you should have a 2nd disc that contains developer tools). But you have to compile gcc to have a cross-compiler (recommended but hard), or you can convert the binary by objconv (not nice, but works).
Re: Developing on OSX
Posted: Fri Mar 18, 2011 7:47 am
by diodesign
Apple's toolchain is on crack: it's specifically tuned to produce binaries for Steve's platforms. I struggled for too long to maintain an ELF-targeting GNU GCC on my OS X machine (built by the XCode toolchain) until I figured it was easier to use crosstool-ng on Linux to set up a cross-compiler. Grab a spare PC, slap Linux on it and hook it up to your network as a headless build server, or get VMWare for your Mac.
You save literally days and your sanity.
Re: Developing on OSX
Posted: Fri Mar 18, 2011 8:37 am
by Solar
@turdus, diodesign:
If you found that the
GCC Cross-Compiler tutorial didn't work for you,
please do give according feedback, e.g. on the discussion page of the article, the
OSDev Wiki subforum, or (while we're at it) in this thread.
The tutorial has proven to be easy enough for most people, both on Windows and Linux. I don't see why it should not be just as easy on MacOS. The advantages of having one way that works on all
three platforms should be obvious.
As of now, the only Mac-specific thing I see is that apparently you need to update libiconv beforehand. Anything else that didn't work for you on MacOS?
Re: Developing on OSX
Posted: Fri Mar 18, 2011 11:31 am
by diodesign
Solar wrote:As of now, the only Mac-specific thing I see is that apparently you need to update libiconv beforehand. Anything else that didn't work for you on MacOS?
My apologies. It was possible to get a basic toolchain working without the wiki because I was initially building the kernel and simple userland binaries with a cross-compiling GCC and nasm that were built on OS X.
However when it came to porting newlib to my OS it wasn't possible to follow the wiki because Apple's toolchain is not generic and is tuned to produce software for their platforms to the point where (in my experience) the tutorial can't be followed to build a full cross-compiling toolchain without replacing lots of utilities - at which point I might as well just switch to Linux.
I've long since erased memories of staying up all night trying to set up a full cross-compiler on Mac OS X. I'm glad I did as I now have multiple toolchains targeting x86. x64 and ARM thanks to crosstool-ng on a Ubuntu build server with code edited and docs viewed on the Apple desktop.
Re: Developing on OSX
Posted: Fri Mar 18, 2011 4:45 pm
by gerryg400
I just got a new mac the other day. I did a basic install then added xcode from the mac install disc, which installs gcc. I didn't install anything else at all.
I built a cross-binutils and cross-gcc with the mac tool-chain and then built newlib with my cross-toolchain. All that I needed to download are the obvious
binutils
gcc
gmp
mpc
mpfr
newlib
None of that mac-ports stuff is needed.
Maybe I better check the wiki to see whether I deviated from it at all. It seems very straight-forward to me. (But I'm sure I couldn't do it on windows)
Re: Developing on OSX
Posted: Fri Mar 18, 2011 5:00 pm
by diodesign
Well maybe I just suck then.
Re: Developing on OSX
Posted: Fri Mar 18, 2011 6:02 pm
by quok
gerryg400 wrote:I just got a new mac the other day. I did a basic install then added xcode from the mac install disc, which installs gcc. I didn't install anything else at all.
I built a cross-binutils and cross-gcc with the mac tool-chain and then built newlib with my cross-toolchain. All that I needed to download are the obvious
binutils
gcc
gmp
mpc
mpfr
newlib
None of that mac-ports stuff is needed.
Maybe I better check the wiki to see whether I deviated from it at all. It seems very straight-forward to me. (But I'm sure I couldn't do it on windows)
When OSX 10.5 first came out, you needed macports just for an updated iconv library (or you could build it yourself). I don't think it's needed anymore though. It's been a while since I've built a cross compiler on OSX, but being as I use my macbook every day, maybe I should update the wiki with newer instructions. Then again, I'm still on 10.5.8, and the laziness bug has struck me.
Re: Developing on OSX
Posted: Fri Mar 18, 2011 7:46 pm
by gerryg400
diodesign wrote:Well maybe I just suck then.
Unlikely. Are you on 10.6.x ? It's much less painful these days.
Re: Developing on OSX
Posted: Fri Mar 18, 2011 9:38 pm
by diodesign
gerryg400 wrote:diodesign wrote:Well maybe I just suck then.
Unlikely. Are you on 10.6.x ? It's much less painful these days.
Thanks but yeah, I'm on 10.6.6. I can't remember exact what was causing the problems, I was following
http://wiki.osdev.org/OS_Specific_Toolchain
Re: Developing on OSX
Posted: Sat Mar 19, 2011 12:41 am
by gerryg400
I just checked my tools build script. I ran the following
Code: Select all
../binutils-$BINUTILS_VER/configure --disable-werror --target=$TARGET --prefix=$PREFIX --with-sysroot=$PREFIX
make all
make install
then
Code: Select all
../gcc-4.5.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --with-newlib --with-sysroot=$PREFIX
make all-gcc
make install-gcc
make all-target-libgcc
make install-target-libgcc
and finally
Code: Select all
../newlib-$NEWLIB_VER/configure --target=$TARGET --prefix=$PREFIX
make all
make install
I don't think the tutorial mentions the '--with-sysroot' option. Also I should point out that I've never tried to build a C++ programme with my tool chain.
Re: Developing on OSX
Posted: Sat Mar 19, 2011 6:57 am
by turdus
berkus wrote:turdus wrote:And forget llvm, you can download the usual toolchain for free from apple (gnu make, gcc and their friends, or, if you have purchased the OS with your machine you should have a 2nd disc that contains developer tools).
I wouldn't call Apple's build of gcc generic enough. Objconv you apparently have to build anyway, it's not in default dev tools.
If you forget llvm, you're missing out on the opportunity to have a VERY simple to build crosscompiler (unlike gcc crap, you just need to run two "svn checkout", one mkdir, one cmake and one make command to build ENTIRE cross-compiler). EDIT: Added an article stub about this to the wiki.
The only reason I need crossgcc atm is the fact that clang++ doesn't support lambdas yet.
Fair enough! When I last checked llvm, it was not so easy to set up. Since I do not need a crosscompiler for my OS, my info could be out of date.