4

I'm trying to write some "free standing" (What is the name for a program running directly without an OS?) code, and seeing as the OS-X linker has no support for linker scripts or flat binary output, I assume it would be best to use the GNU linker instead.

Is there a way to install/compile just the GNU linker without all of GCC?

Will a compiled GNU linker be able to understand the object files output by the OS-X version of the GAS assembler?

What is the best way to compile GCC if I can't just compile the linker?

Note: I want to compile, not use a package system.

Community
  • 1
  • 1
Hawken
  • 2,059
  • 19
  • 34

1 Answers1

2

I'm using the cross/i386-elf-gcc and cross/i386-elf-binutils ports from MacPorts for this purpose in an experimental pet kernel project of mine, using these in my Makefile:

CC=             i386-elf-gcc-4.3.2
AS=             i386-elf-as
LD=             i386-elf-ld

I have not even attempted to mix and match components from different toolchains. You may be able to get it to work somehow, but it does not seem to be worth the trouble if you can just install a "clean" set of cross-compiling tools and be reasonably sure that they will play nicely with each other.

Daniel Roethlisberger
  • 6,958
  • 2
  • 41
  • 59
  • 2
    Additions: The GNU linker will not accept the Mach-O format, so mix-and-match is not possible. But since binutils contains both the linker and assembler, there is no reason not to have both anyway. Installing gcc is not necessary for just assembly language. – ughoavgfhw Apr 23 '12 at 23:30
  • True, you don't need GCC. Except maybe if you want to use the GCC frontend for assembling or linking, e.g. when you want to use pre-processed assembly files (`.S`). – Daniel Roethlisberger Apr 23 '12 at 23:36
  • @ughoavgfhw I may also want to merge C + assembly for this project of mine, so just binutils will not be enough. – Hawken Apr 23 '12 at 23:42