c - 了解 XV6 makefile 中的代码块

标签 c linux makefile gnu xv6

我试图从 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

我在哪里可以找到解释上述所有选项的引用资料?例如,我试图在 GNU 网站上寻找选项“-N”,但没有找到。

提前致谢

最佳答案

我不是 Makefile 方面的专家,但您可能正在寻找一些 GNU 程序的 man 页面。
这一行,例如:

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

是,如果我理解正确的话,是 bashmake 语法的混合:

  • $(LD) 替换为 make 变量 LD,它很可能包含链接器可执行文件的名称(通常是 ld).
  • $(LDFLAGS) 与上面类似,不同之处在于它持有 flags 以传递给 LD 中命名的可执行文件。
  • -N -e main -Ttext 0 -o 只是 LD
  • 的参数
  • $@ 替换为目标
  • $^ 替换为以空格分隔的所有依赖项列表

因此,如果您想了解 -N 选项,最好的选择是 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.

关于c - 了解 XV6 makefile 中的代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29448967/

相关文章:

c - 如何用C语言打开网址?

c - inotify 事件 IN_MODIFY 为 tftp put 发生两次

linux - 在 ARM Linux 中记录 CPU 寄存器更改

c - 使用 O_CREAT|O_RDWR 打开文件将导致文件为只写

c++ - 使用 C++ 从 Linux 串行端口读取提供困惑的数据

c - Linux 用户空间程序的正确构建环境

c - 测量函数花费的时间 : clock_gettime

c - SplitLinkedList如何拆分

c - 仅当通过 makefile 执行程序时出现段错误

shell - 如何从 Makefile 使用 shell 内置函数?