1

I'm trying to understand the following code block from XV6 makefile :

ULIB = ulib.o usys.o printf.o umalloc.o

_%: %.o $(ULIB)
    $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
    $(OBJDUMP) -S $@ > $*.asm
    $(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym

Where can I find a reference which explains all the options described above ? For example I tried to look for the option "-N" in the GNU website and I didn't find it.

Thanks in advance

SyndicatorBBB
  • 1,757
  • 2
  • 26
  • 44

1 Answers1

3

I'm no expert on Makefiles, but you're probably looking for the man pages of a couple of GNU programs.
This line, for example:

$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^

Is, if I understand it right, a mixture of bash and make syntax:

  • $(LD) is replaced by the make variable LD, which most likely holds the name of the linker executable (usually ld).
  • $(LDFLAGS) is like the above, with the difference that it holds the flags to pass to the executable named in LD.
  • -N -e main -Ttext 0 -o are just arguments to LD
  • $@ is replaced by the target
  • $^ is replaced by a space-separated list of all dependencies

So if you want to know about the -N option, your best bet is the GNU ld man page:

-N
--omagic
Set the text and data sections to be readable and writable. Also, do not page-align the data segment, and disable linking against shared libraries. If the output format supports Unix style magic numbers, mark the output as "OMAGIC". Note: Although a writable text section is allowed for PE-COFF targets, it does not conform to the format specification published by Microsoft.

Siguza
  • 21,155
  • 6
  • 52
  • 89
  • Is there someway I can debug this peace of code to understand exactly what it does? – SyndicatorBBB Apr 05 '15 at 16:07
  • What is there to debug? Just read the `man` pages of the different commands or google them. But the first command links the target, the second one disassembles it and the third one dumps its symbol table. – Siguza Apr 05 '15 at 17:40