Developing on OSX

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
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

Developing on OSX

Post 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
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Developing on OSX

Post 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.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Developing on OSX

Post 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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Developing on OSX

Post 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).
User avatar
diodesign
Posts: 14
Joined: Sat Sep 11, 2010 10:14 am
Location: England
Contact:

Re: Developing on OSX

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Developing on OSX

Post 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?
Every good solution is obvious once you've found it.
User avatar
diodesign
Posts: 14
Joined: Sat Sep 11, 2010 10:14 am
Location: England
Contact:

Re: Developing on OSX

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Developing on OSX

Post 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)
If a trainstation is where trains stop, what is a workstation ?
User avatar
diodesign
Posts: 14
Joined: Sat Sep 11, 2010 10:14 am
Location: England
Contact:

Re: Developing on OSX

Post by diodesign »

Well maybe I just suck then.
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: Developing on OSX

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Developing on OSX

Post by gerryg400 »

diodesign wrote:Well maybe I just suck then.
Unlikely. Are you on 10.6.x ? It's much less painful these days.
If a trainstation is where trains stop, what is a workstation ?
User avatar
diodesign
Posts: 14
Joined: Sat Sep 11, 2010 10:14 am
Location: England
Contact:

Re: Developing on OSX

Post 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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Developing on OSX

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Developing on OSX

Post 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.
Post Reply