Skip to contentSkip to conversation

sparse/semind: add the new --param=dissect-show-compiled option

PATCH In review Oleg Nesterov 2 participants 4 messages Dec 26, 2025 – Dec 27, 2025 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sparse/semind: add the new --param=dissect-show-compiled option

parse_cmdline_add() sets dissect_show_all_symbols = 1 unconditionally and currently it is not possible to clear this option.

We could simply remove this line; users could use "semind add --param=dissect-show-all-symbols," but this would break existing setups.

---
 options.c | 2 ++
 semind.c  | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
options.c +2 -0
index 0f207e80..dbe0349f 100644
@@ -976,6 +976,8 @@ static char **handle_param(char *arg, char **next)
 
 	if (!strcmp(value, "dissect-show-all-symbols"))
 		dissect_show_all_symbols = 1;
+	else if (!strcmp(value, "dissect-show-compiled"))
+		dissect_show_all_symbols = 0;
 
 	return next;
 }
semind.c +2 -2
index ad8003ba..fa084e04 100644
@@ -322,14 +322,14 @@ done:
 		show_usage();
 	}
 
-	// enforce tabstop
+	// enforce defaults
 	tabstop = 1;
+	dissect_show_all_symbols = 1;
 
 	// step back since sparse_initialize will ignore argv[0].
 	optind--;
 
 	sparse_initialize(argc - optind, argv + optind, &semind_filelist);
-	dissect_show_all_symbols = 1;
 }
 
 static void parse_cmdline_rm(int argc, char **argv)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 2/2 sparse/semind: robustify parse_cmdline_add()

"semind add -ftabstop=8 ..." works as expected, but (for example) "semind add --param=dissect-show-all-symbols ..." doesn't, this arg is not passed to sparse_initialize().

Because in the latter case getopt_long() increments optind when it sees --param=dissect-show-all-symbols. I have no idea if getopt_long() is correct or not, but lets change parse_cmdline_add() so that it doesn't depend on getopt_long()'s behaviour.

---
 semind.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
semind.c +4 -4
index fa084e04..e9708444 100644
@@ -298,7 +298,7 @@ static void parse_cmdline_add(int argc, char **argv)
 		{ "help", no_argument, NULL, 'h' },
 		{ NULL }
 	};
-	int c;
+	int parsed = optind, c;
 
 	opterr = 0;
 
@@ -315,6 +315,7 @@ static void parse_cmdline_add(int argc, char **argv)
 			case '?':
 				goto done;
 		}
+		parsed = optind;
 	}
 done:
 	if (optind == argc) {
@@ -327,9 +328,8 @@ done:
 	dissect_show_all_symbols = 1;
 
 	// step back since sparse_initialize will ignore argv[0].
-	optind--;
-
-	sparse_initialize(argc - optind, argv + optind, &semind_filelist);
+	parsed--;
+	sparse_initialize(argc - parsed, argv + parsed, &semind_filelist);
 }
 
 static void parse_cmdline_rm(int argc, char **argv)
Signature · 1 line
2.52.0
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] sparse/semind: robustify parse_cmdline_add()

Quoted 10 lines · Oleg Nesterov

"semind add -ftabstop=8 ..." works as expected, but (for example) "semind add --param=dissect-show-all-symbols ..." doesn't, this arg is not passed to sparse_initialize().

Because in the latter case getopt_long() increments optind when it sees --param=dissect-show-all-symbols. I have no idea if getopt_long() is correct or not, but lets change parse_cmdline_add() so that it doesn't depend on getopt_long()'s behaviour.

Hm. This behavior seems very strange to me. I couldn't find an explanation for it in getopt_long(3) man page. But I tried this sample with glibc and musl, and the behavior was the same and does not depend on POSIXLY_CORRECT

  #include <stdio.h>
  #include <getopt.h>
  
  int main(int argc, char **argv)
  {
          char c;
          opterr = 0;
          while ((c = getopt_long(argc, argv, "", NULL, NULL)) != -1) {
                  if (c != '?')
                          printf("unexpected known option: %c\n", c);
                  break;
          }
          printf("optind=%d\n", optind);
          return 0;

}

Here are the results from both libc:

for o in --f "--f f" -f -ff "-f f"; do printf '%s\t' "args='$o'"; ./z-musl $o; done
args='--f' optind=1
args='--f f' optind=1
args='-f' optind=2
args='-ff' optind=1
args='-f f' optind=2

So it seems that this is common behavior for different libc's. Thank you so much for finding this and fixing it!

Quoted 41 lines
---
 semind.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
semind.c +4 -4
index fa084e04..e9708444 100644
@@ -298,7 +298,7 @@ static void parse_cmdline_add(int argc, char **argv)
 		{ "help", no_argument, NULL, 'h' },
 		{ NULL }
 	};
-	int c;
+	int parsed = optind, c;
 
 	opterr = 0;
 
@@ -315,6 +315,7 @@ static void parse_cmdline_add(int argc, char **argv)
 			case '?':
 				goto done;
 		}
+		parsed = optind;
 	}
 done:
 	if (optind == argc) {
@@ -327,9 +328,8 @@ done:
 	dissect_show_all_symbols = 1;
 
 	// step back since sparse_initialize will ignore argv[0].
-	optind--;
-
-	sparse_initialize(argc - optind, argv + optind, &semind_filelist);
+	parsed--;
+	sparse_initialize(argc - parsed, argv + parsed, &semind_filelist);
 }
 
 static void parse_cmdline_rm(int argc, char **argv)
Signature · 1 line
2.52.0
Signature · 1 line
Rgrds, legion
Acked-by on v1 1/2
#3 lore raw
In reply to Oleg Nesterov
Quoted 8 lines · Oleg Nesterov

parse_cmdline_add() sets dissect_show_all_symbols = 1 unconditionally and currently it is not possible to clear this option.

We could simply remove this line; users could use "semind add --param=dissect-show-all-symbols," but this would break existing setups.

Quoted 43 lines
---
 options.c | 2 ++
 semind.c  | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
options.c +2 -0
index 0f207e80..dbe0349f 100644
@@ -976,6 +976,8 @@ static char **handle_param(char *arg, char **next)
 
 	if (!strcmp(value, "dissect-show-all-symbols"))
 		dissect_show_all_symbols = 1;
+	else if (!strcmp(value, "dissect-show-compiled"))
+		dissect_show_all_symbols = 0;
 
 	return next;
 }
semind.c +2 -2
index ad8003ba..fa084e04 100644
@@ -322,14 +322,14 @@ done:
 		show_usage();
 	}
 
-	// enforce tabstop
+	// enforce defaults
 	tabstop = 1;
+	dissect_show_all_symbols = 1;
 
 	// step back since sparse_initialize will ignore argv[0].
 	optind--;
 
 	sparse_initialize(argc - optind, argv + optind, &semind_filelist);
-	dissect_show_all_symbols = 1;
 }
 
 static void parse_cmdline_rm(int argc, char **argv)
Signature · 1 line
2.52.0
Signature · 1 line
Rgrds, legion