Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] [pre-commit] Two symlink fixes
@ 2026-09-01 20:27 Tom de Vries
  2026-09-01 20:27 ` [PATCH 1/2] [pre-commit] Reject symlinks in check-file-mode Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom de Vries @ 2026-09-01 20:27 UTC (permalink / raw)
  To: gdb-patches

This series has two patches.

The first extends check-file-mode to disallow symlinks.

The second adds a new pre-commit hook check-copies.

Tom de Vries (2):
  [pre-commit] Reject symlinks in check-file-mode
  [pre-commit] Add check-copies

 .pre-commit-config.yaml        | 15 ++++++-
 gdb/contrib/check-copies.py    | 54 ++++++++++++++++++++++++
 gdb/contrib/check-file-mode.sh | 77 +++++++++++++++++++++++-----------
 gdbserver/.shellcheckrc        |  4 +-
 gdbsupport/.shellcheckrc       |  4 +-
 5 files changed, 126 insertions(+), 28 deletions(-)
 create mode 100755 gdb/contrib/check-copies.py
 mode change 120000 => 100644 gdbserver/.shellcheckrc
 mode change 120000 => 100644 gdbsupport/.shellcheckrc


base-commit: 6f24afa4391bd33f1263378280b99385d2c13055
-- 
2.51.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] [pre-commit] Reject symlinks in check-file-mode
  2026-09-01 20:27 [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
@ 2026-09-01 20:27 ` Tom de Vries
  2026-09-01 20:27 ` [PATCH 2/2] [pre-commit] Add check-copies Tom de Vries
  2026-09-15  6:54 ` [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
  2 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2026-09-01 20:27 UTC (permalink / raw)
  To: gdb-patches

In a recent commit I introduced two symlinks.

After reading a bit more about it, I realized that this can be problematic on
platforms without proper support for it [1].

Which is probably also the reason why there aren't any symlinks in the repo
other than those two.

Eliminate the symlinks, and extend check-file-mode to reject symlinks.

While we're at it, move the existing check into a function, and improve
comments and error message a bit.

[1] https://gitforwindows.org/symbolic-links.html
---
 .pre-commit-config.yaml        |  4 ++
 gdb/contrib/check-file-mode.sh | 77 +++++++++++++++++++++++-----------
 gdbserver/.shellcheckrc        |  4 +-
 gdbsupport/.shellcheckrc       |  4 +-
 4 files changed, 63 insertions(+), 26 deletions(-)
 mode change 120000 => 100644 gdbserver/.shellcheckrc
 mode change 120000 => 100644 gdbsupport/.shellcheckrc

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0b4285e6c82..34d2cba40b9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -151,6 +151,10 @@ repos:
         language: unsupported_script
         entry: gdb/contrib/check-file-mode.sh
         files: *gdb_files
+        # With the default types == [file], because types and types_or are
+        # and-ed, no symlinks will be selected, so we use types == [] instead.
+        types: []
+        types_or: [file, symlink]
       - id: &id5 shellcheck
         name: *id5
         files: '^(gdb|gdbsupport|gdbserver)/'
diff --git a/gdb/contrib/check-file-mode.sh b/gdb/contrib/check-file-mode.sh
index 5a9b0e89fbe..e9cfaf02ce4 100755
--- a/gdb/contrib/check-file-mode.sh
+++ b/gdb/contrib/check-file-mode.sh
@@ -17,30 +17,59 @@
 set -e
 set -o pipefail
 
-no_exec_files=()
-for f in "$@"; do
-    case $f in
-	*/*.py \
-	    | */*.sh \
-	    | */configure \
-	    | gdb/gstack-1.in \
-	    | gdb/gcore-1.in \
-	    | gdb/po/gdbtext \
-	    | gdb/make-init-c \
-	    | gdb/testsuite/lib/notty-wrap )
-	    continue
-	    ;;
-	*)
-	    no_exec_files=("${no_exec_files[@]}" "$f")
-	    ;;
-    esac
-done
+# Flag files that are executable, but not meant to be executable.
+check_exec ()
+{
+    no_exec_files=()
+    for f in "$@"; do
+	case $f in
+	    */*.py \
+		| */*.sh )
+		# Shell script or python.
+		continue
+		;;
+	    gdb/po/gdbtext \
+		| gdb/make-init-c \
+		| gdb/testsuite/lib/notty-wrap )
+		# Shell script without .sh extension.
+		continue
+		;;
+	    */configure \
+		| gdb/gstack-1.in \
+		| gdb/gcore-1.in )
+		# Used to generate shell script.
+		continue
+		;;
+	    *)
+		no_exec_files=("${no_exec_files[@]}" "$f")
+		;;
+	esac
+    done
 
