Module Name: src Committed By: rillig Date: Fri Apr 28 13:09:48 UTC 2023
Modified Files: src/usr.bin/make/unit-tests: parse.mk var-scope-local.exp var-scope-local.mk Log Message: tests/make: add tests for target-local variables While here, move a test from var-scope-local.mk to parse.mk since that test is not related to variables. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/parse.mk cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/var-scope-local.exp cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/var-scope-local.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/unit-tests/parse.mk diff -u src/usr.bin/make/unit-tests/parse.mk:1.3 src/usr.bin/make/unit-tests/parse.mk:1.4 --- src/usr.bin/make/unit-tests/parse.mk:1.3 Sun Jul 24 20:25:23 2022 +++ src/usr.bin/make/unit-tests/parse.mk Fri Apr 28 13:09:48 2023 @@ -1,4 +1,4 @@ -# $NetBSD: parse.mk,v 1.3 2022/07/24 20:25:23 rillig Exp $ +# $NetBSD: parse.mk,v 1.4 2023/04/28 13:09:48 rillig Exp $ # # Test those parts of the parsing that do not belong in any of the other # categories. @@ -22,3 +22,33 @@ # # https://bugs.freebsd.org/265119 one-target ${:U } + + +# Since parse.c 1.656 from 2022-01-27 and before parse.c 1.662 from +# 2022-02-05, there was an out-of-bounds read in Parse_IsVar when looking for +# a variable assignment in a dependency line with trailing whitespace. Lines +# without trailing whitespace were not affected. Global variable assignments +# were guaranteed to have no trailing whitespace and were thus not affected. +# +# Try to reproduce some variants that may lead to a crash, depending on the +# memory allocator. To get a crash, the terminating '\0' of the line must be +# the last byte of a memory page. The expression '${:U}' forces this trailing +# whitespace. + +# On FreeBSD x86_64, a crash could in some cases be forced using the following +# line, which has length 47, and if the memory for the expanded line starts at +# 0xXXXX_XXd0, the terminating '\0' may end up at 0xXXXX_Xfff: +Try_to_crash_FreeBSD.xxxxxxxxxxxxxxxxxx: 12345 ${:U} + +# The following line has length 4095 after being expanded, so line[4095] == +# '\0'. If the line is +# allocated on a page boundary and the following page is not mapped, this line +# leads to a segmentation fault. +${:U:range=511:@_@1234567@:ts.}: 12345 ${:U} + +# The following line has length 8191, so line[8191] == '\0'. If the line is +# allocated on a page boundary and the following page is not mapped, this line +# leads to a segmentation fault. +${:U:range=1023:@_@1234567@:ts.}: 12345 ${:U} + +12345: Index: src/usr.bin/make/unit-tests/var-scope-local.exp diff -u src/usr.bin/make/unit-tests/var-scope-local.exp:1.4 src/usr.bin/make/unit-tests/var-scope-local.exp:1.5 --- src/usr.bin/make/unit-tests/var-scope-local.exp:1.4 Sat Mar 26 14:34:07 2022 +++ src/usr.bin/make/unit-tests/var-scope-local.exp Fri Apr 28 13:09:48 2023 @@ -1,5 +1,5 @@ -Global: .ALLTARGETS = one -Global: .ALLTARGETS = one two +Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one +Global: .ALLTARGETS = all target-rule.ext dir/subdir/target-rule.ext inference-rule.ir-to dir/subdir/inference-rule.ir-to inference-rule.ir-from dir/subdir/inference-rule.ir-from inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to inference-rule-chain.ir-gen-from dir/subdir/inference-rule-chain.ir-gen-from one two Var_Parse: ${.MAKE.TARGET_LOCAL_VARIABLES} (eval) Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored @@ -7,6 +7,46 @@ Global: one two = # (empty) Global: one two = three Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 +target-rule.ext: @ = <target-rule.ext> +target-rule.ext: % = <undefined> +target-rule.ext: ? = <> +target-rule.ext: < = <undefined> +target-rule.ext: * = <target-rule.ext> +dir/subdir/target-rule.ext: @ = <dir/subdir/target-rule.ext> +dir/subdir/target-rule.ext: % = <undefined> +dir/subdir/target-rule.ext: ? = <> +dir/subdir/target-rule.ext: < = <undefined> +dir/subdir/target-rule.ext: * = <dir/subdir/target-rule.ext> +inference-rule.ir-to: @ = <inference-rule.ir-to> +inference-rule.ir-to: % = <undefined> +inference-rule.ir-to: ? = <inference-rule.ir-from> +inference-rule.ir-to: < = <inference-rule.ir-from> +inference-rule.ir-to: * = <inference-rule> +dir/subdir/inference-rule.ir-to: @ = <dir/subdir/inference-rule.ir-to> +dir/subdir/inference-rule.ir-to: % = <undefined> +dir/subdir/inference-rule.ir-to: ? = <dir/subdir/inference-rule.ir-from> +dir/subdir/inference-rule.ir-to: < = <dir/subdir/inference-rule.ir-from> +dir/subdir/inference-rule.ir-to: * = <dir/subdir/inference-rule> +inference-rule-chain.ir-from: @ = <inference-rule-chain.ir-from> +inference-rule-chain.ir-from: % = <undefined> +inference-rule-chain.ir-from: ? = <inference-rule-chain.ir-gen-from> +inference-rule-chain.ir-from: < = <inference-rule-chain.ir-gen-from> +inference-rule-chain.ir-from: * = <inference-rule-chain> +inference-rule-chain.ir-to: @ = <inference-rule-chain.ir-to> +inference-rule-chain.ir-to: % = <undefined> +inference-rule-chain.ir-to: ? = <inference-rule-chain.ir-from> +inference-rule-chain.ir-to: < = <inference-rule-chain.ir-from> +inference-rule-chain.ir-to: * = <inference-rule-chain> +dir/subdir/inference-rule-chain.ir-from: @ = <dir/subdir/inference-rule-chain.ir-from> +dir/subdir/inference-rule-chain.ir-from: % = <undefined> +dir/subdir/inference-rule-chain.ir-from: ? = <dir/subdir/inference-rule-chain.ir-gen-from> +dir/subdir/inference-rule-chain.ir-from: < = <dir/subdir/inference-rule-chain.ir-gen-from> +dir/subdir/inference-rule-chain.ir-from: * = <dir/subdir/inference-rule-chain> +dir/subdir/inference-rule-chain.ir-to: @ = <dir/subdir/inference-rule-chain.ir-to> +dir/subdir/inference-rule-chain.ir-to: % = <undefined> +dir/subdir/inference-rule-chain.ir-to: ? = <dir/subdir/inference-rule-chain.ir-from> +dir/subdir/inference-rule-chain.ir-to: < = <dir/subdir/inference-rule-chain.ir-from> +dir/subdir/inference-rule-chain.ir-to: * = <dir/subdir/inference-rule-chain> : Making var-scope-local.c out of nothing. : Making var-scope-local.o from var-scope-local.c. : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".". Index: src/usr.bin/make/unit-tests/var-scope-local.mk diff -u src/usr.bin/make/unit-tests/var-scope-local.mk:1.5 src/usr.bin/make/unit-tests/var-scope-local.mk:1.6 --- src/usr.bin/make/unit-tests/var-scope-local.mk:1.5 Wed Feb 9 21:09:24 2022 +++ src/usr.bin/make/unit-tests/var-scope-local.mk Fri Apr 28 13:09:48 2023 @@ -1,4 +1,4 @@ -# $NetBSD: var-scope-local.mk,v 1.5 2022/02/09 21:09:24 rillig Exp $ +# $NetBSD: var-scope-local.mk,v 1.6 2023/04/28 13:09:48 rillig Exp $ # # Tests for target-local variables, such as ${.TARGET} or $@. These variables # are relatively short-lived as they are created just before making the @@ -12,6 +12,42 @@ .MAIN: all +# Target-local variables in a target rule +all: target-rule.ext dir/subdir/target-rule.ext +target-rule.ext dir/subdir/target-rule.ext: .PHONY + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +.SUFFIXES: .ir-gen-from .ir-from .ir-to +.ir-from.ir-to: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' +.ir-gen-from.ir-from: + @echo '$@: @ = <${@:Uundefined}>' + @echo '$@: % = <${%:Uundefined}>' + @echo '$@: ? = <${?:Uundefined}>' + @echo '$@: < = <${<:Uundefined}>' + @echo '$@: * = <${*:Uundefined}>' + +# Target-local variables in an inference rule +all: inference-rule.ir-to dir/subdir/inference-rule.ir-to +inference-rule.ir-from: .PHONY +dir/subdir/inference-rule.ir-from: .PHONY + +# Target-local variables in a chain of inference rules +all: inference-rule-chain.ir-to dir/subdir/inference-rule-chain.ir-to +inference-rule-chain.ir-gen-from: .PHONY +dir/subdir/inference-rule-chain.ir-gen-from: .PHONY + + +# Deferred evaluation during parsing +# # The target-local variables can be used in expressions, just like other # variables. When these expressions are evaluated outside of a target, these # expressions are not yet expanded, instead their text is preserved, to allow @@ -20,8 +56,8 @@ # # Conditions from .if directives are evaluated in the scope of the command # line, which means that variables from the command line, from the global -# scope and from the environment are resolved, in this order (but see the -# command line option '-e'). In that phase, expressions involving +# scope and from the environment are resolved, in this precedence order (but +# see the command line option '-e'). In that phase, expressions involving # target-local variables need to be preserved, including the exact names of # the variables. # @@ -77,13 +113,17 @@ .endif +# Custom local variables +# # Additional target-local variables may be defined in dependency lines. .MAKEFLAGS: -dv # In the following line, the ':=' may either be interpreted as an assignment # operator or as the dependency operator ':', followed by an empty variable # name and the assignment operator '='. It is the latter since in an -# assignment, the left-hand side must be at most a single word. The empty -# variable name is expanded twice, once for 'one' and once for 'two'. +# assignment, the left-hand side must be a single word or empty. +# +# The empty variable name is expanded twice, once for 'one' and once for +# 'two'. # expect: Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored # expect: Var_SetExpand: variable name "" expands to empty string, with value "three" - ignored one two:=three @@ -205,32 +245,3 @@ a_use: .USE VAR=use all: var-scope-local-use.o var-scope-local-use.o: a_use - - -# Since parse.c 1.656 from 2022-01-27 and before parse.c 1.662 from -# 2022-02-05, there was an out-of-bounds read in Parse_IsVar when looking for -# a variable assignment in a dependency line with trailing whitespace. Lines -# without trailing whitespace were not affected. Global variable assignments -# were guaranteed to have no trailing whitespace and were thus not affected. -# -# Try to reproduce some variants that may lead to a crash, depending on the -# memory allocator. To get a crash, the terminating '\0' of the line must be -# the last byte of a memory page. The expression '${:U}' forces this trailing -# whitespace. - -# On FreeBSD x86_64, a crash could in some cases be forced using the following -# line, which has length 47, so the terminating '\0' may end up at an address -# of the form 0xXXXX_XXXX_XXXX_Xfff: -Try_to_crash_FreeBSD.xxxxxxxxxxxxxxxxxx: 12345 ${:U} - -# The following line has length 4095, so line[4095] == '\0'. If the line is -# allocated on a page boundary and the following page is not mapped, this line -# leads to a segmentation fault. -${:U:range=511:@_@1234567@:ts.}: 12345 ${:U} - -# The following line has length 8191, so line[8191] == '\0'. If the line is -# allocated on a page boundary and the following page is not mapped, this line -# leads to a segmentation fault. -${:U:range=1023:@_@1234567@:ts.}: 12345 ${:U} - -12345: