[PATCH core-updates] build-system/gnu: strip with --strip-unneeded

  • Done
  • quality assurance status badge
Details
2 participants
  • Jakub K?dzio?ka
  • Ludovic Courtès
Owner
unassigned
Submitted by
Jakub K?dzio?ka
Severity
normal
J
J
Jakub K?dzio?ka wrote on 27 Jul 2020 01:38
(address . guix-patches@gnu.org)
20200726233850.12321-1-kuba@kadziolka.net
Apart from debug information, one can also strip some symbols. This can
be a significant difference, qtbase:out consists of about 5 MB of those
symbols. As per [1], --strip-debug is included in --strip-unneeded, and
the debug files created also contain a copy of the information removed
by --strip-unneeded.

Linux From Scratch suggests that this option shouldn't be used on static
libraries [2], however other sources [3] indicate otherwise. Building a
toolchain with this patch succeeds, and the result works fine for
'gcc -static hello-world.c'.


* guix/build/gnu-build-system.scm (strip): Use --strip-unneeded.
---
guix/build/gnu-build-system.scm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm
index 2e7dff2034..d3347c9518 100644
--- a/guix/build/gnu-build-system.scm
+++ b/guix/build/gnu-build-system.scm
@@ -425,7 +425,7 @@ makefiles."
(objcopy-command (if target
(string-append target "-objcopy")
"objcopy"))
- (strip-flags '("--strip-debug"
+ (strip-flags '("--strip-unneeded"
"--enable-deterministic-archives"))
(strip-directories '("lib" "lib64" "libexec"
"bin" "sbin"))
--
2.27.0
J
J
Jakub K?dzio?ka wrote on 30 Jul 2020 02:21
[PATCH v2 core-updates] build-system/gnu: strip with --strip-unneeded
(address . 42555@debbugs.gnu.org)
20200730002154.5704-1-kuba@kadziolka.net
Apart from debug information, one can also strip some symbols. This can
be a significant difference, the closure of gcc-toolchain@7 got reduced
by 15 MB in my tests.

As per [1], --strip-debug is included in --strip-unneeded, and
the debug files created also contain a copy of the information removed
by --strip-unneeded.

Linux From Scratch suggests that this option shouldn't be used on static
libraries [2], however other sources [3] indicate otherwise. Building a
toolchain with this patch succeeds, and the result works fine for
'gcc -static hello-world.c'.


* guix/build/gnu-build-system.scm (strip): Use --strip-unneeded.
* guix/build-system/gnu.scm (static-package, gnu-build, gnu-cross-build): Likewise.
---

I have realized that my previous patch was a no-op due to default values
for arguments being scattered across files. I ran my builds again and
now I can observe results in the earlier stages of the toolchain,
accessible to a testing core-updates build.

guix/build-system/gnu.scm | 6 +++---
guix/build/gnu-build-system.scm | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

