Commit graph

3169 commits

Author SHA1 Message Date
Paul Smith
d523661ce2 [SV 66499] Detect jobserver values that are too large
Set the jobserver pipe to non-blocking before writing tokens; if a
token write fails the user's jobserver value is too large so fail.

Original implementation: Dmitry Goncharov <dgoncharov@users.sf.net>

* src/posixos.c (set_blocking): Split into force_blocking() which
always enables/disables blocking; set_blocking() may call it.
(jobserver_setup): Set the write side of the pipe to non-blocking
before writing tokens.  If it fails with EAGAIN we know the pipe
is full: create a fatal error.
* tests/scripts/features/jobserver: Test a too-large jobserver.
2024-12-08 23:30:37 -05:00
Paul Smith
f12a4fddce jobserver: Ensure the named pipe is deleted on error
Make sure the jobserver named pipe is deleted even if the
jobserver_setup() function calls fatal() and exits early.

* src/main.c (clean_jobserver): Always reset_jobserver().
* src/posixos.c (jobserver_setup): Set job_root up front.
* tests/test_driver.pl: Print out the logfile pathname on error.
For tests with regex matches this might be the only file available.
Don't print the base filename unless one is created.
2024-12-08 23:30:37 -05:00
Paul Smith
186522e480 * doc/make.texi: [SV 66324] Fix a typo 2024-12-08 23:30:00 -05:00
Dmitry Goncharov
aa8626ce09 [SV 66273] Double-colon targets must not be intermediate
An explicitly mentioned double-colon target cannot be intermediate.

* src/read.c (record_files): Set file->is_explicit in the case of an
explicitly mentioned file built by a double colon rule.
* src/file.c (print_file): Have print_file print whether a file is
explicitly mentioned.
* tests/scripts/features/patternrules: Add tests.
2024-10-01 22:27:25 -04:00
Dmitry Goncharov
93704dd565 [SV 66268] Include newlines in file removal error message
* src/file.c (remove_intermediates): Fix an error message about a
failure to remove an intermediate file.
* tests/scripts/features/patternrules: Add tests.
2024-10-01 22:14:31 -04:00
Paul Smith
101bf5636f * doc/make.texi: Clarify -j versus -jN behavior 2024-09-02 16:23:36 -04:00
Sergei Trofimovich
9251546bac Fix biased shuffle by avoiding already "struck" elements
Artem Klimov noticed that current shuffle implementation suffers from
probability bias due to a typical bug in the shuffling implementation.

When we consider already shuffled element we slightly bias their
propability.

https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
suggests shuffling each "struck" element only once.

Before the change probabilities of 4-element array to land from `i`
index to `j` index are:

          0     1     2     3
      _____ _____ _____ _____
  0 | 25.00 29.30 24.60 21.10
  1 | 25.00 22.25 28.13 24.63
  2 | 25.00 23.44 22.26 29.30
  3 | 25.00 25.01 25.01 24.98

Note that `0->1` probability is almost 29% while `0->3` os only 21%.

After the change probabilities are not as biased:

          0     1     2     3
      _____ _____ _____ _____
  0 | 24.99 24.99 25.01 25.01
  1 | 24.99 25.04 24.99 24.99
  2 | 25.01 25.00 25.00 24.99
  3 | 25.01 24.98 25.00 25.01

* src/shuffle.c (random_shuffle_array): Fix biased shuffle by avoiding
already "struck" elements.
2024-09-02 15:11:36 -04:00
Paul Smith
7dc23aff30 * doc/make.texi: GNUMAKEFLAGS is only read from the environment 2024-09-02 14:54:23 -04:00
Paul Eggert
0267eb64fa Check for snprintf truncation on W32
* src/main.c (find_and_set_default_shell) [MK_OS_W32]:
Do not use a buffer that snprintf truncated.
2024-09-02 14:43:24 -04:00
Paul Eggert
bba4427b5d Fix unlikely pointer overflow in abspath
* src/function.c (abspath): len is now ptrdiff_t,
to avoid GCC warning about comparing signed to unsigned.
It really is a pointer difference, after all.
Rejigger comparision to avoid undefined behavior
if dest + len is an invalid pointer.
2024-09-02 14:43:24 -04:00
Paul Eggert
c23a7e6232 Prefer memcpy to strncpy if either will do
strncpy is trickier and a bit slower.
* src/function.c (func_realpath, func_abspath):
* src/misc.c (xstrndup):
Prefer memcpy or mempcpy to strncpy when the source length is known.
2024-09-02 14:43:24 -04:00
Paul Eggert
4d3bf7838f Omit unused PATH_MAX code
* src/makeint.h (GET_PATH_MAX, PATH_VAR):
Simplify, since PATH_MAX is always defined here.
(NEED_GET_PATH_MAX): Remove.
* src/misc.c (get_path_max) [NEED_GET_PATH_MAX]: Remove.
2024-09-02 14:43:24 -04:00
Paul Eggert
8c8c7fc226 Avoid strlen calls after sprintf
* src/file.c (file_timestamp_sprintf):
* src/function.c (func_words, func_call):
* src/job.c (child_error):
* src/main.c (define_makeflags):
* src/output.c (message, error, fatal):
Use return value from sprintf instead of calling strlen
on the resulting buffer.
2024-09-02 14:43:24 -04:00
Paul Smith
9fee98f843 [SV 65759] Document special handling of "-" command line option
* doc/make.1: Add information on "-" option handling.
* doc/make.texi: Ditto.
2024-09-02 13:48:41 -04:00
Dan D
f800f8bae3 [SV 65777] Add more const
Add more const to static arrays.  On some systems this allows more
data to be placed in RO segments and shared between multiple
instances of the make executable.  Anyway more const is good hygiene.

* src/default.c: Add const to arrays.
* src/function.c: Ditto.
* src/hash.c: Ditto.
* src/hash.h: Ditto.
* src/job.c: Ditto.
* src/read.c: Ditto.
* src/remake.c: Ditto.
* src/rule.c: Ditto.
* src/rule.h: Ditto.
2024-09-02 13:48:30 -04:00
Paul Smith
39a4c81062 Remove obsolete email address for the FSF
* doc/make.texi: Use the newer email address in the manual.
* gl/lib/fnmatch.c: Use a URL instead of a street address.
* gl/lib/fnmatch.in.h: Ditto.
* gl/lib/glob.c: Ditto.
* gl/lib/glob.in.h: Ditto.
2024-09-01 21:12:37 -04:00
Paul Smith
d97e048b08 * bootstrap.conf: Update to newer prerequisites 2024-09-01 21:09:42 -04:00
Paul Smith
c63a5bc6a2 [SV 65917] Mark also_make targets as updated in make -n
Suggested patch by Hannes Domani <ssbssa@yahoo.de>

* src/remake.c (notice_finished_file): When run with -n, mark
also_make targets as updated.
* tests/scripts/options/dash-n: Test pattern and grouped targets.
2024-08-04 23:53:26 -04:00
Paul Smith
bc979e4949 * src/job.c (new_job): [SV-66030] Show all also-make targets 2024-08-04 17:16:23 -04:00
Paul Smith
6970561de0 Don't add a target to its own also_make list
* src/dep.h (copy_dep): Make a copy of one struct dep.
* src/misc.c (copy_dep): Implement the new function.
(copy_dep_chain): Call copy_dep() for each dep in the chain.
* src/read.c (record_files): Write our own copy loop and omit the
current file from its own also_make list.  Since we don't keep
the function's also_make, free it.
2024-08-04 17:13:07 -04:00
Paul Smith
f0db5e321f * doc/make.texi: [SV-65982] Clarify what --debug=makefile does 2024-08-04 16:04:19 -04:00
Paul Smith
8653c25fcf * src/remake.c (update_file_1): [SV 65999] Clarify debug output 2024-08-04 16:02:19 -04:00
Paul Smith
4d883c414d * doc/make.texi: [SV-66018] Mention .ONESHELL in [-+@] docs 2024-08-04 16:02:19 -04:00
Dmitry Goncharov
034f862361 [SV 66037] Avoid hang/crash from MAKEFLAGS=... on command line
Make enters an infinite loop when some option and MAKEFLAGS=<value>
are specified on the command line.  For example,
    $ make -r MAKEFLAGS=hello=world

