[2/2,applied] abi{compat,diff,dw,pkgdiff},kmidiff: Fix short options handling

Message ID 87y0enmclv.fsf@seketeli.org
State New
Headers
Series [1/2,applied] abicompat: Do not abort when abicompat is invoked without argument |

Commit Message

Dodji Seketeli Aug. 3, 2026, 3:45 p.m. UTC
  Hello,

Some tools were defining short option aliases using OPTION_ALIAS with
argp.  These aliases make it so that a short option 't' would have
been invoked with '--j' instead of '-j'.

This patch removes those aliases by directly assigning the short
option character to the option key enum value, which is the proper way
to define short options with argp.

	* tools/abicompat.cc (enum option_key): Assign 'u' to
	OPT_LIST_UNDEFINED_SYMBOLS and 'b' to OPT_SHOW_BASE_NAMES. Adjust
	subsequent enum values to avoid conflicts.
	(argp_options): Remove OPTION_ALIAS entries for "u" and "b".
	* tools/abidiff.cc (enum option_key): Assign 'w' to
	OPT_KMI_WHITELIST, 'l' to OPT_LEAF_CHANGES_ONLY, 'x' to
	OPT_NO_CHANGE_CATEGORIZATION, and 't' to
	OPT_NON_REACHABLE_TYPES. Adjust subsequent enum values.
	(argp_options): Remove OPTION_ALIAS entries for "w", "l", "x", and
	"t".
	* tools/abidw.cc (enum option_key): Assign 'd' to
	OPT_DEBUG_INFO_DIR, 'w' to OPT_KMI_WHITELIST, and 'o' to
	OPT_OUT_FILE. Adjust subsequent enum values.
	(argp_options): Remove OPTION_ALIAS entries for "d", "w", and "o".
	* tools/abipkgdiff.cc (enum option_key): Assign 'f' to
	OPT_FULL_IMPACT, 'i' to OPT_IMPACTED_INTERFACES, 'w' to
	OPT_KMI_WHITELIST, 'l' to OPT_LEAF_CHANGES_ONLY, and 't' to
	OPT_NON_REACHABLE_TYPES.  Adjust subsequent enum values.
	(argp_options): Remove OPTION_ALIAS entries for "f", "i", "w",
	"l", and "t".
	* tools/kmidiff.cc (enum option_key): Adjust OPT_SHOW_BITS to
	follow OPT_EXPORTED_INTERFACES_ONLY instead of using a hardcoded
	value.
	(argp_options): Remove OPTION_ALIAS entry for "w".

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 tools/abicompat.cc  | 10 ++++------
 tools/abidiff.cc    | 20 ++++++++------------
 tools/abidw.cc      | 15 ++++++---------
 tools/abipkgdiff.cc | 23 ++++++++++-------------
 tools/kmidiff.cc    |  3 +--
 5 files changed, 29 insertions(+), 42 deletions(-)
  

Patch

diff --git a/tools/abicompat.cc b/tools/abicompat.cc
index 61c43679..eecadf19 100644
--- a/tools/abicompat.cc
+++ b/tools/abicompat.cc
@@ -745,12 +745,12 @@  enum option_key
   OPT_IGNORE_SONAME,
   OPT_LIB_DEBUG_INFO_DIR1,
   OPT_LIB_DEBUG_INFO_DIR2,
-  OPT_LIST_UNDEFINED_SYMBOLS,
-  OPT_NO_REDUNDANT,
+  OPT_LIST_UNDEFINED_SYMBOLS = 'u',
+  OPT_NO_REDUNDANT = OPT_LIB_DEBUG_INFO_DIR2 + 1,
   OPT_NO_SHOW_LOCS,
   OPT_REDUNDANT,
-  OPT_SHOW_BASE_NAMES,
-  OPT_SUPPR,
+  OPT_SHOW_BASE_NAMES = 'b',
+  OPT_SUPPR = OPT_REDUNDANT + 1,
   OPT_WEAK_MODE,
 };
 
@@ -779,7 +779,6 @@  static const struct argp_option argp_options[] =
   { "libd2", OPT_LIB_DEBUG_INFO_DIR2, "PATH", OPTION_ALIAS, 0, 0 },
   { "list-undefined-symbols", OPT_LIST_UNDEFINED_SYMBOLS, 0, 0,
     "display the list of undefined symbols of the application", 0 },
