Skip to content

Commit d0e628c

Browse files
committed
kbuild: doc: clarify the difference between extra-y and always-y
The difference between extra-y and always-y is obscure. Basically, Kbuild builds targets listed in extra-y and always-y in visited Makefiles without relying on any dependency. The difference is that extra-y is used to list the targets needed for vmlinux whereas always-y is used to list the targets that must be always built irrespective of final targets. Kbuild skips extra-y when it is building only modules (i.e. 'make modules'). This is the long-standing behavior since extra-y was introduced in 2003, and it is explained in that commit log [1]. For clarification, this is the extra-y vs always-y table: extra-y always-y 'make' y y 'make vmlinux' y y 'make modules' n y Kbuild skips extra-y also when building external modules since obviously it never builds vmlinux. Unfortunately, extra-y is wrongly used in many places of upstream code, and even in external modules. Using extra-y in external module Makefiles is wrong. What you should use is probably always-y or 'targets'. The current documentation for extra-y is misleading. I rewrote it, and moved it to the section 3.7. always-y is not documented anywhere. I added. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=f94e5fd7e5d09a56a60670a9bb211a791654bba8 Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Randy Dunlap <[email protected]>
1 parent 39bb232 commit d0e628c

File tree

1 file changed

+71
-39
lines changed

1 file changed

+71
-39
lines changed

Documentation/kbuild/makefiles.rst

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ This document describes the Linux kernel Makefiles.
1515
--- 3.4 Objects which export symbols
1616
--- 3.5 Library file goals - lib-y
1717
--- 3.6 Descending down in directories
18-
--- 3.7 Compilation flags
19-
--- 3.8 Dependency tracking
20-
--- 3.9 Custom Rules
21-
--- 3.10 Command change detection
22-
--- 3.11 $(CC) support functions
23-
--- 3.12 $(LD) support functions
24-
--- 3.13 Script Invocation
18+
--- 3.7 Non-builtin vmlinux targets - extra-y
19+
--- 3.8 Always built goals - always-y
20+
--- 3.9 Compilation flags
21+
--- 3.10 Dependency tracking
22+
--- 3.11 Custom Rules
23+
--- 3.12 Command change detection
24+
--- 3.13 $(CC) support functions
25+
--- 3.14 $(LD) support functions
26+
--- 3.15 Script Invocation
2527
2628
=== 4 Host Program support
2729
--- 4.1 Simple Host Program
@@ -321,7 +323,60 @@ more details, with real examples.
321323
names. This allows kbuild to totally skip the directory if the
322324
corresponding `CONFIG_` option is neither 'y' nor 'm'.
323325

324-
3.7 Compilation flags
326+
3.7 Non-builtin vmlinux targets - extra-y
327+
-----------------------------------------
328+
329+
extra-y specifies targets which are needed for building vmlinux,
330+
but not combined into built-in.a.
331+
332+
Examples are:
333+
334+
1) head objects
335+
336+
Some objects must be placed at the head of vmlinux. They are
337+
directly linked to vmlinux without going through built-in.a
338+
A typical use-case is an object that contains the entry point.
339+
340+
arch/$(SRCARCH)/Makefile should specify such objects as head-y.
341+
342+
Discussion:
343+
Given that we can control the section order in the linker script,
344+
why do we need head-y?
345+
346+
2) vmlinux linker script
347+
348+
The linker script for vmlinux is located at
349+
arch/$(SRCARCH)/kernel/vmlinux.lds
350+
351+
Example::
352+
353+
# arch/x86/kernel/Makefile
354+
extra-y := head_$(BITS).o
355+
extra-y += head$(BITS).o
356+
extra-y += ebda.o
357+
extra-y += platform-quirks.o
358+
extra-y += vmlinux.lds
359+
360+
$(extra-y) should only contain targets needed for vmlinux.
361+
362+
Kbuild skips extra-y when vmlinux is apparently not a final goal.
363+
(e.g. 'make modules', or building external modules)
364+
365+
If you intend to build targets unconditionally, always-y (explained
366+
in the next section) is the correct syntax to use.
367+
368+
3.8 Always built goals - always-y
369+
---------------------------------
370+
371+
always-y specifies targets which are literally always built when
372+
Kbuild visits the Makefile.
373+
374+
Example::
375+
# ./Kbuild
376+
offsets-file := include/generated/asm-offsets.h
377+
always-y += $(offsets-file)
378+
379+
3.9 Compilation flags
325380
---------------------
326381

327382
ccflags-y, asflags-y and ldflags-y
@@ -410,8 +465,8 @@ more details, with real examples.
410465
AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt
411466

412467

413-
3.8 Dependency tracking
414-
-----------------------
468+
3.10 Dependency tracking
469+
------------------------
415470

416471
Kbuild tracks dependencies on the following:
417472

@@ -422,8 +477,8 @@ more details, with real examples.
422477
Thus, if you change an option to $(CC) all affected files will
423478
be re-compiled.
424479

425-
3.9 Custom Rules
426-
----------------
480+
3.11 Custom Rules
481+
-----------------
427482

428483
Custom rules are used when the kbuild infrastructure does
429484
not provide the required support. A typical example is
@@ -499,7 +554,7 @@ more details, with real examples.
499554

500555
will be displayed with "make KBUILD_VERBOSE=0".
501556

502-
3.10 Command change detection
557+
3.12 Command change detection
503558
-----------------------------
504559

505560
When the rule is evaluated, timestamps are compared between the target
@@ -545,7 +600,7 @@ more details, with real examples.
545600
unwanted results when the target is up to date and only the
546601
tests on changed commands trigger execution of commands.
547602

548-
3.11 $(CC) support functions
603+
3.13 $(CC) support functions
549604
----------------------------
550605

551606
The kernel may be built with several different versions of
@@ -660,7 +715,7 @@ more details, with real examples.
660715
endif
661716
endif
662717

663-
3.12 $(LD) support functions
718+
3.14 $(LD) support functions
664719
----------------------------
665720

666721
ld-option
@@ -674,7 +729,7 @@ more details, with real examples.
674729
#Makefile
675730
LDFLAGS_vmlinux += $(call ld-option, -X)
676731

677-
3.13 Script invocation
732+
3.15 Script invocation
678733
----------------------
679734

680735
Make rules may invoke scripts to build the kernel. The rules shall
@@ -1304,29 +1359,6 @@ When kbuild executes, the following steps are followed (roughly):
13041359

13051360
When "make" is executed without arguments, bzImage will be built.
13061361

1307-
7.6 Building non-kbuild targets
1308-
-------------------------------
1309-
1310-
extra-y
1311-
extra-y specifies additional targets created in the current
1312-
directory, in addition to any targets specified by `obj-*`.
1313-
1314-
Listing all targets in extra-y is required for two purposes:
1315-
1316-
1) Enable kbuild to check changes in command lines
1317-
1318-
- When $(call if_changed,xxx) is used
1319-
1320-
2) kbuild knows what files to delete during "make clean"
1321-
1322-
Example::
1323-
1324-
#arch/x86/kernel/Makefile
1325-
extra-y := head.o init_task.o
1326-
1327-
In this example, extra-y is used to list object files that
1328-
shall be built, but shall not be linked as part of built-in.a.
1329-
13301362
7.7 Commands useful for building a boot image
13311363
---------------------------------------------
13321364

0 commit comments

Comments
 (0)