public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Don't process low-mem files in multifile mode
@ 2019-01-01  0:00 Tom de Vries
  2019-01-01  0:00 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

Hi,

Consider three executables, a.out and b.out with n DIEs, and c.out with
n + m DIEs.

When running in multifile mode, with a low-mem limit of n + m - 1 DIEs:
...
$ dwz -m common.out -l$(($n + $m - 1)) a.out b.out c.out
...
the expectation is that c.out is not used in multifile processing, because it
exceeds the low-mem limit.  However, all three files turn out to have the
.gnu_debugaltlink section, showing that in fact c.out was used in multifile
processing.

Fix this by adding a low_mem_p field to struct file_result, setting it in
function dwz and using it in main.

OK for trunk?

Thanks,
- Tom

Don't process low-mem files in multifile mode

2019-03-01  Tom de Vries  <tdevries@suse.de>

	PR dwz/24274
	* Makefile (TEST_EXECS): Add hello2.
	* dwz.c (struct file_result): Add low_mem_p field.
	(dwz): Set low_mem_p field.  Remove non-functional low_mem test.
	(main): Don't use low_mem_p files in multifile loop.
	* hello.c [HAVE_STRUCT] (struct a): New struct.
	[HAVE_STRUCT] (a): New var.
	(main) [HAVE_STRUCT]: Use a.
	* testsuite/dwz.tests/multifile-low-mem.sh: New test.

---
 Makefile                                 |  5 ++++-
 dwz.c                                    |  8 ++++++--
 hello.c                                  | 14 ++++++++++++++
 testsuite/dwz.tests/multifile-low-mem.sh | 26 ++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index bc51ca2..b8dd9ca 100644
--- a/Makefile
+++ b/Makefile
@@ -17,11 +17,14 @@ clean:
 
 PWD:=$(shell pwd -P)
 
-TEST_EXECS = hello
+TEST_EXECS = hello hello2
 
 hello:
 	$(CC) hello.c -o $@ -g
 
+hello2:
+	$(CC) hello.c -o $@ -DWITH_STRUCT -g
+
 check: dwz $(TEST_EXECS)
 	mkdir -p testsuite-bin
 	cd testsuite-bin; ln -sf $(PWD)/dwz .
diff --git a/dwz.c b/dwz.c
index d348418..ffa8e08 100644
--- a/dwz.c
+++ b/dwz.c
@@ -10954,6 +10954,7 @@ struct file_result
   dev_t dev;
   ino_t ino;
   nlink_t nlink;
+  bool low_mem_p;
 };
 
 /* Handle compression of a single file FILE.  If OUTFILE is
@@ -10970,6 +10971,7 @@ dwz (const char *file, const char *outfile, struct file_result *res,
   struct stat st;
 
   res->res = -1;
+  res->low_mem_p = low_mem ? true : false;
   fd = open (file, O_RDONLY);
   if (fd < 0)
     {
@@ -10999,6 +11001,7 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	  break;
       if (&resa[n] != res)
 	{
+	  res->low_mem_p = resa[n].low_mem_p;
 	  /* If a hardlink to this has been processed before
 	     and we didn't change it, just assume the same
 	     state.  */
@@ -11224,7 +11227,7 @@ dwz (const char *file, const char *outfile, struct file_result *res,
   close (fd);
 
   free (dso);
-  if (ret == 0 && !low_mem)
+  if (ret == 0)
     res->res = 0;
   return ret;
 }
@@ -11968,7 +11971,8 @@ main (int argc, char *argv[])
 		  /* Don't process again files that couldn't
 		     be processed successfully.  */
 		  if (resa[i - optind].res == -1
-		      || resa[i - optind].res == 1)
+		      || resa[i - optind].res == 1
+		      || resa[i - optind].low_mem_p)
 		    continue;
 		  for (cu = alt_first_cu; cu; cu = cu->cu_next)
 		    alt_clear_dups (cu->cu_die);
diff --git a/hello.c b/hello.c
index 82d070e..ee65515 100644
--- a/hello.c
+++ b/hello.c
@@ -1,8 +1,22 @@
 #include <stdio.h>
 
