]> git.ipfire.org Git - thirdparty/linux.git/commit - scripts/Makefile.build
kbuild: make built-in.a rule robust against too long argument error
authorMasahiro Yamada <masahiroy@kernel.org>
Fri, 27 May 2022 10:01:52 +0000 (19:01 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Wed, 1 Jun 2022 14:07:29 +0000 (23:07 +0900)
commitcd968b97c49214e6557381bddddacbd0e0fb696e
treec7df9e88fd1767e7e335ea3ab0104d9fdde163b4
parent31cb50b5590fe911077b8463ad01144fac8fa4f3
kbuild: make built-in.a rule robust against too long argument error

Kbuild runs at the top of objtree instead of changing the working
directory to subdirectories. I think this design is nice overall but
some commands have a scalability issue.

The build command of built-in.a is one of them whose length scales with:

    O(D * N)

Here, D is the length of the directory path (i.e. $(obj)/ prefix),
N is the number of objects in the Makefile, O() is the big O notation.

The deeper directory the Makefile directory is located, the more easily
it will hit the too long argument error.

We can make it better. Trim the $(obj)/ by Make's builtin function, and
restore it by a shell command (sed).

With this, the command length scales with:

    O(D + N)

In-tree modules still have some room to the limit (ARG_MAX=2097152),
but this is more future-proof for big modules in a deep directory.

For example, you can build i915 as builtin (CONFIG_DRM_I915=y) and
compare drivers/gpu/drm/i915/.built-in.a.cmd with/without this commit.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
scripts/Makefile.build