If decode_switches() runs handle_non_switch_argument() from within
the getopt() loop, it would recursively call decode_switches() to
enter a new getopt() loop, corrupting the state of the outer loop.

* src/main.c (decode_switches): Save up non-option arguments and run
handle_non_switch_argument() only after we're done with getopt().
* tests/scripts/variables/MAKEFLAGS: Add tests.
2024-08-04 16:00:48 -04:00
Paul Smith
49b955a50d * doc/make.texi (Overview): Update reference to POSIX.1-2024 2024-08-04 15:21:59 -04:00
Paul Smith
69038e62e0 * src/warning.h: Put warnings into alphabetical order.
* src/warning.c: Ditto.
* tests/scripts/options/warn: Fix tests for the new order.
2024-08-04 15:21:59 -04:00
Dmitry Goncharov
a9e3eb1eec [SV 65739] Add warning circular-dep.
Add a warning to control circular dependency detection.  Use "warn" as
the default action to be backward-compatible.

* src/warning.h (enum warning_type): Add warning type wt_circular_dep.
* src/warning.c (warn_init): Set default wt_circular_dep to w_warn.
* src/remake.c (update_file_1): Consult the circular-dep warning to
handle circular dependencies.
* tests/scripts/options/warn: Test --warn circular-dep flag.
* tests/scripts/variables/WARNINGS: Test .WARNINGS circular-dep flag.
* doc/make.texi: Document circular-dep warning.
* doc/make.1: Ditto.
2024-08-04 15:21:59 -04:00
Dmitry Goncharov
e3f938caf8 * tests/scripts/functions/shell: [SV 65323] Run huge var test in bash
The long variable name causes ksh to crash.  Some systems use ksh as
/bin/sh, so force bash if it's available else skip the test.
2024-05-06 14:11:17 -04:00
Dmitry Goncharov
40664fef1f [SV 65324] disable_builtins: Don't dereference NULL suffix_file
Make crashes when -r and MAKEFLAGS= are specified on the command line.

On startup make begins to process command line arguments.
During processing of "MAKEFLAGS=" make calls reset_makeflags, which in
turn calls disable_builtins, which dereferences null suffix_file.
Here is the backtrace.

0 disable_builtins main.c:3482
1 reset_makeflags main.c:3104
2 set_special_var variable.c:1325
3 do_variable_definition variable.c:1693
4 try_variable_definition variable.c:1889
5 handle_non_switch_argument main.c:3021
6 decode_switches main.c:3150
7 main main.c:1621

* src/main.c (disable_builtins): Avoid dereferencing null suffix_file.
* tests/scripts/features/suffixrules: Add a test.
2024-05-06 14:11:17 -04:00
Paul Smith
f7985ab827 * make.texi (How to Use Variables): [SV 65536] Rewrite this chapter
Re-reading this chapter I decided it was time to introduce a complete
rewrite, of at least parts of this.  Much of the enhancements added
over the years were in the wrong place or not clear.
2024-05-06 14:11:17 -04:00
Paul Smith
8339232a2f * .dir-locals.el: Correct bug reference regex format 2024-04-14 15:51:23 -04:00
Paul Smith
949952258e [SV 65537] Update to newer gnulib
* bootstrap.conf: Switch to gnulib stable-202401 branch.
* maintMakefile: Support an EXTRA_CFLAGS variable in maintainer mode.
* README.git: Describe how to use it.
2024-04-14 15:27:37 -04:00
Paul Smith
479c54f6ed * NEWS: Clean up UTF-8 issues 2024-04-14 15:27:12 -04:00
Paul Smith
033330e34c * doc/make.texi (Pattern Rules): Clarify that rules must have recipes. 2024-03-28 19:14:25 -04:00
Paul Eggert
61ee4578f5 * src/arscan.c (parse_int): Fix integer overflow test
Use intprops.h macros rather than trying to detect integer overflow by
hand, and doing it incorrectly.  Example of incorrect behavior:
if val == 3689348814741910323, base == 10, UINTMAX_WIDTH == 64, and
 *ptr == '0' then (val*base)+(*ptr-'0') yields 18446744073709551614