+#ifdef WITH_STRUCT
+struct a {
+  int a;
+  char *p;
+};
+
+struct a a;
+#endif
+
 int
 main (void)
 {
+#ifdef WITH_STRUCT
+  a.p = "hello";
+  printf ("%s\n", a.p);
+#else
   printf ("hello\n");
+#endif
   return 0;
 }
diff --git a/testsuite/dwz.tests/multifile-low-mem.sh b/testsuite/dwz.tests/multifile-low-mem.sh
new file mode 100755
index 0000000..435dfa3
--- /dev/null
+++ b/testsuite/dwz.tests/multifile-low-mem.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+cp ../hello 1
+cp ../hello 2
+cp ../hello2 3
+
+low_mem_limit=$(readelf -w 3 | grep '(DW_TAG' | wc -l)
+low_mem_limit=$((low_mem_limit - 1))
+
+dwz -l$low_mem_limit -m 4 1 2 3
+
+smaller-than.sh 1 ../hello
+smaller-than.sh 2 ../hello
+smaller-than.sh 3 ../hello2
+
+ls=$(ls)
+ls=$(echo $ls)
+[ "$ls" = "1 2 3 4" ]
+
+[ $(gnu-debugaltlink-name.sh 1) = "4" ]
+[ $(gnu-debugaltlink-name.sh 2) = "4" ]
+[ "$(gnu-debugaltlink-name.sh 3)" = "" ]
+
+rm -f 1 2 3 4

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

* Re: [PATCH] Don't process low-mem files in multifile mode
  2019-01-01  0:00 [PATCH] Don't process low-mem files in multifile mode Tom de Vries
@ 2019-01-01  0:00 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

On 01-03-19 19:48, Tom de Vries wrote:
> Hi,
> 
> Consider three executables, a.out and b.out with n DIEs, and c.out with
> n + m DIEs.
> 
> When running in multifile mode, with a low-mem limit of n + m - 1 DIEs:
> ...
> $ dwz -m common.out -l$(($n + $m - 1)) a.out b.out c.out
> ...
> the expectation is that c.out is not used in multifile processing, because it
> exceeds the low-mem limit.  However, all three files turn out to have the
> .gnu_debugaltlink section, showing that in fact c.out was used in multifile
> processing.
> 
> Fix this by adding a low_mem_p field to struct file_result, setting it in
> function dwz and using it in main.
> 

To put it in terms of the --trace switch I just posted, the effect of
the patch is:
...
 $ dwz -t -l$l -m common.out a.out b.out c.out
 Compressing a.out
 Write-multifile a.out
 Compressing b.out
 Write-multifile b.out
 Compressing c.out
 Hit low-mem die-limit
 Compressing c.out in low-mem mode
 Optimize-multifile
 Read-multifile
 Compressing a.out in finalize-multifile mode
 Compressing b.out in finalize-multifile mode
-Compressing c.out in finalize-multifile mode
...

Thanks,
- Tom

> OK for trunk?
>
> Thanks,
> - Tom
> 
> Don't process low-mem files in multifile mode
> 
> 2019-03-01  Tom de Vries  <tdevries@suse.de>
> 
> 	PR dwz/24274
> 	* Makefile (TEST_EXECS): Add hello2.
> 	* dwz.c (struct file_result): Add low_mem_p field.
> 	(dwz): Set low_mem_p field.  Remove non-functional low_mem test.
> 	(main): Don't use low_mem_p files in multifile loop.
> 	* hello.c [HAVE_STRUCT] (struct a): New struct.
> 	[HAVE_STRUCT] (a): New var.
> 	(main) [HAVE_STRUCT]: Use a.
> 	* testsuite/dwz.tests/multifile-low-mem.sh: New test.
> 
> ---
>  Makefile                                 |  5 ++++-
>  dwz.c                                    |  8 ++++++--
>  hello.c                                  | 14 ++++++++++++++
>  testsuite/dwz.tests/multifile-low-mem.sh | 26 ++++++++++++++++++++++++++
>  4 files changed, 50 insertions(+), 3 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index bc51ca2..b8dd9ca 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -17,11 +17,14 @@ clean:
>  
>  PWD:=$(shell pwd -P)
>  
> -TEST_EXECS = hello
> +TEST_EXECS = hello hello2
>  
>  hello:
>  	$(CC) hello.c -o $@ -g
>  
> +hello2:
> +	$(CC) hello.c -o $@ -DWITH_STRUCT -g
> +
>  check: dwz $(TEST_EXECS)
>  	mkdir -p testsuite-bin
>  	cd testsuite-bin; ln -sf $(PWD)/dwz .
> diff --git a/dwz.c b/dwz.c
> index d348418..ffa8e08 100644
> --- a/dwz.c
> +++ b/dwz.c
> @@ -10954,6 +10954,7 @@ struct file_result
>    dev_t dev;
>    ino_t ino;
>    nlink_t nlink;
> +  bool low_mem_p;
>  };
>  
>  /* Handle compression of a single file FILE.  If OUTFILE is
> @@ -10970,6 +10971,7 @@ dwz (const char *file, const char *outfile, struct file_result *res,
>    struct stat st;
>  
>    res->res = -1;
> +  res->low_mem_p = low_mem ? true : false;
>    fd = open (file, O_RDONLY);
>    if (fd < 0)
>      {
> @@ -10999,6 +11001,7 @@ dwz (const char *file, const char *outfile, struct file_result *res,
>  	  break;
>        if (&resa[n] != res)
>  	{
> +	  res->low_mem_p = resa[n].low_mem_p;
>  	  /* If a hardlink to this has been processed before
>  	     and we didn't change it, just assume the same
>  	     state.  */
> @@ -11224,7 +11227,7 @@ dwz (const char *file, const char *outfile, struct file_result *res,
>    close (fd);
>  
>    free (dso);
> -  if (ret == 0 && !low_mem)
> +  if (ret == 0)
>      res->res = 0;
>    return ret;
>  }
> @@ -11968,7 +11971,8 @@ main (int argc, char *argv[])
>  		  /* Don't process again files that couldn't
>  		     be processed successfully.  */
>  		  if (resa[i - optind].res == -1
> -		      || resa[i - optind].res == 1)
> +		      || resa[i - optind].res == 1
> +		      || resa[i - optind].low_mem_p)
>  		    continue;
>  		  for (cu = alt_first_cu; cu; cu = cu->cu_next)
>  		    alt_clear_dups (cu->cu_die);
> diff --git a/hello.c b/hello.c
> index 82d070e..ee65515 100644
> --- a/hello.c
> +++ b/hello.c
> @@ -1,8 +1,22 @@
>  #include <stdio.h>
>  
> +#ifdef WITH_STRUCT
> +struct a {
> +  int a;
> +  char *p;
> +};
> +
> +struct a a;
> +#endif
> +
>  int
>  main (void)
>  {
> +#ifdef WITH_STRUCT
> +  a.p = "hello";
> +  printf ("%s\n", a.p);
> +#else
>    printf ("hello\n");
> +#endif
>    return 0;
>  }
> diff --git a/testsuite/dwz.tests/multifile-low-mem.sh b/testsuite/dwz.tests/multifile-low-mem.sh
> new file mode 100755
> index 0000000..435dfa3
> --- /dev/null
> +++ b/testsuite/dwz.tests/multifile-low-mem.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +set -e
> +
> +cp ../hello 1
> +cp ../hello 2
> +cp ../hello2 3
> +
> +low_mem_limit=$(readelf -w 3 | grep '(DW_TAG' | wc -l)
> +low_mem_limit=$((low_mem_limit - 1))
> +
> +dwz -l$low_mem_limit -m 4 1 2 3
> +
> +smaller-than.sh 1 ../hello
> +smaller-than.sh 2 ../hello
> +smaller-than.sh 3 ../hello2
> +
> +ls=$(ls)
> +ls=$(echo $ls)
> +[ "$ls" = "1 2 3 4" ]
> +
> +[ $(gnu-debugaltlink-name.sh 1) = "4" ]
> +[ $(gnu-debugaltlink-name.sh 2) = "4" ]
> +[ "$(gnu-debugaltlink-name.sh 3)" = "" ]
> +
> +rm -f 1 2 3 4
> 

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

end of thread, other threads:[~2019-03-08 11:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [PATCH] Don't process low-mem files in multifile mode Tom de Vries
2019-01-01  0:00 ` 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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).