Commit Graph

292091 Commits

Author SHA1 Message Date
simonb 80f785edc2 Update -m description to reflect reality. Kernel dynamic memory tracking
was removed long ago; only pool usage is reported.
2021-12-13 08:19:12 +00:00
rillig 671f55cc50 make: condense CondParser_ComparisonOp
No functional change.
2021-12-13 07:47:07 +00:00
rillig acaf7a811d make: fix memory leak when parsing '.if ${expr}' (since 2004-04-13)
$ (
	echo 'VAR=value'
	perl -e 'printf(".if \${VAR}\n.endif\n" x 5000);';
	echo 'all:'
	printf '\t%s\n' \
	    '@pid=$$$$; \' \
	    'ppid=$$(ps -o ppid -p "$$pid" | sed 1d); \' \
	    'ps -o vsz,rsz -p $$ppid | sed 1d'
) > leak-cond2.mk

$ make-2004.04.08.07.24.26 -r -f leak-cond.mk
2668
$ make-2004.04.13.16.06.23 -r -f leak-cond.mk
3964

$ echo $(((3964 - 2668) * 1000 / 5000))
259

This 259 is close enough to the 256 from Buf_Init in CondParser_Leaf.
2021-12-13 07:06:39 +00:00
rillig a6eeb27f5d make: clean up loading of files
The call to Buf_DoneData was useless since ownership of the buffer data
has already been passwed on to loadedfile_create and the local variable
'buf' goes out of scope after that statement.

Except for cleaning up in debug mode, there is no reason to call
Buf_DoneData and then discard the returned value.

No functional change.
2021-12-13 06:11:34 +00:00
rillig 5da10dfc62 make: fix memory leak for filenames in .for loops (since 2013-06-18)
Previously, each time a .for directive pushed its buffer on the input
file stack, the current filename was duplicated.  This was a waste of
memory.

The name of a file is typically only used while it is read in.  There is
one situation when the filename is needed for longer, which is when a
target is defined.

Since .for loops are implemented as a special form of included files,
each .for loop duplicated the current filename as well.

$ cat << EOF > for.mk
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor

all:
	@ps -o rsz -p ${.MAKE.PID}
EOF

$ make-2021.12.13.03.55.16 -r -f for.mk
  RSZ
10720

$ ./make -r -f for.mk
 RSZ
1716

The difference is 8 MB, which amounts to 1 million .for loops.
2021-12-13 05:25:04 +00:00
rillig ee69cf194d make: fix memory leak when parsing a variable name
To trigger the memory leak, the expanded variable name must not be a
prefix of the textual variable name.

	textual name		expanded name
ok:	UNDEF.${undef}		UNDEF.
leak:	UNDEF.${undef}.		UNDEF..
2021-12-13 04:18:01 +00:00
rillig 21cb46b924 make: reduce memory allocation in modifier ':?'
The memory allocation was in LazyBuf_DoneGet.  The substring for the
untaken branch had been allocated even though it was not necessary.

No functional change.
2021-12-13 03:55:16 +00:00
rillig 5f71b45ef2 make: reduce memory allocations in modifier ':C'
The memory allocation was in the call to LazyBuf_DoneGet.

No functional change.
2021-12-13 03:41:57 +00:00
rillig 83e5bc3015 make: condense RegexReplace for the modifier ':C'
No functional change.
2021-12-13 03:19:32 +00:00
kre 30ec2d6e25 mv out: label into the #ifdef _KERNEL section, as it is only
referenced from there.  Hopefully ubbreak buikd of usr.sbin/crash
2021-12-13 03:17:50 +00:00
rillig 4724a17eb6 make: in the modifier ':C', don't call strlen unnecessarily
No functional change.
2021-12-13 03:03:42 +00:00
rillig 79438dd14d make: extract RegexReplaceBackref from RegexReplace
No functional change.
2021-12-13 02:57:44 +00:00
msaitoh ee532b2421 Use unsigned to avoid undefined behavior. Found by kUBSan.
Reported-by: syzbot+699ce32cd32e2a670788@syzkaller.appspotmail.com
2021-12-13 02:53:43 +00:00
rillig eee933da20 make: merge duplicate code for memory handling in Var_Parse
No functional change.
2021-12-13 02:34:15 +00:00
rillig 0729e01b00 make: fix remaining memory leak for .SUFFIXES (since yesterday) 2021-12-13 02:22:14 +00:00
rillig dae09ef292 make: distinguish between short-lived and environment variables
No functional change.
2021-12-13 02:17:59 +00:00
rillig 8739b19227 make: rename VarFreeEnv to VarFreeShortLived
The newly added "variable" .SUFFIXES is short-lived as well, which makes
it necessary to distinguish between environment variables and
short-lived variables.

No binary change.
2021-12-13 02:07:58 +00:00
rillig 2c4470c7fa make: fix indentation in meta.c 2021-12-13 01:51:12 +00:00
rillig 80015ebbbf make: clean up code for freeing short-lived variables
Since yesterday's addition of the short-lived "variable" named
.SUFFIXES, not only environment variables are short-lived.  Clean up the
code to prepare for fixing the remaining memory leaks.

No functional change.
2021-12-13 01:37:51 +00:00
chs 3bb0445a32 revert rev 1.4 ("Add garbage instructions at end of kern_assert after vpanic.")
that change had no effect because vpanic() is marked __dead / noreturn
and thus the compiler would optimize away everything after a call to vpanic().
the original problem has now been fixed differently (but only for x86 so far).
2021-12-13 01:33:32 +00:00
chs 6ee08449c7 ddb: fix function names of "noreturn" functions in stack traces.
when looking up function names for stack traces (where the addresses are the
return addresses of function calls), if the address is the first instruction
in the function, assume that the function being called is marked "noreturn"
and that the function containing the call is actually the function immediately
before the address that we looked up.  to find the correct function name,
do the lookup again with (address - 1) and then add one to the offset within
the function that we find.
2021-12-13 01:25:29 +00:00
rillig 1cf50694da make: fix memory leak when evaluating ${.SUFFIXES} (since yesterday)
perl -e '
    printf(".SUFFIXES: %s\n", "x" x 224);
    printf("_:=\${.SUFFIXES}\n" x 100_000);
    printf("all:\n");
' \
| MALLOC_CONF=stats_print:true \
    ./make -r -f - 2>&1 \
| awk '/bins:/,/^ *256/ { print $1 "\t" $4}'

Roughly 100000 less allocations for bin size 16, for the variable name.
2021-12-13 01:00:10 +00:00
rillig aba504eebb make: fix memory leak when evaluating ${.SUFFIX} (since yesterday) 2021-12-13 00:33:33 +00:00
rillig ba8c4744d3 make: fix memory leak in IncludeFile
Previously, each .include leaked a copy of the file name.
2021-12-13 00:09:07 +00:00
rillig 50a3da6336 make: in Arch_ParseArchive, rename libName to lib
For symmetry with mem.

No binary change.
2021-12-12 23:47:21 +00:00
rillig 1d8e4d76b5 make: remove unused type MFStr
The only binary change is the line number of the assertion in
Substring_Sub.
2021-12-12 23:39:34 +00:00
rillig 6b18044f86 make: in Arch_ParseArchive, replace MFStr with FStr
This was the only use of the type MFStr, which produced the same code as
FStr.

No binary change.
2021-12-12 23:32:03 +00:00
dholland 602dabe914 Add a bunch of missing food items. 2021-12-12 22:58:35 +00:00
rillig 2b9d8aa505 make: use simpler memory management for parsing archive members
No functional change.
2021-12-12 22:41:47 +00:00
andvar 1cb7819f04 fix various typos in comments. 2021-12-12 22:20:52 +00:00
rillig e67aefd60c tests/make: test and document the newly added "variable" .SUFFIXES 2021-12-12 22:16:48 +00:00
sjg 4587900247 Add .SUFFIXES as read-only variable.
References to ${.SUFFIXES} are handled dynamically in
ParseVarnameLong by calling Suff_NamesStr.

The variable cannot be set normally.

Reviewed by: rillig
2021-12-12 20:45:48 +00:00
maya 1eb4f57936 Add amdgpu firmware build goo (disabled) 2021-12-12 20:33:21 +00:00
maya 60f8009839 Import nvidia firmware from linux-firmware repository at commit:
commit 2984e265cac6ef19a0de4fb21396fb87f45273d9
Merge: 6f5aada 359ab77
Author: Josh Boyer <jwboyer@kernel.org>
Date:   Fri Sep 3 11:11:05 2021 -0400

    Merge tag 'iwlwifi-fw-2021-09-02' of git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware into main

    Revert accidentally released untested binaries

    Signed-off-by: Josh Boyer <jwboyer@kernel.org>

