LD
From OSDev Wiki
LD (available as part of the binutils package, at http://www.gnu.org/software/binutils/) is the standard linker under Linux (and possibly other Unixes). It supports most input and output formats in existence (through the use of libbfd), and it is reportedly the most flexible of the listed linkers.
This description is based on the LD sources, that can compile to support all formats. Please be aware that the LD that comes with DJGPP is very limited in its output formats (DJGPP/COFF, A.Out, flat binary), and also the LD that is part of Linux etc. - you have to ./configure and recompile LD to your requirements.
- Pros
- Supports most known input formats (ELF, DJGPP/COFF, Win32/COFF, A.Out, etc)
- Supports most known output formats (ELF, Win32/PE, A.Out, COFF, etc)
- Supports creation of shared libraries
- Can create flat binary files
- Can specify code/data addresses, with separate load and execution addresses (vital for a higher half kernel)
- Supports DWARF, ECOFF and STABS debugging information
- Free (as in both beer and speech)
- Cons
- Does not support OMF/OBJ file format
- Can get complex writing custom Linker Scripts
LD does not create shared libraries by itself. You have to give the proper flags to the compiler so that it can generate position-independent code (note that this is talking about ELF shared libraries only).
LD is able to link while keeping relocations in your final object (called the 'incremental link'), and it also can leave unresolved symbols if instructed to do so.
On the PE side, you have to use a huge hack to get LD to generate relocatable DLLs. This involves running LD three (!) times:
ld -s --base-file $(BASE).base --dll -o $(TARGET) $(OBJS) $(LIBS) $(LDFLAGS) dlltool --as=as --dllname $(TARGET) $(DTFLAGS) --base-file $(BASE).base --output-exp $(EXP_TEMP) ld -s --base-file $(BASE).base --dll -o $(TARGET) $(OBJS) $(LIBS) $(LDFLAGS) dlltool --as=as --dllname $(TARGET) $(DTFLAGS) --base-file $(BASE).base --output-exp $(EXP_TEMP) ld --dll -o $(TARGET) $(EXP) $(OBJS) $(LIBS) $(LDFLAGS)
However, this is not, in general, a problem for OS development.
You might also want to check out ar, a static-link library companion for LD.
