PDA

View Full Version : Compiling the Linux Kernel on OS X?




linuxftw
Jul 15, 2007, 12:42 PM
I would like to compile the Linux kernel on OS X, as the thread title suggests.

Would XCode, be enough to do it? Or would the version of GCC it uses not work?

Any input would be useful, thanks :)



robbieduncan
Jul 15, 2007, 01:37 PM
To what end? It's not like you can replace Darwin with the Linux kernel and get OSX with a Linux core? Other than that, XCode uses gcc as it's compiler so I suppose it might well work...

linuxftw
Jul 15, 2007, 02:22 PM
To what end? It's not like you can replace Darwin with the Linux kernel and get OSX with a Linux core?

No I know thats not possible. Just having to use linux to compile the linux kernel is a pain for me.

Anyway, I have had a go with the latest 2.6.5 kernel. The problem im facing is that the "-shared" option isn't available for GCC on OS X or something along those lines:

"i686-apple-darwin8-gcc-4.0.1: unrecognized option '-shared'
/usr/bin/ld: Undefined symbols:
_main"

ld returns 1 exit status, etc etc...

Anybody know a work around?

robbieduncan
Jul 15, 2007, 02:31 PM
I think the problem is that you are using the OSX linker so you will be building mach-o executables. You need to build in a different executable format (probably ELF?). Maybe then you'd gain access to the options you need. But that would prevent the OSX linker from being able to work.

Basically you need a cross compiler for x68-linux on x86-darwin...

linuxftw
Jul 15, 2007, 02:35 PM
Thanks, it might be simpler for me just to compile on linux then.

robbieduncan
Jul 15, 2007, 02:37 PM
Thanks, it might be simpler for me just to compile on linux then.

I think that's probably the case, yes.

antibact1
Jul 15, 2007, 09:49 PM
I've actually heard that the next iteration of iLife is going to include a graphical Linux kernel compiler, so if you wait for that, you may be in luck.

Really though, this is an absolutely ridiculous idea. It really begs the questions as to what you're even doing compiling a kernel, when you seem to be clueless about operating system internals. Best of luck to you.

iSee
Jul 16, 2007, 12:00 AM
Everyone's clueless about operating system internals until they start working with them.

antibact1
Jul 16, 2007, 12:39 AM
Everyone's clueless about operating system internals until they start working with them.

I agree. And to learn about the internals of a specific operating system, it's useful to look into them on that operating system.

ptomsich
Jul 16, 2007, 08:35 AM
We regularily cross-compile Linux kernels on OS X to various target architectures (mainly MIPS and ARM, but also sometimes to embedded PowerPC targets) and it's perfectly possible but non-trivial to get working initially.

You will need an appropriate cross-toolchain (targeting <your-target-arch>-elf) and a number of userspace tools installed. From the top of my head, you will need ncurses for "make menuconfig", need to modify scripts/kconfig/lxdialog/check-lxdialog.sh to recognize .dylib files (again only, if you want to do a "make menuconfig"), and generally work around a lot of issues in the scripts subdirectory.

If you are only starting with Linux kernel development, native compiles will be a lot simpler than cross-compiles, though. And Linux-hosted cross-compiles will be simpler than OS X-hosted cross-compiled.

wmperry
Aug 5, 2007, 04:19 PM
ptomisch, could you provide details on how you get the cross-compilation to work? I have been using an i686-linux-gnu cross-compiling toolchain to build work-related software on my (macbook pro) laptop, and that works great until we get to compiling the kernel (mainly module related).

Setting ARCH and CROSS_COMPILE appropriate gets the build started, but it croaks when it tries to build scripts/mod/file2alias.c with HOSTCC. Have you just hacked your kernel source to let this build as a mach-o binary? It includes some linux kernel internal headers, which expect to have other linux-specific includes in the standard system include path.

Thanks

-Bill Perry

We regularily cross-compile Linux kernels on OS X to various target architectures (mainly MIPS and ARM, but also sometimes to embedded PowerPC targets) and it's perfectly possible but non-trivial to get working initially.

You will need an appropriate cross-toolchain (targeting <your-target-arch>-elf) and a number of userspace tools installed. From the top of my head, you will need ncurses for "make menuconfig", need to modify scripts/kconfig/lxdialog/check-lxdialog.sh to recognize .dylib files (again only, if you want to do a "make menuconfig"), and generally work around a lot of issues in the scripts subdirectory.

If you are only starting with Linux kernel development, native compiles will be a lot simpler than cross-compiles, though. And Linux-hosted cross-compiles will be simpler than OS X-hosted cross-compiled.