-  { "u", OPT_LIST_UNDEFINED_SYMBOLS, 0, OPTION_ALIAS, 0, 0 },
   { "no-redundant", OPT_NO_REDUNDANT, 0, 0,
     "do not display redundant changes", 0 },
   { "no-show-locs", OPT_NO_SHOW_LOCS, 0, 0,
@@ -789,7 +788,6 @@  static const struct argp_option argp_options[] =
   { "show-base-names", OPT_SHOW_BASE_NAMES, 0, 0,
     "in the report, only show the base names of the files; not the full paths",
     0 },
-  { "b", OPT_SHOW_BASE_NAMES, 0, OPTION_ALIAS, 0, 0 },
   { "suppressions", OPT_SUPPR, "PATH", 0,
     "specify a suppression file", 0 },
   { "suppr", OPT_SUPPR, "PATH", OPTION_ALIAS, 0, 0 },
diff --git a/tools/abidiff.cc b/tools/abidiff.cc
index e51a81ce..24ab6d5e 100644
--- a/tools/abidiff.cc
+++ b/tools/abidiff.cc
@@ -243,13 +243,13 @@  enum option_key
   OPT_KEEP,
   OPT_KEEP_FN,
   OPT_KEEP_VAR,
-  OPT_KMI_WHITELIST,
-  OPT_LDEPS,
-  OPT_LEAF_CHANGES_ONLY,
-  OPT_NO_ADDED_SYMS,
+  OPT_KMI_WHITELIST = 'w',
+  OPT_LDEPS = OPT_KEEP_VAR + 1,
+  OPT_LEAF_CHANGES_ONLY = 'l',
+  OPT_NO_ADDED_SYMS = OPT_LDEPS + 1,
   OPT_NO_ARCH,
-  OPT_NO_CHANGE_CATEGORIZATION,
-  OPT_NO_CORPUS_PATH,
+  OPT_NO_CHANGE_CATEGORIZATION = 'x',
+  OPT_NO_CORPUS_PATH = OPT_NO_ARCH + 1,
   OPT_NO_DEFAULT_SUPPRESSION,
   OPT_NO_HARMFUL,
   OPT_NO_LEVERAGE_DWARF_FACTORIZATION,
@@ -259,8 +259,8 @@  enum option_key
   OPT_NO_SHOW_LOCS,
   OPT_NO_SHOW_RELATIVE_OFFSET_CHANGES,
   OPT_NO_UNREFERENCED_SYMBOLS,
-  OPT_NON_REACHABLE_TYPES,
-  OPT_REDUNDANT,
+  OPT_NON_REACHABLE_TYPES = 't',
+  OPT_REDUNDANT = OPT_NO_UNREFERENCED_SYMBOLS + 1,
   OPT_SHOW_BITS,
   OPT_SHOW_BYTES,
   OPT_SHOW_DEC,
@@ -366,11 +366,9 @@  static const struct argp_option argp_options[] =
     "keep only variables matching a regex", 0 },
   { "kmi-whitelist", OPT_KMI_WHITELIST, "PATH", 0,
     "path to a linux kernel abi whitelist", 0 },
-  { "w", OPT_KMI_WHITELIST, "PATH", OPTION_ALIAS, 0, 0 },
   { "leaf-changes-only", OPT_LEAF_CHANGES_ONLY, 0, 0,
     "only show leaf changes, so no change impact analysis "
     "(implies --redundant)", 0 },
-  { "l", OPT_LEAF_CHANGES_ONLY, 0, OPTION_ALIAS, 0, 0 },
   { "list-dependencies", OPT_LDEPS, 0, 0,
     "show the dependencies of the input files", 0 },
   { "ldeps", OPT_LDEPS, 0, OPTION_ALIAS, 0, 0 },
@@ -382,7 +380,6 @@  static const struct argp_option argp_options[] =
     "do not assume the ODR to speed-up the analysis of the binary", 0 },
   { "no-change-categorization", OPT_NO_CHANGE_CATEGORIZATION, 0, 0,
     "don't perform categorization of changes, for speed purposes", 0 },
-  { "x", OPT_NO_CHANGE_CATEGORIZATION, 0, OPTION_ALIAS, 0, 0 },
   { "no-corpus-path", OPT_NO_CORPUS_PATH, 0, 0,
     "do not take the path to the corpora into account", 0 },
   { "no-default-suppression", OPT_NO_DEFAULT_SUPPRESSION, 0, 0,
@@ -408,7 +405,6 @@  static const struct argp_option argp_options[] =
     "do not display changes about symbols not referenced by debug info", 0 },
   { "non-reachable-types", OPT_NON_REACHABLE_TYPES, 0, 0,
     "consider types non reachable from public interfaces", 0 },
