在编译Linux内核时,诸如CC、LD和CC[M]输出的代码是什么?

时间:2021-01-02 00:07:22

While compiling Linux from scratch I realize that there are compile codes that appear while compiling.

当我从头开始编译Linux时,我意识到编译时出现了编译代码。

For example CC filename , LD filename, CC[M] filename.

例如,CC文件名,LD文件名,CC[M]文件名。

What do these codes mean?

这些代码是什么意思?

3 个解决方案

#1


9  

The different markings specify the following

不同的标记指定了以下内容。

  • [CC] - Compiles the C file into an designated object file. The object file contains the archicture assembler code of that .c file. As it might also reference parts outside its scope. For example calling another function in another .c file. The function calls are left open within the object file, which is later included by the linker. Therefore
  • [CC] -将C文件编译成指定的对象文件。对象文件包含该.c文件的archicture汇编代码。因为它也可以引用其范围之外的部分。例如,在另一个.c文件中调用另一个函数。函数调用在对象文件中保持打开,该文件稍后被链接器包含。因此
  • [LD] is the proces of linking the compiled objects together, and wire up the function calls that has been left open by the compiler. However, many parts are linked together as the core part of the kernel, while some parts are left out. And thus you see
  • [LD]是将编译后的对象链接到一起的方法,并连接编译器打开的函数调用。然而,许多部分被连接在一起作为内核的核心部分,而有些部分则被忽略了。因此你看到
  • [CC (M)] for those parts which are compiled as points to be loaded into the kernel at runtime. But which are not linked together in the monolithic part of the kernel. But instead can be inserted when the kernel is booted.
  • [CC (M)]为那些被编译为在运行时被加载到内核的部分。但是在内核的整体部分中,它们并没有链接在一起。但是,当内核被引导时,可以插入。

#2


6  

Let's take an specific example and figure out what it does in the kernel 4.1, e.g. IHEX.

让我们举一个具体的例子,看看它在内核4.1中做了什么,例如IHEX。

Find what a code does

找出代码的作用。

Just run:

运行:

make SHELL='sh -x'

How that works: https://*.com/a/32010960/895245

这是如何工作的:https://*.com/a/32010960/895245

If we grep the output for IHEX, we find the lines:

如果我们对IHEX的输出进行grep,我们会找到这些行:

+ echo   IHEX    firmware/e100/d101s_ucode.bin
  IHEX    firmware/e100/d101s_ucode.bin
+ objcopy -Iihex -Obinary /home/*/git/kernel/src/firmware/e100/d101s_ucode.bin.ihex firmware/e100/d101s_ucode.bin

so we conclude that IHEX does a objcopy -Iihex.

因此,我们得出结论,IHEX做了一个objcopy -Iihex。

Find where a code is defined

找到定义代码的地方。

Every kernel command must be defined with something like:

每个内核命令都必须定义如下:

quiet_cmd_ihex  = IHEX    $@
      cmd_ihex  = $(OBJCOPY) -Iihex -Obinary $< $@

$(obj)/%: $(obj)/%.ihex
        $(call cmd,ihex)

for the verbosity settings (e.g. V=1 and make -s) to work.

对于verbosity设置(例如,V=1并使-s)工作。

So in general, you just have to

所以一般来说,你只需要。

git grep 'cmd.* = CODE'

to find CODE.

找到代码。

I have explained in detail how this system works at: https://*.com/a/32023861/895245

我已经详细解释了这个系统是如何工作的:https://*.com/a/32023861/895245。

Get the list of all codes

获取所有代码的列表。

make | grep -E '^  ' | sort -uk1,1

CC and CC [M]

CC和CC[M]

Defined in scripts/Makefile.build:

在脚本中定义/ Makefile.build:

quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
      cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<

and the [M] comes from the target specific variables:

而[M]则来自于目标特定变量:

$(real-objs-m)        : quiet_modtag := [M]
$(real-objs-m:.o=.i)  : quiet_modtag := [M]
$(real-objs-m:.o=.s)  : quiet_modtag := [M]
$(real-objs-m:.o=.lst): quiet_modtag := [M]
$(obj-m)              : quiet_modtag := [M]

It is then called through:

然后通过:

$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
    [...]
    $(call if_changed_rule,cc_o_c)

define rule_cc_o_c
    [...]
    $(call echo-cmd,cc_o_c) $(cmd_cc_o_c);                \

where if_changed_rule is defined in scripts/Kbuild.include as:

在脚本/Kbuild中定义if_changed_rule。包括:

if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ),                 \
    @set -e;                                                             \
    $(rule_$(1)))

and Kbuild.include gets included on the top level Makefile.

和Kbuild。include包括在顶层Makefile中。

LD

LD

There are a few versions, but the simplest seems to be:

有几个版本,但最简单的似乎是:

quiet_cmd_link_o_target = LD      $@
cmd_link_o_target = $(if $(strip $(obj-y)),\
              $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
              $(cmd_secanalysis),\
              rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)

$(builtin-target): $(obj-y) FORCE
    $(call if_changed,link_o_target)

and in scripts/Kbuild.include:

在脚本/ Kbuild.include:

# Execute command if command has changed or prerequisite(s) are updated.
#
if_changed = $(if $(strip $(any-prereq) $(arg-check)),                       \
    @set -e;                                                             \
    $(echo-cmd) $(cmd_$(1));                                             \
    printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)

#3


1  

It should show:

它应该显示:

  • CC when compiling a core part of the kernel
  • 在编译内核的核心部分时抄送。
  • CC [M] when compiling a module
  • CC [M]在编译模块时。
  • LD when linking
  • LD当链接

#1


9  

The different markings specify the following

不同的标记指定了以下内容。

  • [CC] - Compiles the C file into an designated object file. The object file contains the archicture assembler code of that .c file. As it might also reference parts outside its scope. For example calling another function in another .c file. The function calls are left open within the object file, which is later included by the linker. Therefore
  • [CC] -将C文件编译成指定的对象文件。对象文件包含该.c文件的archicture汇编代码。因为它也可以引用其范围之外的部分。例如,在另一个.c文件中调用另一个函数。函数调用在对象文件中保持打开,该文件稍后被链接器包含。因此
  • [LD] is the proces of linking the compiled objects together, and wire up the function calls that has been left open by the compiler. However, many parts are linked together as the core part of the kernel, while some parts are left out. And thus you see
  • [LD]是将编译后的对象链接到一起的方法,并连接编译器打开的函数调用。然而,许多部分被连接在一起作为内核的核心部分,而有些部分则被忽略了。因此你看到
  • [CC (M)] for those parts which are compiled as points to be loaded into the kernel at runtime. But which are not linked together in the monolithic part of the kernel. But instead can be inserted when the kernel is booted.
  • [CC (M)]为那些被编译为在运行时被加载到内核的部分。但是在内核的整体部分中,它们并没有链接在一起。但是,当内核被引导时,可以插入。

#2


6  

Let's take an specific example and figure out what it does in the kernel 4.1, e.g. IHEX.

让我们举一个具体的例子,看看它在内核4.1中做了什么,例如IHEX。

Find what a code does

找出代码的作用。

Just run:

运行:

make SHELL='sh -x'

How that works: https://*.com/a/32010960/895245

这是如何工作的:https://*.com/a/32010960/895245

If we grep the output for IHEX, we find the lines:

如果我们对IHEX的输出进行grep,我们会找到这些行:

+ echo   IHEX    firmware/e100/d101s_ucode.bin
  IHEX    firmware/e100/d101s_ucode.bin
+ objcopy -Iihex -Obinary /home/*/git/kernel/src/firmware/e100/d101s_ucode.bin.ihex firmware/e100/d101s_ucode.bin

so we conclude that IHEX does a objcopy -Iihex.

因此,我们得出结论,IHEX做了一个objcopy -Iihex。

Find where a code is defined

找到定义代码的地方。

Every kernel command must be defined with something like:

每个内核命令都必须定义如下:

quiet_cmd_ihex  = IHEX    $@
      cmd_ihex  = $(OBJCOPY) -Iihex -Obinary $< $@

$(obj)/%: $(obj)/%.ihex
        $(call cmd,ihex)

for the verbosity settings (e.g. V=1 and make -s) to work.

对于verbosity设置(例如,V=1并使-s)工作。

So in general, you just have to

所以一般来说,你只需要。

git grep 'cmd.* = CODE'

to find CODE.

找到代码。

I have explained in detail how this system works at: https://*.com/a/32023861/895245

我已经详细解释了这个系统是如何工作的:https://*.com/a/32023861/895245。

Get the list of all codes

获取所有代码的列表。

make | grep -E '^  ' | sort -uk1,1

CC and CC [M]

CC和CC[M]

Defined in scripts/Makefile.build:

在脚本中定义/ Makefile.build:

quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
      cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<

and the [M] comes from the target specific variables:

而[M]则来自于目标特定变量:

$(real-objs-m)        : quiet_modtag := [M]
$(real-objs-m:.o=.i)  : quiet_modtag := [M]
$(real-objs-m:.o=.s)  : quiet_modtag := [M]
$(real-objs-m:.o=.lst): quiet_modtag := [M]
$(obj-m)              : quiet_modtag := [M]

It is then called through:

然后通过:

$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
    [...]
    $(call if_changed_rule,cc_o_c)

define rule_cc_o_c
    [...]
    $(call echo-cmd,cc_o_c) $(cmd_cc_o_c);                \

where if_changed_rule is defined in scripts/Kbuild.include as:

在脚本/Kbuild中定义if_changed_rule。包括:

if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ),                 \
    @set -e;                                                             \
    $(rule_$(1)))

and Kbuild.include gets included on the top level Makefile.

和Kbuild。include包括在顶层Makefile中。

LD

LD

There are a few versions, but the simplest seems to be:

有几个版本,但最简单的似乎是:

quiet_cmd_link_o_target = LD      $@
cmd_link_o_target = $(if $(strip $(obj-y)),\
              $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
              $(cmd_secanalysis),\
              rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)

$(builtin-target): $(obj-y) FORCE
    $(call if_changed,link_o_target)

and in scripts/Kbuild.include:

在脚本/ Kbuild.include:

# Execute command if command has changed or prerequisite(s) are updated.
#
if_changed = $(if $(strip $(any-prereq) $(arg-check)),                       \
    @set -e;                                                             \
    $(echo-cmd) $(cmd_$(1));                                             \
    printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)

#3


1  

It should show:

它应该显示:

  • CC when compiling a core part of the kernel
  • 在编译内核的核心部分时抄送。
  • CC [M] when compiling a module
  • CC [M]在编译模块时。
  • LD when linking
  • LD当链接