FAQ : linkers

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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

FAQ : linkers

Post by Pype.Clicker »

here comes a question from http://www.osdev.org/osfaq2/index.php/Linkers
Is it still true ld can't create shared libraries, or is this dated information?
As far as i know, ld does not create shared libraries by itself. You have to give the proper flags to GCC itself so that it can generate position-independent code (note that i'm only talking about ELF shared libraries).

What i know for sure is that LD is able to link while keeping relocations in your final object (called the 'incremental link') and it also can stand unresolved symbols if instructed to do so ...
Tim

Re:FAQ : linkers

Post by Tim »

On the PE side, you have to use a huge hack to get LD to generate relocatable DLLs. This involves running LD three (!) times:

Code: Select all

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