which is greater than val even though overflow has occurred.
Fortunately this bug could not be triggered on GNU/Linux hosts,
although it may be possible on platforms (if any) where struct ar_hdr
has members so large that they can represent integers that do not fit
int uintmax_t.
2024-03-28 19:08:13 -04:00
KO Myung-Hun
f289ece6cf * src/makeint.h (JOBSERVER_USE_FIFO): Do not define on OS/2.
mkfifo() on OS/2 is a dummy, it even returns a wrong value on error.
2024-03-28 19:08:13 -04:00
Paul Smith
d791fb4139 * src/variable.c (do_variable_definition) [W32]: Fix bad variable. 2024-03-28 19:08:13 -04:00
Marco Sirabella
0b91f42f58 * src/arscan.c (ar_name_equal): Support GNU ar's -P option. 2024-03-28 19:08:13 -04:00
Marco Sirabella
882d59c672 * tests/README: Fix sample run_make_tests command line. 2024-03-24 16:36:35 -04:00
Paul Smith
5fc62f8295 * doc/make.texi: GNU Make does set GNUMAKEFLAGS, to empty. 2024-03-24 16:29:14 -04:00
Paul Smith
3d4f3e0627 * doc/make.texi: Document temporary file name prefix
* src/posixos.c (jobserver_setup): Set prefix for FIFO temp file.
Ensure it can't conflict with a "normal" temp file.
* src/w32/w32os.c (os_anontmp): Set prefix for anon temp files.
2024-03-24 16:23:28 -04:00
Paul Smith
242603fa46 [SV 65268] Un-set append mode for stdout/stderr on exit
It turns out that options set on stdout/stderr last after exit.
Leaving append-mode enabled can break other facilities, so reset the
flags on stdout/stderr before we exit.

* src/os.h: Add a new fd_reset_append() to reset flags on FDs.
Modify fd_set_append() to return the old flags.
* src/posixos.c (fd_reset_append): Set provided flags on the FD.
(fd_set_append): Return the previous flags set on the FD.
* src/output.c (output_init): Preserve old flags for stdout/stderr.
(output_close): Reset flags for stdout/stderr.
* src/w32/w32os.c: Implement dummy methods.
2024-03-24 15:25:53 -04:00
Paul Smith
b8a2a4424b [SV 65273] configure.ac: Remove check for sys/timeb.h
GNU Make doesn't use ftime(); we only checked for this to work around
an error in the completely obsolete SCO 3.2 system.  Since ftime() is
deprecated, including sys/timeb.h has started throwing warnings on
newer systems so just remove it completely.
Reported by: Collin Funk <collin.funk1@gmail.com>

* configure.ac: Remove the check for sys/timeb.h.
* src/makeint.h: Remove the include of sys/timeb.h.
* src/config.h-vms: Don't define HAVE_SYS_TIMEB_H.
* src/config.h.W32: Ditto.
2024-03-24 15:25:18 -04:00
Jouke Witteveen
bfbf169b63 [SV 65448] intcmp: Compare values instead of magnitudes
* src/function.c (func_intcmp): Reverse comparison direction when
both arguments are negative.
* tests/scripts/functions/intcmp: Add tests and remove useless ones.
2024-03-24 14:08:59 -04:00
Paul Smith
21a538ce8f [SV 65359] doc/make.texi: Describe invalid export variable names 2024-03-24 14:05:45 -04:00
Paul Smith
3176b60566 [SV 64085] Handle .POSIX plus .IGNORE correctly
POSIX requires that a conforming makefile should not use -e if
 1) make is invoked with -i
 2) A .IGNORE target exists with no prerequisites
 3) The current target is a prerequisite of .IGNORE