-if [ ${#no_exec_files[@]} -eq 0 ]; then
-    exit 0
-fi
+    if [ ${#no_exec_files[@]} -eq 0 ]; then
+	return
+    fi
 
-# Flag files that are executable, but not meant to be executable.
+    if ! git ls-files --stage -- "${no_exec_files[@]}" \
+	    | (! grep '^100755 '); then
+	echo "Found executable mode (100755) on file without .sh or .py"
+	echo "Please fix or add to exception list in $0"
+	exit 1
+    fi
+}
+
+# Flag symlinks.  Symlinks are support by git, but can be problematic on
+# platforms without proper support for it [1].
+# [1] https://gitforwindows.org/symbolic-links.html
+check_symlinks ()
+{
+    if ! git ls-files --stage -- "$@" \
+	    | (! grep '^120000 '); then
+	echo "Found symlink mode (120000)"
+	echo "Please replace by copy"
+	exit 1
+    fi
+}
 
-git ls-files --stage -- "${no_exec_files[@]}" \
-    | (! grep '^100755 ')
+check_exec "$@"
+check_symlinks "$@"
diff --git a/gdbserver/.shellcheckrc b/gdbserver/.shellcheckrc
deleted file mode 120000
index 2a49a004d21..00000000000
--- a/gdbserver/.shellcheckrc
+++ /dev/null
@@ -1 +0,0 @@
-../gdb/.shellcheckrc
\ No newline at end of file
diff --git a/gdbserver/.shellcheckrc b/gdbserver/.shellcheckrc
new file mode 100644
index 00000000000..91b66edaf7a
--- /dev/null
+++ b/gdbserver/.shellcheckrc
@@ -0,0 +1,3 @@
+# SC2002 was disabled by default in 0.11.0.  Turn it on for
+# compatibility with 0.10.0.
+enable=useless-use-of-cat
diff --git a/gdbsupport/.shellcheckrc b/gdbsupport/.shellcheckrc
deleted file mode 120000
index 2a49a004d21..00000000000
--- a/gdbsupport/.shellcheckrc
+++ /dev/null
@@ -1 +0,0 @@
-../gdb/.shellcheckrc
\ No newline at end of file
diff --git a/gdbsupport/.shellcheckrc b/gdbsupport/.shellcheckrc
new file mode 100644
index 00000000000..91b66edaf7a
--- /dev/null
+++ b/gdbsupport/.shellcheckrc
@@ -0,0 +1,3 @@
+# SC2002 was disabled by default in 0.11.0.  Turn it on for
+# compatibility with 0.10.0.
+enable=useless-use-of-cat
-- 
2.51.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] [pre-commit] Add check-copies
  2026-09-01 20:27 [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
  2026-09-01 20:27 ` [PATCH 1/2] [pre-commit] Reject symlinks in check-file-mode Tom de Vries
@ 2026-09-01 20:27 ` Tom de Vries
  2026-09-15  6:54 ` [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
  2 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2026-09-01 20:27 UTC (permalink / raw)
  To: gdb-patches

Instead of using symlinks we maintain identical files, which is
error-prone [1].

Add pre-commit hook check-copies:
...
$ pre-commit run check-copies --all-files -v
check-copies............................................................Passed
- hook id: check-copies
- duration: 0.51s
...
that checks that:
- files that need to be copies are in fact copies, and
- no other files are copies.

I've excluded the testsuite from this check, to avoid having to handle:
...
Accidental copies found: [ \
  'gdb/testsuite/config/arm-ice.exp', 'gdb/testsuite/config/bfin.exp', \
  'gdb/testsuite/config/cygmon.exp', 'gdb/testsuite/config/h8300.exp', \
  'gdb/testsuite/config/i386-bozo.exp']
Accidental copies found: [ \
  'gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.c', \
  'gdb/testsuite/gdb.base/run-after-attach.c']
Accidental copies found: [ \
  'gdb/testsuite/gdb.rocm/addr-bp-gpu-no-deb-info.cpp', \
  'gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.cpp']
...

[1] https://sourceware.org/pipermail/gdb-patches/2026-September/229897.html
---
 .pre-commit-config.yaml     | 11 ++++++--
 gdb/contrib/check-copies.py | 54 +++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100755 gdb/contrib/check-copies.py

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 34d2cba40b9..6d60f81c483 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -123,14 +123,14 @@ repos:
         entry: gdb/check-include-guards.py
         # All gdb header files, but not headers in the test suite.
         files: '^(gdb(support|server)?)/.*\.h$'
-        exclude: '.*/testsuite/.*'
+        exclude: &testsuite_files '.*/testsuite/.*'
       - id: &id1 check-gnu-style
         name: *id1
         language: python
         additional_dependencies: ['termcolor', 'unidiff']
         entry: gdb/contrib/check-gnu-style-pre-commit.sh
         files: '^(gdb(support|server)?)/.*\.(c|h|cc)$'
-        exclude: '.*/testsuite/.*'
+        exclude: *testsuite_files
         verbose: true
       - id: &id2 check-whitespace
         name: *id2
@@ -173,6 +173,13 @@ repos:
         args: [--config-check]
         additional_dependencies: ["pyyaml"]
         files: *pre_commit_config_file
+      - id: &id7 check-copies
+        name: *id7
+        language: unsupported_script
+        entry: gdb/contrib/check-copies.py
+        files: *gdb_files
+        exclude: *testsuite_files
+        require_serial: true
 
 # Local Variables:
 # indent-tabs-mode: nil
diff --git a/gdb/contrib/check-copies.py b/gdb/contrib/check-copies.py
new file mode 100755
index 00000000000..11c226bb9d2
--- /dev/null
+++ b/gdb/contrib/check-copies.py
@@ -0,0 +1,54 @@
+#! /usr/bin/env python3
+
+import subprocess
+import sys
+from itertools import chain
+
+# These files are required to be identical.
+required_list = [
+    ["gdb/.dir-locals.el", "gdbserver/.dir-locals.el", "gdbsupport/.dir-locals.el"],
+    ["gdb/.shellcheckrc", "gdbserver/.shellcheckrc", "gdbsupport/.shellcheckrc"],
+]
+
+
+def run_cmd(cmd, **kwargs):
+    res = subprocess.run(cmd, **kwargs)
+    if res.returncode != 0:
+        raise RuntimeError(
+            "command %s failed with exit status %s" % (cmd, res.returncode)
+        )
+    return res
+
+
+files = sys.argv[1:]
+always_check_files = list(chain.from_iterable(required_list))
+cmd = ["git", "ls-files", "--stage"] + files + always_check_files
+res = run_cmd(cmd, capture_output=True, text=True)
+
+hash_dict = {}
+for line in res.stdout.splitlines():
+    parts = line.split(maxsplit=3)
+    hash = parts[1]
+    file = parts[3]
+    hash_dict.setdefault(hash, []).append(file)
+
+copies = []
+for hash in hash_dict:
+    files = hash_dict[hash]
+    if len(files) == 1:
+        continue
+    copies.append(set(files))
+
+required_set = [set(r) for r in required_list]
+
+for required in required_set:
+    if required in copies:
+        continue
+    print("No longer copies: %s" % required)
+    sys.exit(1)
+
+for copy in copies:
+    if copy in required_set:
+        continue
+    print("Accidental copies found: %s" % copy)
+    sys.exit(1)
-- 
2.51.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] [pre-commit] Two symlink fixes
  2026-09-01 20:27 [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
  2026-09-01 20:27 ` [PATCH 1/2] [pre-commit] Reject symlinks in check-file-mode Tom de Vries
  2026-09-01 20:27 ` [PATCH 2/2] [pre-commit] Add check-copies Tom de Vries
@ 2026-09-15  6:54 ` Tom de Vries
  2 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2026-09-15  6:54 UTC (permalink / raw)
  To: gdb-patches

On 9/1/26 10:27 PM, Tom de Vries wrote:
> This series has two patches.
> 
> The first extends check-file-mode to disallow symlinks.
> 
> The second adds a new pre-commit hook check-copies.
> 

I've pushed this.

Thanks,
- Tom

> Tom de Vries (2):
>    [pre-commit] Reject symlinks in check-file-mode
>    [pre-commit] Add check-copies
> 
>   .pre-commit-config.yaml        | 15 ++++++-
>   gdb/contrib/check-copies.py    | 54 ++++++++++++++++++++++++
>   gdb/contrib/check-file-mode.sh | 77 +++++++++++++++++++++++-----------
>   gdbserver/.shellcheckrc        |  4 +-
>   gdbsupport/.shellcheckrc       |  4 +-
>   5 files changed, 126 insertions(+), 28 deletions(-)
>   create mode 100755 gdb/contrib/check-copies.py
>   mode change 120000 => 100644 gdbserver/.shellcheckrc
>   mode change 120000 => 100644 gdbsupport/.shellcheckrc
> 
> 
> base-commit: 6f24afa4391bd33f1263378280b99385d2c13055


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-15  6:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-01 20:27 [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
2026-09-01 20:27 ` [PATCH 1/2] [pre-commit] Reject symlinks in check-file-mode Tom de Vries
2026-09-01 20:27 ` [PATCH 2/2] [pre-commit] Add check-copies Tom de Vries
2026-09-15  6:54 ` [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox