History log of /linux-master/scripts/basic/fixdep.c
Revision Date Author Comments
# 5e9e95cc9 11-Jun-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion

When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses
the directory tree to determine which EXPORT_SYMBOL to trim. If an
EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the
second traverse, where some source files are recompiled with their
EXPORT_SYMBOL() tuned into a no-op.

Linus stated negative opinions about this slowness in commits:

- 5cf0fd591f2e ("Kbuild: disable TRIM_UNUSED_KSYMS option")
- a555bdd0c58c ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding")

We can do this better now. The final data structures of EXPORT_SYMBOL
are generated by the modpost stage, so modpost can selectively emit
KSYMTAB entries that are really used by modules.

Commit f73edc8951b2 ("kbuild: unify two modpost invocations") is another
ground-work to do this in a one-pass algorithm. With the list of modules,
modpost sets sym->used if it is used by a module. modpost emits KSYMTAB
only for symbols with sym->used==true.

BTW, Nicolas explained why the trimming was implemented with recursion:

https://lore.kernel.org/all/2o2rpn97-79nq-p7s2-nq5-8p83391473r@syhkavp.arg/

Actually, we never achieved that level of optimization where the chain
reaction of trimming comes into play because:

- CONFIG_LTO_CLANG cannot remove any unused symbols
- CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled only for vmlinux,
but not modules

If deeper trimming is required, we need to revisit this, but I guess
that is unlikely to happen.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 93c656de 07-Jan-2023 Masahiro Yamada <masahiroy@kernel.org>

fixdep: do not parse *.rlib, *.rmeta, *.so

fixdep is designed only for parsing text files. read_file() appends
a terminating null byte ('\0') and parse_config_file() calls strstr()
to search for CONFIG options.

rustc outputs *.rlib, *.rmeta, *.so to dep-info. fixdep needs them in
the dependency, but there is no point in parsing such binary files.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>


# faa91c47 07-Jan-2023 Masahiro Yamada <masahiroy@kernel.org>

fixdep: avoid parsing the same file over again

The dep files (*.d files) emitted by C compilers usually contain the
deduplicated list of included files.

One exceptional case is when a header is included by the -include
command line option, and also by #include directive.

For example, the top Makefile adds the command line option,
"-include $(srctree)/include/linux/kconfig.h". You do not need to
include <linux/kconfig.h> in every source file.

In fact, include/linux/kconfig.h is listed twice in many .*.cmd files
due to include/linux/xarray.h having "#include <linux/kconfig.h>".
I did not fix that since it is a small redundancy.

However, this is more annoying for rustc. rustc emits the dependency
for each emission type.

For example, cmd_rustc_library emits dep-info, obj, and metadata.
So, the emitted *.d file contains the dependency for those 3 targets,
which makes fixdep parse the same file 3 times.

$ grep rust/alloc/raw_vec.rs rust/.alloc.o.cmd
rust/alloc/raw_vec.rs \
rust/alloc/raw_vec.rs \
rust/alloc/raw_vec.rs \

To skip the second parsing, this commit adds a hash table for parsed
files, just like we did for CONFIG options.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>


# 871d6573 07-Jan-2023 Masahiro Yamada <masahiroy@kernel.org>

fixdep: refactor hash table lookup

Change the hash table code so it will be easier to add the second table.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>


# bc6df812 07-Jan-2023 Masahiro Yamada <masahiroy@kernel.org>

fixdep: parse Makefile more correctly to handle comments etc.

fixdep parses dependency files (*.d) emitted by the compiler.

*.d files are Makefiles describing the dependencies of the main source
file.

fixdep understands minimal Makefile syntax. It works well enough for
GCC and Clang, but not for rustc.

This commit improves the parser a little more for better processing
comments, escape sequences, etc.

My main motivation is to drop comments. rustc may output comments
(e.g. env-dep). Currentyly, rustc build rules invoke sed to remove
comments, but it is more efficient to do it in fixdep.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>


# 92215e7a 29-Dec-2022 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rename cmd_$@ to savedcmd_$@ in *.cmd files

The cmd-check macro compares $(cmd_$@) and $(cmd_$1), but a pitfall is
that you cannot use cmd_<target> as the variable name for the command.

For example, the following code will not work in the top Makefile
or ./Kbuild.

quiet_cmd_foo = GEN $@
cmd_foo = touch $@

targets += foo
foo: FORCE
$(call if_changed,foo)

In this case, both $@ and $1 are expanded to 'foo', so $(cmd_check)
is always empty.

We do not need to use the same prefix for cmd_$@ and cmd_$1.
Rename the former to savedcmd_$@.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>


# 6a5e25fc 30-Dec-2022 Masahiro Yamada <masahiroy@kernel.org>

fixdep: remove unneeded <stdarg.h> inclusion

This is unneeded since commit 69304379ff03 ("fixdep: use fflush() and
ferror() to ensure successful write to files").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 69304379 06-Mar-2022 Masahiro Yamada <masahiroy@kernel.org>

fixdep: use fflush() and ferror() to ensure successful write to files

Currently, fixdep checks the return value from (v)printf(), but it does
not ensure the complete write to the .cmd file.

printf() just writes data to the internal buffer, which usually succeeds.
(Of course, it may fail for another reason, for example when the file
descriptor is closed, but that is another story.)

When the buffer (4k?) is full, an actual write occurs, and printf() may
really fail. One of typical cases is "No space left on device" when the
disk is full.

The data remaining in the buffer will be pushed out to the file when
the program exits, but we never know if it is successful.

One straight-forward fix would be to add the following code at the end
of the program.

ret = fflush(stdout);
if (ret < 0) {
/* error handling */
}

However, it is tedious to check the return code in all the call sites
of printf(), fflush(), fclose(), and whatever can cause actual writes
to the end device. Doing that lets the program bail out at the first
failure but is usually not worth the effort.

Instead, let's check the error status from ferror(). This is 'sticky',
so you need to check it just once. You still need to call fflush().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: David Laight <david.laight@aculab.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>


# 0e0345b7 15-Apr-2021 Alexey Dobriyan <adobriyan@gmail.com>

kbuild: redo fake deps at include/config/*.h

Make include/config/foo/bar.h fake deps files generation simpler.

* delete .h suffix
those aren't header files, shorten filenames,

* delete tolower()
Linux filesystems can deal with both upper and lowercase
filenames very well,

* put everything in 1 directory
Presumably 'mkdir -p' split is from dark times when filesystems
handled huge directories badly, disks were round adding to
seek times.

x86_64 allmodconfig lists 12364 files in include/config.

../obj/include/config/
├── 104_QUAD_8
├── 60XX_WDT
├── 64BIT
...
├── ZSWAP_DEFAULT_ON
├── ZSWAP_ZPOOL_DEFAULT
└── ZSWAP_ZPOOL_DEFAULT_ZBUD

0 directories, 12364 files

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 859c8175 07-May-2020 Gustavo A. R. Silva <gustavoars@kernel.org>

modpost,fixdep: Replace zero-length array with flexible-array

The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
int stuff;
struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

sizeof(flexible-array-member) triggers a warning because flexible array
members have incomplete type[1]. There are some instances of code in
which the sizeof operator is being incorrectly/erroneously applied to
zero-length arrays and the result is zero. Such instances may be hiding
some bugs. So, this work (flexible-array member conversions) will also
help to get completely rid of those sorts of issues.

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 3f9070a6 18-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

fixdep: remove redundant null character check

If *q is '\0', the condition (isalnum(*q) || *q == '_') is false anyway.

It is redundant to ensure non-zero *q.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 87d660f0 18-Feb-2020 Masahiro Yamada <masahiroy@kernel.org>

fixdep: remove unneeded code and comments about *.ver files

This is probably stale code. In old days (~ Linux 2.5.59), Kbuild made
genksyms generate include/linux/modules/*.ver files.

The currenct Kbuild does not generate *.ver files at all.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 6f9ac9f4 25-Jun-2019 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: check return value of printf() and putchar()

When there is not enough space on your storage device, the build will
fail with 'No space left on device' error message.

The reason is obvious from the message, so you will free up some disk
space, then you will resume the build.

However, sometimes you may still see a mysterious error message:

unterminated call to function 'wildcard': missing ')'.

If you run out of the disk space, fixdep may end up with generating
incomplete .*.cmd files.

For example, if the disk-full error occurs while fixdep is running
print_dep(), the .*.cmd might be truncated like this:

$(wildcard include/config/

When you run 'make' next time, this broken .*.cmd will be included,
then Make will terminate parsing since it is a wrong syntax.

Once this happens, you need to run 'make clean' or delete the broken
.*.cmd file manually.

Even if you do not see any error message, the .*.cmd files after any
error could be potentially incomplete, and unreliable. You may miss
the re-compilation due to missing header dependency.

If printf() cannot output the string for disk shortage or whatever
reason, it returns a negative value, but currently fixdep does not
check it at all. Consequently, fixdep *successfully* generates a
broken .*.cmd file. Make never notices that since fixdep exits with 0,
which means success.

Given the intended usage of fixdep, it must respect the return value
of not only malloc(), but also printf() and putchar().

This seems a long-standing issue since the introduction of fixdep.

In old days, Kbuild tried to provide an extra safety by letting fixdep
output to a temporary file and renaming it after everything is done:

scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\
rm -f $(depfile); \
mv -f $(dot-target).tmp $(dot-target).cmd)

It was no help to avoid the current issue; fixdep successfully created
a truncated tmp file, which would be renamed to a .*.cmd file.

This problem should be fixed by propagating the error status to the
build system because:

[1] Since commit 9c2af1c7377a ("kbuild: add .DELETE_ON_ERROR special
target"), Make will delete the target automatically on any failure
in the recipe.

[2] Since commit 392885ee82d3 ("kbuild: let fixdep directly write to
.*.cmd files"), .*.cmd file is included only when the corresponding
target already exists.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# bbda5ec6 29-Nov-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS

My main motivation of this commit is to clean up scripts/Kbuild.include
and scripts/Makefile.build.

Currently, CONFIG_TRIM_UNUSED_KSYMS works with a tricky gimmick;
possibly exported symbols are detected by letting $(CPP) replace
EXPORT_SYMBOL* with a special string '=== __KSYM_*===', which is
post-processed by sed, and passed to fixdep. The extra preprocessing
is costly, and hacking cmd_and_fixdep is ugly.

I came up with a new way to find exported symbols; insert a dummy
symbol __ksym_marker_* to each potentially exported symbol. Those
dummy symbols are picked up by $(NM), post-processed by sed, then
appended to .*.cmd files. I collected the post-process part to a
new shell script scripts/gen_ksymdeps.sh for readability. The dummy
symbols are put into the .discard.* section so that the linker
script rips them off the final vmlinux or modules.

A nice side-effect is building with CONFIG_TRIM_UNUSED_KSYMS will
be much faster.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Nicolas Pitre <nico@linaro.org>


# b3aa58d2 16-Apr-2018 Nicolas Pitre <nico@fluxnic.net>

fixdep: suppress consecutive / from file paths in dependency list files

Underscores in symbol names are translated into slashes for path names.
Filesystems treat consecutive slashes as if there was only one, so
let's do the same in the dependency list for easier grepping, etc.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# fbfa9be9 16-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: move include/config/ksym/* to include/ksym/*

The idea of using fixdep was inspired by Kconfig, but autoksyms
belongs to a different group. So, I want to move those touched
files under include/config/ksym/ to include/ksym/.

The directory include/ksym/ can be removed by 'make clean' because
it is meaningless for the external module building.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Nicolas Pitre <nico@linaro.org>


# 638e69cf 28-Feb-2018 Rasmus Villemoes <linux@rasmusvillemoes.dk>

fixdep: do not ignore kconfig.h

kconfig.h was excluded from consideration by fixdep by
6a5be57f0f00 (fixdep: fix extraneous dependencies) to avoid some false
positive hits

(1) include/config/.h
(2) include/config/h.h
(3) include/config/foo.h

(1) occurred because kconfig.h contains the string CONFIG_ in a
comment. However, since dee81e988674 (fixdep: faster CONFIG_ search), we
have a check that the part after CONFIG_ is non-empty, so this does not
happen anymore (and CONFIG_ appears by itself elsewhere, so that check
is worthwhile).

(2) comes from the include guard, __LINUX_KCONFIG_H. But with the
previous patch, we no longer match that either.

That leaves (3), which amounts to one [1] false dependency (aka stat() call
done by make), which I think we can live with:

We've already had one case [2] where the lack of include/linux/kconfig.h in
the .o.cmd file caused a missing rebuild, and while I originally thought
we should just put kconfig.h in the dependency list without parsing it
for the CONFIG_ pattern, we actually do have some real CONFIG_ symbols
mentioned in it, and one can imagine some translation unit that just
does '#ifdef __BIG_ENDIAN' but doesn't through some other header
actually depend on CONFIG_CPU_BIG_ENDIAN - so changing the target
endianness could end up rebuilding the world, minus that small
TU. Quoting Linus,

... when missing dependencies cause a missed re-compile, the resulting
bugs can be _really_ subtle.

[1] well, two, we now also have CONFIG_BOOGER/booger.h - we could change
that to FOO if we care

[2] https://lkml.org/lkml/2018/2/22/838

Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 5b8ad96d 28-Feb-2018 Rasmus Villemoes <linux@rasmusvillemoes.dk>

fixdep: remove some false CONFIG_ matches

The string CONFIG_ quite often appears after other alphanumerics,
meaning that that instance cannot be referencing a Kconfig
symbol. Omitting these means make has fewer files to stat() when
deciding what needs to be rebuilt - for a defconfig build, this seems to
remove about 2% of the (wildcard ...) lines from the .o.cmd files.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 14a596a7 28-Feb-2018 Rasmus Villemoes <linux@rasmusvillemoes.dk>

fixdep: remove stale references to uml-config.h

uml-config.h hasn't existed in this decade (87e299e5c750 - x86, um: get
rid of uml-config.h). The few remaining UML_CONFIG instances are defined
directly in terms of their real CONFIG symbol in common-offsets.h, so
unlike when the symbols got defined via a sed script, anything that uses
UML_CONFIG_FOO now should also automatically pick up a dependency on
CONFIG_FOO via the normal fixdep mechanism (since common-offsets.h
should at least recursively be a dependency). Hence I believe we should
actually be able to ignore the HELLO_CONFIG_BOOM cases.

Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Richard Weinberger <richard@nod.at>
Cc: user-mode-linux-devel@lists.sourceforge.net
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# ab9ce9fe 11-Jan-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: use existing helper to check modular CONFIG options

str_ends_with() tests if the given token ends with a particular string.
Currently, it is used to check file paths without $(srctree).

Actually, we have one more place where this helper is useful. Use it
to check if CONFIG option ends with _MODULE.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 87b95a81 11-Jan-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: refactor parse_dep_file()

parse_dep_file() has too much indentation, and puts the code far to
the right. This commit refactors the code and reduces the one level
of indentation.

strrcmp() computes 'slen' by itself, but the caller already knows the
length of the token, so 'slen' can be passed via function argument.
With this, we can swap the order of strrcmp() and "*p = \0;"

Also, strrcmp() is an ambiguous function name. Flip the logic and
rename it to str_ends_with().

I added a new helper is_ignored_file() - this returns 1 if the token
represents a file that should be ignored.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 5d1ef76f 11-Jan-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: move global variables to local variables of main()

I do not mind global variables where they are useful enough. In this
case, I do not see a good reason to use global variables since they
are just referenced in shallow places. It is easy to pass them via
function arguments.

I squashed print_cmdline() into main() since it is just one line code.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# ccfe7887 11-Jan-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: remove unneeded memcpy() in parse_dep_file()

Each token in the depfile is copied to the temporary buffer 's' to
terminate the token with zero. We do not need to do this any more
because the parsed buffer is now writable. Insert '\0' directly in
the buffer without calling memcpy().

<limits.h> is no longer necessary. (It was needed for PATH_MAX).

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 4003fd80 11-Jan-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: factor out common code for reading files

Now, do_config_files() and print_deps() are almost the same. Only
the difference is the parser function called (parse_config_file vs
parse_dep_file).

We can reduce the code duplication by factoring out the common code
into read_file() - this function allocates a buffer and loads a file
to it. It returns the pointer to the allocated buffer. (As before,
it bails out by exit(2) for any error.) The caller must free the
buffer when done.

Having empty source files is possible; fixdep should simply skip them.
I deleted the "st.st_size == 0" check, so read_file() allocates 1-byte
buffer for an empty file. strstr() will immediately return NULL, and
this is what we expect.

On the other hand, an empty dep_file should be treated as an error.
In this case, parse_dep_file() will error out with "no targets found"
and it is a correct error message.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 01b5cbe7 11-Jan-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: use malloc() and read() to load dep_file to buffer

Commit dee81e988674 ("fixdep: faster CONFIG_ search") changed how to
read files in which CONFIG options are searched. It used malloc()
and read() instead of mmap() because it needed to zero-terminate the
buffer in order to use strstr(). print_deps() was left untouched
since there was no reason to change it.

Now, I have two motivations to change it in the same way.

- do_config_file() and print_deps() do quite similar things; they
open a file, load it onto memory, and pass it to a parser function.
If we use malloc() and read() for print_deps() too, we can factor
out the common code. (I will do this in the next commit.)

- parse_dep_file() copies each token to a temporary buffer because
it needs to zero-terminate it to be passed to printf(). It is not
possible to modify the buffer directly because it is mmap'ed with
O_RDONLY. If we load the file content into a malloc'ed buffer, we
can insert '\0' after each token, and save memcpy(). (I will do
this in the commit after next.)

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 41f92cff 11-Jan-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

fixdep: remove unnecessary <arpa/inet.h> inclusion

<arpa/inet.h> was included for ntohl(), but it was removed by
commit dee81e988674 ("fixdep: faster CONFIG_ search").

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 7c2ec43a 08-Jan-2018 Lukas Bulwahn <lukas.bulwahn@gmail.com>

fixdep: exit with error code in error branches of do_config_file()

do_config_file() should exit with an error code on internal run-time
errors, and not return if it fails as then the error in do_config_file()
would go unnoticed in the current code and allow the build to continue.
The exit with error code will make the build fail in those very
exceptional cases. If this occurs, this actually indicates a deeper
problem in the execution of the kernel build process.

Now, in these error cases, we do not explicitly free memory and close
the file handlers in do_config_file(), as this is covered by exit().

This issue in the fixdep script was introduced with its initial
implementation back in 2002 by the original author Kai Germaschewski with
this commit 04bd72170653 ("kbuild: Make dependencies at compile time")
in the linux history git tree, i.e.,
git://git.kernel.org/pub/scm/linux/kernel/git/history/history.git.

This issue was identified during the review of a previous patch that
intended to address a memory leak detected by a static analysis tool.

Link: https://lkml.org/lkml/2017/12/14/736

Suggested-by: Nicholas Mc Guire <der.herr@hofr.at>
Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 4e433fc4 08-Aug-2017 Cao jin <caoj.fnst@cn.fujitsu.com>

fixdep: trivial: typo fix and correction

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# dee81e98 24-Aug-2016 Alexey Dobriyan <adobriyan@gmail.com>

fixdep: faster CONFIG_ search

Do you think kernel build is 100% dominated by gcc? You are wrong!
One small utility called "fixdep" consistently manages to sneak into
profile's first page (unless you have small monitor of course).

The choke point is this clever code:

for (; m < end; m++) {
if (*m == INT_CONF) { p = (char *) m ; goto conf; }
if (*m == INT_ONFI) { p = (char *) m-1; goto conf; }
if (*m == INT_NFIG) { p = (char *) m-2; goto conf; }
if (*m == INT_FIG_) { p = (char *) m-3; goto conf; }

4 branches per 4 characters is not fast.

Use strstr(3), so that SSE2 etc can be used.

With this patch, fixdep is so deep at the bottom, it is hard to find it.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>


# c1a95fda 22-Jan-2016 Nicolas Pitre <nico@fluxnic.net>

kbuild: add fine grained build dependencies for exported symbols

Like with kconfig options, we now have the ability to compile in and
out individual EXPORT_SYMBOL() declarations based on the content of
include/generated/autoksyms.h. However we don't want the entire
world to be rebuilt whenever that file is touched.

Let's apply the same build dependency trick used for CONFIG_* symbols
where the time stamp of empty files whose paths matching those symbols
is used to trigger fine grained rebuilds. In our case the key is the
symbol name passed to EXPORT_SYMBOL().

However, unlike config options, we cannot just use fixdep to parse
the source code for EXPORT_SYMBOL(ksym) because several variants exist
and parsing them all in a separate tool, and keeping it in synch, is
not trivially maintainable. Furthermore, there are variants such as

EXPORT_SYMBOL_GPL(pci_user_read_config_##size);

that are instanciated via a macro for which we can't easily determine
the actual exported symbol name(s) short of actually running the
preprocessor on them.

Storing the symbol name string in a special ELF section doesn't work
for targets that output assembly or preprocessed source.

So the best way is really to leverage the preprocessor by having it
output actual symbol names anchored by a special sequence that can be
easily filtered out. Then the list of symbols is simply fed to fixdep
to be merged with the other dependencies.

That implies the preprocessor is executed twice for each source file.
A previous attempt relied on a warning pragma for each EXPORT_SYMBOL()
instance that was filtered apart from stderr by the build system with
a sed script during the actual compilation pass. Unfortunately the
preprocessor/compiler diagnostic output isn't stable between versions
and this solution, although more efficient, was deemed too fragile.

Because of the lowercasing performed by fixdep, there might be name
collisions triggering spurious rebuilds for similar symbols. But this
shouldn't be a big issue in practice. (This is the case for CONFIG_*
symbols and I didn't want to be different here, whatever the original
reason for doing so.)

To avoid needless build overhead, the exported symbol name gathering is
performed only when CONFIG_TRIM_UNUSED_KSYMS is selected.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>


# d8329e35 12-Feb-2016 Nicolas Pitre <nico@fluxnic.net>

fixdep: accept extra dependencies on stdin

... and merge them in the list of parsed dependencies.

Signed-off-by: Nicolas Pitre <nico@linaro.org>


# 46fe94ad 07-Dec-2015 Tom Rini <trini@konsulko.com>

kbuild: fixdep: Check fstat(2) return value

Coverity has recently added a check that will find when we don't check
the return code from fstat(2). Copy/paste the checking logic that
print_deps() has with an appropriate re-wording of the perror() message.

Signed-off-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Michal Marek <mmarek@suse.com>


# 4c835b57 18-Nov-2015 Nicolas Iooss <nicolas.iooss_linux@m4x.org>

fixdep: constify strrcmp arguments

strrcmp only performs read access to the memory addressed by its
arguments so make them const pointers.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: Michal Marek <mmarek@suse.com>


# d179e227 23-Jul-2015 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: fixdep: drop meaningless hash table initialization

The clear_config() is called just once at the beginning of this
program, but the global variable hashtab[] is already zero-filled
at the start-up.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Michal Marek <mmarek@suse.com>


# d7211096 23-Jul-2015 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: fixdep: optimize code slightly

If the target string matches "CONFIG_", move the pointer p
forward. This saves several 7-chars adjustments.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Michal Marek <mmarek@suse.com>


# bb66fc67 10-Jun-2014 Masahiro Yamada <yamada.m@jp.panasonic.com>

kbuild: trivial - use tabs for code indent where possible

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 2ab8a996 06-Mar-2013 Stephen Warren <swarren@nvidia.com>

kbuild: fixdep: support concatenated dep files

The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.

In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.

The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.

Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>


# 8a168ca7 28-Dec-2012 Masanari Iida <standby24x7@gmail.com>

treewide: Fix typo in various drivers

Correct spelling typo in printk within various drivers.

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# 6a5be57f 01-Aug-2011 Peter Foley <pefoley2@verizon.net>

fixdep: fix extraneous dependencies

The introduction of include/linux/kconfig.h created 3 extraneous
dependencies:
include/config/.h
include/config/h.h
include/config/foo.h

Fix this by excluding kconfig.h from fixdep calculations.

Signed-off-by: Peter Foley <pefoley2@verizon.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 7840fea2 11-Mar-2011 Michal Marek <mmarek@suse.cz>

kbuild: Fix computing srcversion for modules

Recent change to fixdep:

commit b7bd182176960fdd139486cadb9962b39f8a2b50
Author: Michal Marek <mmarek@suse.cz>
Date: Thu Feb 17 15:13:54 2011 +0100

fixdep: Do not record dependency on the source file itself

changed the format of the *.cmd files without realizing that it is also
used by modpost. Put the path to the source file to the file back, in a
special variable, so that modpost sees all source files when calculating
srcversion for modules.

Reported-and-tested-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


# b7bd1821 17-Feb-2011 Michal Marek <mmarek@suse.cz>

fixdep: Do not record dependency on the source file itself

The dependency is already expressed by the Makefiles, storing it in the
.cmd file breaks build if a .c file is replaced by .S or vice versa,
because the .cmd file contains

foo/bar.o: foo/bar.c ...

foo/bar.c ... :

so the foo/bar.c -> foo/bar.o rule triggers even if there is no
foo/bar.c anymore.

Acked-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# a3ba8113 22-Dec-2010 Ben Gamari <bgamari.foss@gmail.com>

Make fixdep error handling more explicit

Also add missing error handling to fstat call

Signed-off-by: Ben Gamari <bgamari.foss@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 8af27e1d 09-Nov-2010 Eric Dumazet <eric.dumazet@gmail.com>

fixdep: use hash table instead of a single array

I noticed fixdep uses ~2% of cpu time in kernel build, in function
use_config()

fixdep spends a lot of cpu cycles in linear searches in its internal
string array. With about 400 stored strings per dep file, this begins to
be noticeable.

Convert fixdep to use a hash table.

kbuild results on my x86_64 allmodconfig

Before patch :

real 10m30.414s
user 61m51.456s
sys 8m28.200s

real 10m12.334s
user 61m50.236s
sys 8m30.448s

real 10m42.947s
user 61m50.028s
sys 8m32.380s

After:

real 10m8.180s
user 61m22.506s
sys 8m32.384s

real 10m35.039s
user 61m21.654s
sys 8m32.212s

real 10m14.487s
user 61m23.498s
sys 8m32.312s

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 264a2683 17-Oct-2009 Sam Ravnborg <sam@ravnborg.org>

kbuild: move autoconf.h to include/generated

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# f0a75770 24-Jul-2009 Trevor Keith <tsrk@tsrk.net>

trivial: kbuild: remove extraneous blank line after declaration of usage()

Signed-off-by: Trevor Keith <tsrk@tsrk.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# 7d3392e5 11-Jun-2009 Markus Heidelberg <markus.heidelberg@web.de>

trivial: remove references to non-existent include/linux/config.h

Ignore drivers/staging/ since it is very likely that new drivers
introduce it again.

Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# 4356f489 18-Sep-2009 Trevor Keith <tsrk@tsrk.net>

kbuild: add static to prototypes

Warnings found via gcc -Wmissing-prototypes.

Signed-off-by: Trevor Keith <tsrk@tsrk.net>
Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# d067aa74 10-Jun-2009 Amerigo Wang <amwang@redhat.com>

kbuild: fix a compile warning

gcc-4.4.1:

HOSTCC scripts/basic/fixdep
scripts/basic/fixdep.c: In function 'traps':
scripts/basic/fixdep.c:377: warning: dereferencing type-punned pointer will break strict-aliasing rules
scripts/basic/fixdep.c:379: warning: dereferencing type-punned pointer will break strict-aliasing rules

(Apparently -fno-strict-aliasing will fix this too)

Signed-off-by: WANG Cong <amwang@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 04c58f81 01-May-2007 Andy Green <andy@warmcat.com>

kbuild: scripts/basic/fixdep segfault on pathological string-o-death

build scripts: fixdep blows segfault on string CONFIG_MODULE seen

The string "CONFIG_MODULE" appearing anywhere in a source file causes
fixdep to segfault. This string appeared in the wild in the current
mISDN sources (I think they meant CONFIG_MODULES). But it shouldn't
segfault (esp as CONFIG_MODULE appeared in a quoted string).

Signed-off-by: Andy Green <andy@warmcat.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# c21b1e4d 29-Mar-2007 Jan Beulich <jbeulich@novell.com>

[PATCH] kbuild: fix dependency generation

Commit 2e3646e51b2d6415549b310655df63e7e0d7a080 changed the way the
split config tree is built, but failed to also adjust fixdep accordingly
- if changing a config option from or to m, files referencing the
respective CONFIG_..._MODULE (but not the corresponding CONFIG_...)
didn't get rebuilt.

The problem is that trisate symbol are represent with three different
symbols:
SYMBOL=n => no symbol defined
SYMBOL=y => CONFIG_SYMBOL defined to '1'
SYMBOL=m => CONFIG_SYMBOL_MODULE defined to '1'

But conf_split_config do not distingush between the =y and =m case, so
only the =y case is honoured.

This is fixed in fixdep so when a CONFIG symbol with _MODULE is found we
skip that part and only look for the CONFIG_SYMBOL version.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


# 6176aa9a 30-Jan-2006 Jan Beulich <jbeulich@novell.com>

kbuild: consolidate command line escaping

While the recent change to also escape # symbols when storing C-file
compilation command lines was helpful, it should be in effect for all
command lines, as much as the dollar escaping should be in effect for
C-source compilation commands. Additionally, for better readability and
maintenance, consolidating all the escaping (single quotes, dollars,
and now sharps) was also desirable.

Signed-Off-By: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 4d99f93b 25-Dec-2005 Sam Ravnborg <sam@mars.ravnborg.org>

kbuild: escape '#' in .target.cmd files

Commandlines are contained in the .<target>.cmd files and in case they
contain a '#' char make see this as start of comment.
Teach fixdep to escape the '#' char so make will assing the full commandline.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 48b9d03c 25-Jun-2005 J.A. Magallon <jamagallon@able.es>

[PATCH] Kill signed chars

scripts/ is full of mismatches between char* params an signed char* arguments,
and viceversa. gcc4 now complaints loud about this. Patch below deletes all
those 'signed'.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>


# 1da177e4 16-Apr-2005 Linus Torvalds <torvalds@ppc970.osdl.org>

Linux-2.6.12-rc2

Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.

Let it rip!