Toggle diff (46 lines)
diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm
index 6b481ad45c..2c23197e77 100644
--- a/guix/build-system/gnu.scm
+++ b/guix/build-system/gnu.scm
@@ -215,7 +215,7 @@ use `--strip-all' as the arguments to `strip'."
(arguments
(let ((a (default-keyword-arguments (package-arguments p)
'(#:configure-flags '()
- #:strip-flags '("--strip-debug")))))
+ #:strip-flags '("--strip-unneeded")))))
(substitute-keyword-arguments a
((#:configure-flags flags)
`(cons* "--disable-shared" "LDFLAGS=-static" ,flags))
@@ -337,7 +337,7 @@ standard packages used as implicit inputs of the GNU build system."
(parallel-tests? #t)
(patch-shebangs? #t)
(strip-binaries? #t)
- (strip-flags ''("--strip-debug"
+ (strip-flags ''("--strip-unneeded"
"--enable-deterministic-archives"))
(strip-directories ''("lib" "lib64" "libexec"
"bin" "sbin"))
@@ -492,7 +492,7 @@ is one of `host' or `target'."
(parallel-build? #t) (parallel-tests? #t)
(patch-shebangs? #t)
(strip-binaries? #t)
- (strip-flags ''("--strip-debug"
+ (strip-flags ''("--strip-unneeded"
"--enable-deterministic-archives"))
(strip-directories ''("lib" "lib64" "libexec"
"bin" "sbin"))
diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm
index 2e7dff2034..d3347c9518 100644
--- a/guix/build/gnu-build-system.scm
+++ b/guix/build/gnu-build-system.scm
@@ -425,7 +425,7 @@ makefiles."
(objcopy-command (if target
(string-append target "-objcopy")
"objcopy"))
- (strip-flags '("--strip-debug"
+ (strip-flags '("--strip-unneeded"
"--enable-deterministic-archives"))
(strip-directories '("lib" "lib64" "libexec"
"bin" "sbin"))
--
2.28.0
L
L
Ludovic Courtès wrote on 19 Sep 2020 14:49
(name . Jakub K?dzio?ka)(address . kuba@kadziolka.net)(address . 42555@debbugs.gnu.org)
87o8m2q6ca.fsf@gnu.org
Hi Jakub,

Jakub K?dzio?ka <kuba@kadziolka.net> skribis:

Toggle quote (4 lines)
> Apart from debug information, one can also strip some symbols. This can
> be a significant difference, the closure of gcc-toolchain@7 got reduced
> by 15 MB in my tests.

Nice! Now’s a good time to get that patch in on ‘core-updates’.

Toggle quote (4 lines)
> As per [1], --strip-debug is included in --strip-unneeded, and
> the debug files created also contain a copy of the information removed
> by --strip-unneeded.

Hmm the Binutils manual suggests otherwise (info "(binutils) objcopy"):

Toggle snippet (8 lines)
'-g'
'--strip-debug'
Do not copy debugging symbols or sections from the source file.

'--strip-unneeded'
Strip all symbols that are not needed for relocation processing.

… but objcopy.c reads this:

Toggle snippet (6 lines)
else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
keep = (strip_symbols != STRIP_DEBUG
&& strip_symbols != STRIP_UNNEEDED
&& ! convert_debugging);

… confirming that ‘--strip-unneeded’ includes ‘--strip-debug’.

I submitted a patch for the Binutils manual.

Toggle quote (5 lines)
> Linux From Scratch suggests that this option shouldn't be used on static
> libraries [2], however other sources [3] indicate otherwise. Building a
> toolchain with this patch succeeds, and the result works fine for
> 'gcc -static hello-world.c'.

OK.

Toggle quote (2 lines)
Perhaps we can omit this one. In general, I think it’s safer to refer
to “primary sources” as Wikipedians would say.

Toggle quote (6 lines)
> [3]: https://www.technovelty.org/linux/stripping-shared-libraries.html
>
> * guix/build/gnu-build-system.scm (strip): Use --strip-unneeded.
> * guix/build-system/gnu.scm (static-package, gnu-build, gnu-cross-build): Likewise.

LGTM!

For the record, I tried ‘--strip-all’ before, but that was problematic
for some reason:


Thanks,
Ludo’.
J
J
Jakub K?dzio?ka wrote on 19 Sep 2020 15:49
(name . Ludovic Courtès)(address . ludo@gnu.org)
C5RE6M5VJN1J.1FA1WPBHZPQ0S@gravity
On Sat Sep 19, 2020 at 4:49 PM CEST, Ludovic Courtès wrote:
Toggle quote (10 lines)
> Hi Jakub,
>
> Jakub K?dzio?ka <kuba@kadziolka.net> skribis:
>
> > Apart from debug information, one can also strip some symbols. This can
> > be a significant difference, the closure of gcc-toolchain@7 got reduced
> > by 15 MB in my tests.
>
> Nice! Now’s a good time to get that patch in on ‘core-updates’.

Thanks. Patch pushed (with a small hiccup...)

Toggle quote (5 lines)
>
> Perhaps we can omit this one. In general, I think it’s safer to refer
> to “primary sources” as Wikipedians would say.

The problem with "primary sources" is that the docs on this are quite
sparse. I think this link is much more comprehensive.

Toggle quote (14 lines)
> > [3]: https://www.technovelty.org/linux/stripping-shared-libraries.html
> >
> > * guix/build/gnu-build-system.scm (strip): Use --strip-unneeded.
> > * guix/build-system/gnu.scm (static-package, gnu-build, gnu-cross-build): Likewise.
>
> LGTM!
>
> For the record, I tried ‘--strip-all’ before, but that was
> problematic
> for some reason:
>
> https://lists.gnu.org/archive/html/guix-devel/2018-03/msg00135.html

The docs for --strip-all say "Do not copy relocation and symbol
information", so I would expect some relocation and/or linking use case
to get broken...

Regards,
Jakub K?dzio?ka
?