* src/job.c (start_job_command): Add the target's flags when
constructing argv so it can check (3) above.
(construct_command_argv_internal): Don't set shellflags if it's not
set: this only happens if we're parsing for the slow path and we
don't need them.
(construct_command_argv): Don't allocate buffers if not needed.
When detecting "-ec", check the global ignore_errors_flag and the
current command line flags.
* tests/scripts/targets/IGNORE: Add tests for .IGNORE.
* tests/scripts/targets/POSIX: Add tests for the three cases above.
2024-02-04 19:41:50 -05:00
Dmitry Goncharov
07187db947 [SV 64822, SV 36486] Fix appending to a pattern specific variable
Appending to a pattern specific variable produces an incorrect value
in the presence of a command line definition or an env override of
the variable.  Also, fix pattern/target-specific appending to a
variable with origin override.

* At parse time record_target_var sets the value of a pattern
  specific variable to the value defined on command line or to the
  value of the env override.
* Later, at build time, recursively_expand_for_file appends this
  value of the variable (set in record_target_var) to the command
  line value again, regardless of the origin of the variable.

This patch modifies recursively_expand_for_file to avoid appending,
unless the origin of the variable beats or equals the origin of one
of the parent definitions of this variable.

Reported by Rob <robw9739@gmail.com>,
Brian Vandenberg <phantall@gmail.com>,
Markus Oberhumer <markus@oberhumer.com>.

* NEWS: Note the change.
* src/variable.c (do_variable_definition): Avoid merging a
pattern-specific variable with the parent definition when a command
line or env override is present.
* src/expand.c (recursively_expand_for_file): Avoid appending to a
pattern-specific variable, unless the origin of this pattern-specific
variable beats or equals the origin of one of the parent definitions
of this variable.
* doc/make.texi (Override Directive): Add missing cross-reference.
* tests/scripts/variables/append: Add tests.
2024-02-04 18:26:21 -05:00
Paul Smith
a493d9ab6c * NEWS: Clean up 2024-02-04 11:34:49 -05:00
Dmitry Goncharov
a382ac6cd1 [SV 64803] Set origin for unmodified variables after -e
Ensure the origin of all variables inherited from the environment is
"environment override" if -e is given.  Previously only variables
that were set in the makefile had this origin.

PDS: Most of these changes are from Dmitry but I slightly modified
the algorithm: instead of rearranging the way in which MAKEFLAGS is
parsed we reset the env_override value to the default before we
re-parse MAKEFLAGS, then we set the origin of all env vars to the
correct value based on the new setting.

* NEWS: Mention the change for backward-compatibility.
* src/main.c (main): Ensure MAKEFLAGS is always marked special.
(reset_makeflags): Set env_overrides back to default before parsing
MAKEFLAGS.
(decode_switches): Call reset_env_override() to check for changes.
* src/variable.h (reset_env_override): Declare a new function.
* src/variable.c (reset_env_override): Go through all env variables
and ensure the origin is correct based on env_overrides.
(set_env_override): Helper function for the hash.
* tests/scripts/functions/foreach: Fix tests.
* tests/scripts/functions/let: Ditto.
* tests/scripts/functions/origin: Ditto.
* tests/scripts/options/dash-e: Add tests.
2024-02-04 11:34:49 -05:00
Paul Smith
63b602e74f * tests/test_driver.pl: Add cd to the .run output file 2024-02-04 11:34:49 -05:00