-  { "t", OPT_NON_REACHABLE_TYPES, 0, OPTION_ALIAS, 0, 0 },
   { "redundant", OPT_REDUNDANT, 0, 0,
     "display redundant changes", 0 },
   { "show-bits", OPT_SHOW_BITS, 0, 0,
diff --git a/tools/abidw.cc b/tools/abidw.cc
index fd466638..d0b2e075 100644
--- a/tools/abidw.cc
+++ b/tools/abidw.cc
@@ -854,8 +854,8 @@  enum option_key
   OPT_DEBUG_ABIDIFF,
   OPT_DEBUG_DC,
   OPT_DEBUG_TC,
-  OPT_DEBUG_INFO_DIR,
-  OPT_DROP_PRIVATE_TYPES,
+  OPT_DEBUG_INFO_DIR = 'd',
+  OPT_DROP_PRIVATE_TYPES = OPT_DEBUG_TC + 1,
   OPT_DROP_UNDEFINED_SYMS,
   OPT_EXPORTED_INTERFACES_ONLY,
   OPT_FAIL_NO_DEBUG_INFO,
@@ -863,8 +863,8 @@  enum option_key
   OPT_FORCE_EARLY_SUPPRESSION,
   OPT_HD,
   OPT_HF,
-  OPT_KMI_WHITELIST,
-  OPT_LDEPS,
+  OPT_KMI_WHITELIST = 'w',
+  OPT_LDEPS = OPT_HF + 1,
   OPT_LINUX_TREE,
   OPT_LOAD_ALL_TYPES,
   OPT_NO_ARCH,
@@ -879,8 +879,8 @@  enum option_key
   OPT_NO_SHOW_LOCS,
   OPT_NO_WRITE_DEFAULT_SIZES,
   OPT_NOOUT,
-  OPT_OUT_FILE,
-  OPT_SHORT_LOCS,
+  OPT_OUT_FILE = 'o',
+  OPT_SHORT_LOCS = OPT_NOOUT + 1,
   OPT_SHOW_STATS,
   OPT_SUPPR,
   OPT_TYPE_ID_STYLE,
@@ -928,7 +928,6 @@  static const struct argp_option argp_options[] =
 #endif
   { "debug-info-dir", OPT_DEBUG_INFO_DIR, "PATH", 0,
     "look for debug info under 'dir-path'", 0 },
-  { "d", OPT_DEBUG_INFO_DIR, "PATH", OPTION_ALIAS, 0, 0 },
   { "drop-private-types", OPT_DROP_PRIVATE_TYPES, 0, 0,
     "drop private types from internal representation", 0 },
   { "drop-undefined-syms", OPT_DROP_UNDEFINED_SYMS, 0, 0,
@@ -950,7 +949,6 @@  static const struct argp_option argp_options[] =
   { "kmi-whitelist", OPT_KMI_WHITELIST, "PATH", 0,
     "path to a linux kernel abi whitelist", 0 },
   { "kmi-stablelist", OPT_KMI_WHITELIST, "PATH", OPTION_ALIAS, 0, 0 },
-  { "w", OPT_KMI_WHITELIST, "PATH", OPTION_ALIAS, 0, 0 },
   { "list-dependencies", OPT_LDEPS, 0, 0,
     "list the dependencies of a given binary", 0 },
   { "linux-tree", OPT_LINUX_TREE, 0, 0,
@@ -987,7 +985,6 @@  static const struct argp_option argp_options[] =
     "do not emit anything after reading the binary", 0 },
   { "out-file", OPT_OUT_FILE, "PATH", 0,
     "write the output to 'file-path'", 0 },
-  { "o", OPT_OUT_FILE, "PATH", OPTION_ALIAS, 0, 0 },
   { "short-locs", OPT_SHORT_LOCS, 0, 0,
     "only print filenames rather than paths", 0 },
   { "stats", OPT_SHOW_STATS, 0, 0,
diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc
index eb28f4b2..0bb8cb64 100644
--- a/tools/abipkgdiff.cc
+++ b/tools/abipkgdiff.cc
@@ -3693,15 +3693,15 @@  enum option_key
   OPT_DSO_ONLY,
   OPT_EXPORTED_INTERFACES_ONLY,
   OPT_FAIL_NO_DBG,
-  OPT_FULL_IMPACT,
-  OPT_HARMLESS,
+  OPT_FULL_IMPACT = 'f',
+  OPT_HARMLESS = OPT_FAIL_NO_DBG + 1,
   OPT_IGNORE_SONAME,
-  OPT_IMPACTED_INTERFACES,
-  OPT_KEEP_TMP_FILES,
-  OPT_KMI_WHITELIST,
-  OPT_KMI_WHITELIST_PKG,
-  OPT_LEAF_CHANGES_ONLY,
-  OPT_NO_ABIGNORE,
+  OPT_IMPACTED_INTERFACES = 'i',
+  OPT_KEEP_TMP_FILES = OPT_IGNORE_SONAME + 1,
+  OPT_KMI_WHITELIST = 'w',
+  OPT_KMI_WHITELIST_PKG = OPT_KEEP_TMP_FILES + 1,
+  OPT_LEAF_CHANGES_ONLY = 'l',
+  OPT_NO_ABIGNORE = OPT_KMI_WHITELIST_PKG + 1,
   OPT_NO_ADDED_BINARIES,
   OPT_NO_ADDED_SYMS,
   OPT_NO_ASSUME_ODR_FOR_CPLUSPLUS,
@@ -3712,8 +3712,8 @@  enum option_key
   OPT_NO_SHOW_LOCS,
   OPT_NO_SHOW_RELATIVE_OFFSET_CHANGES,
   OPT_NO_UNREFERENCED_SYMBOLS,
-  OPT_NON_REACHABLE_TYPES,
-  OPT_PRIVATE_DSO,
+  OPT_NON_REACHABLE_TYPES = 't',
+  OPT_PRIVATE_DSO = OPT_NO_UNREFERENCED_SYMBOLS + 1,
   OPT_REDUNDANT,
   OPT_SELF_CHECK,
   OPT_SET1,
@@ -3763,14 +3763,12 @@  static const struct argp_option argp_options[] =
   { "full-impact", OPT_FULL_IMPACT, 0, 0,
     "when comparing kernel packages, show the full impact analysis report "
     "rather than the default leaf changes reports", 0 },
-  { "f", OPT_FULL_IMPACT, 0, OPTION_ALIAS, 0, 0 },
   { "harmless", OPT_HARMLESS, 0, 0,
     "display the harmless changes", 0 },
   { "ignore-soname", OPT_IGNORE_SONAME, 0, 0,
     "do not take the SONAMEs into account", 0 },
   { "impacted-interfaces", OPT_IMPACTED_INTERFACES, 0, 0,
     "display interfaces impacted by leaf changes", 0 },
-  { "i", OPT_IMPACTED_INTERFACES, 0, OPTION_ALIAS, 0, 0 },
   { "keep-tmp-files", OPT_KEEP_TMP_FILES, 0, 0,
     "don't erase created temporary files", 0 },
   { "linux-kernel-abi-whitelist", OPT_KMI_WHITELIST, "PATH", 0,
@@ -3781,7 +3779,6 @@  static const struct argp_option argp_options[] =
   { "leaf-changes-only", OPT_LEAF_CHANGES_ONLY, 0, 0,
     "only show leaf changes, so no change impact analysis "
     "(implies --redundant)", 0 },
-  { "l", OPT_LEAF_CHANGES_ONLY, 0, OPTION_ALIAS, 0, 0 },
   { "no-abignore", OPT_NO_ABIGNORE, 0, 0,
     "do not look for *.abignore files", 0 },
   { "no-added-binaries", OPT_NO_ADDED_BINARIES, 0, 0,
diff --git a/tools/kmidiff.cc b/tools/kmidiff.cc
index 170778f0..ce0d306a 100644
--- a/tools/kmidiff.cc
+++ b/tools/kmidiff.cc
@@ -110,7 +110,7 @@  enum option_key
   OPT_IMPACTED_INTERFACES = 'i',
   OPT_KMI_WHITELIST = 'w',
   OPT_NO_CHANGE_CATEGORIZATION = 'x',
-  OPT_SHOW_BITS = 262,
+  OPT_SHOW_BITS = OPT_EXPORTED_INTERFACES_ONLY + 1,
   OPT_SHOW_BYTES,
   OPT_SHOW_DEC,
   OPT_SHOW_HEX,
@@ -146,7 +146,6 @@  static const struct argp_option argp_options[] =
     "show interfaces impacted by ABI changes", 0 },
   { "linux-kernel-abi-whitelist", OPT_KMI_WHITELIST, "PATH", 0,
     "path to a linux kernel abi whitelist", 0 },
-  { "w", OPT_KMI_WHITELIST, "PATH", OPTION_ALIAS, 0, 0 },
   { "no-change-categorization", OPT_NO_CHANGE_CATEGORIZATION, 0, 0,
     "don't perform categorization of changes, for speed purposes", 0 },
   { "show-bits", OPT_SHOW_BITS, 0, 0,