Done by removing tegra related directories in linux-firmware.
2021-12-12 18:35:57 +00:00
sjg f20fafd705 ParseVarnameLong: minimize calls to LazyBuf_Get
Reviewed by: rillig
2021-12-12 16:41:39 +00:00
maya 2f02086553 Import AMDGPU firmware from linux-firmware repository at commit:
commit 2984e265cac6ef19a0de4fb21396fb87f45273d9
Merge: 6f5aada 359ab77
Author: Josh Boyer <jwboyer@kernel.org>
Date:   Fri Sep 3 11:11:05 2021 -0400

    Merge tag 'iwlwifi-fw-2021-09-02' of git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware into main

    Revert accidentally released untested binaries

    Signed-off-by: Josh Boyer <jwboyer@kernel.org>

Cherry picking files using the following method:
grep -R MODULE_FIRMWARE bsd/drm2/dist/drm/amd

Replace macros as needed.
Exclues navi10_mes.bin which doesn't exist on linux-firmware for some
reason.
2021-12-12 16:39:53 +00:00
rillig d7cf274423 make: rename Parse_SetInput to Parse_PushInput
The word 'set' sounded too much like it would replace the current file,
but instead the file is pushed to the stack, and the previous file is
continued later.

No functional change.
2021-12-12 15:44:41 +00:00
rillig 881d54021a make: remove unused loadedfile.path 2021-12-12 15:36:52 +00:00
nia 8bb8291bb8 Fix copypasto in comment. 2021-12-12 14:33:13 +00:00
rillig bf7e076867 make: rename ForLoop.sub_next to nextItem
This matches the naming style of the other ForLoop members.

No functional change.
2021-12-12 14:27:48 +00:00
rillig dfdc7d4060 make: fix memory leak in LazyBuf
This affects many operations on variable expressions.  Those using
LazyBuf_Done are affected, those using LazyBuf_DoneGet aren't.

$ cat <<'EOF' > lazybuf-memleak.mk
.for i in ${:U:range=5}
.  for j in ${:U:range=1000}
.    for k in ${:U:range=1000}
.      if 0 && ${VAR:Dpattern\: that needs unescaping}
.      endif
.    endfor
.  endfor
.endfor

all:
	@ps -o vsz -p ${.MAKE.PID} | sed 1d
EOF

Before using LazyBuf for the modifier ':D':

    $ make-2021.04.14.16.12.26 -r -f lazybuf-memleak.mk
        VSZ     RSZ
    1357136 1336432

Using LazyBuf for the modifier ':D':

    $ make-2021.04.14.16.59.34 -r -f lazybuf-memleak.mk
        VSZ     RSZ
    1590864 1574164

This commit alone allocates around 150 MB more data, which matches
5_000_000 strings * 30 bytes/string.

It looks very wrong that the above simple makefile uses 1.3 GB of RAM at
all, and it had already done this in 2017, long before LazyBuf was
introduced.  Before 2017.01.30.02.46.20, the above test makefile reports
way smaller numbers, but that's because the modifier ':range' did not
exist back then.
2021-12-12 13:43:47 +00:00
andvar 1d09ce80b3 fix various typos, mainly in comments. 2021-12-12 13:05:13 +00:00
andvar b5a5957fe8 s/Miscelaneous/Miscellaneous/ and s/slahes/slashes/ in comments. 2021-12-12 11:18:46 +00:00
andvar 4075f0e731 s/Miscellanous/Miscellaneous/ in copypasta comments. 2021-12-12 11:10:03 +00:00
rillig 6028922aa9 make: remove enum.o from Makefile.boot
On 2021-11-18, enum.h and enum.c have been removed.
2021-12-12 11:02:23 +00:00
rillig 3c5bb9b19b make: do not report '?' for fully covered header files 2021-12-12 10:53:37 +00:00
rillig d4dbd5c396 make: only define target report-coverage if USE_COVERAGE is yes
Without USE_COVERAGE, GCOV was undefined, the '2>&1' passed all error
messages to GCOV_PERL, when then discarded them.  If the error messages
had been left on stderr, the error message 'sh: arch.o.gcda: not found'
would have been a clear indicator of the actual cause of an empty
coverage report.
2021-12-12 10:33:03 +00:00
rillig 8a2ea6b511 tests/make: add tests for irrelevant function calls 2021-12-12 09:49:09 +00:00
rillig fb0e49c8d2 tests/make: refine comments for parsing and evaluating conditions 2021-12-12 09:36:00 +00:00
andvar 0e6a3361ec fix typos in word "request(s)". 2021-12-12 09:00:07 +00:00