LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 12-03-2019, 05:36 PM   #1
davecan
Member
 
Registered: Nov 2019
Posts: 31

Rep: Reputation: Disabled
Why do we need to call two separate `strip` commands in section 5.35 ("stripping")


In section 5.35 (current 9.0 LFS) the first two commands are:

Code:
strip --strip-debug /tools/lib/*
/usr/bin/strip --strip-unneeded /tools/{,s}bin/*
It struck me as odd that it was using the relative path first and absolute path second. So I did a which strip and the relative one is referencing /tools/bin/strip which means it was built during the compilation process. I dug around and discovered it was part of binutils.

My question is, why do we need to run two different commands here? Obviously the /tools/bin/strip is configured in a certain way such that using /usr/bin/strip wouldn't work for the first case.

But what actually happened behind the scenes here that resulted in requiring two different commands, and what is actually different between them?

Thanks.
 
Old 12-03-2019, 06:14 PM   #2
TheRealGrogan
Member
 
Registered: Oct 2010
Location: Ontario, Canada
Distribution: Slackware, LFS, Manjaro (for gaming)
Posts: 234

Rep: Reputation: 173Reputation: 173
Well, stripping static libraries will BREAK them (deleting archive symbols) so you would only want to use --strip-debug to remove debugging symbols on .a files. That's why, because it's using a wildcard for all the files in lib. It's generally safe to use --strip-unneeded on shared libraries (.so) but not static. Stick with --strip-debug for the libraries though, it will remove most of the symbols.

It's safe to strip binaries with --strip-unneeded (stick with that) or even the default of --strip-all in most all cases.

P.S. No, the strip programs will not be configured differently. It's YOU that tells strip how to strip. Strip is strip, but you want to avoid a situation where you are stripping the strip program you are using as it would likely segfault, hence using the other strip binary :-)

Last edited by TheRealGrogan; 12-03-2019 at 06:21 PM. Reason: Realized I didn't actually answer the question
 
2 members found this post helpful.
Old 12-03-2019, 06:32 PM   #3
TheRealGrogan
Member
 
Registered: Oct 2010
Location: Ontario, Canada
Distribution: Slackware, LFS, Manjaro (for gaming)
Posts: 234

Rep: Reputation: 173Reputation: 173
By the way, if anybody accidentally strips static libraries incorrectly, they can be fixed with ranlib which will regenerate the archive header data. They shouldn't need to be recompiled.
 
2 members found this post helpful.
Old 12-04-2019, 08:40 AM   #4
davecan
Member
 
Registered: Nov 2019
Posts: 31

Original Poster
Rep: Reputation: Disabled
Thanks. So does that mean that once the second line is run the version of strip in /tools/bin/strip is no longer usable? If not then I'm not quite getting why the /tools/bin/strip is used at all then, since if they both do the exact same thing then using /usr/bin/strip for both commands would seem more straightforward.
 
Old 12-04-2019, 01:45 PM   #5
TheRealGrogan
Member
 
Registered: Oct 2010
Location: Ontario, Canada
Distribution: Slackware, LFS, Manjaro (for gaming)
Posts: 234

Rep: Reputation: 173Reputation: 173
No, it doesn't mean that, just that if you strip a running binary (or libraries that are in use) it's likely to crash. I don't know why they wrote it that way, it really doesn't matter beyond that.

I don't really follow all procedures line by line (I know what I'm doing), I did my own stripping offline (after exiting the chroot) using my own commands with the host system's strip whenever I was stopping for whatever reason. Same program (and same version even, in my case) and it's just reading symbols, making a temporary copy, removing them and replacing the original. That's why you don't do it on running objects.

P.S. If I've just done a "make install" of something on my system, the binaries and libraries aren't loaded yet. I'll enter a directory and

Code:
file * | grep 'not stripped'
That will print a list of everything that's not stripped and I'll use a command to strip only that (maybe with a wildcard if I want to catch multiple similarly named things in one command).

Code:
[grogan@getstuffed:~]$ cd /usr/lib
[grogan@getstuffed:lib]$ file * | grep 'not stripped'
crt1.o:                                                ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), for GNU/Linux 4.19.0, not stripped
crti.o:                                                ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
crtn.o:                                                ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
gcrt1.o:                                               ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), for GNU/Linux 4.19.0, not stripped
libasan_preinit.o:                                     ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
liblsan_preinit.o:                                     ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
libmcheck.a:                                           ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
libpython2.7.so.1.0:                                   ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped
libtsan_preinit.o:                                     ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
Mcrt1.o:                                               ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
Scrt1.o:
Don't touch those compiler objects (*.o) but look there, I had to rebuild my python 2 the other day (needed to remove a macro disabling the sqlite3 extension loader to compile Firefox) and I forgot to strip it. I'm not invoking any python2 commands right now, so it's safe to strip that.

Code:
[root@getstuffed:lib]# strip -p --strip-unneeded libpython2.7.so.1.0
[root@getstuffed:lib]#
(remember, don't use --strip-unneeded on static libraries... not on .a files and --strip-debug is always safer in general)

The -p switch with strip preserves timestamps. I want to keep those, because it makes it easier to find files later.

Another thing, most gnu autotools based builds have a "make install-strip" target. I try that first, to strip things as they are installed. If the command fails with no such target install-strip, then it's "make install" and manual stripping.

Last edited by TheRealGrogan; 12-04-2019 at 02:28 PM. Reason: adding more info
 
Old 12-04-2019, 03:13 PM   #6
davecan
Member
 
Registered: Nov 2019
Posts: 31

Original Poster
Rep: Reputation: Disabled
Useful info thank you.
 
Old 12-04-2019, 03:21 PM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,290

Rep: Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207
just a comment: you do not need to strip anything, they will work without that, just occupy more disk space. Strip is "only" used to remove some symbols from the binary.
(But actually these [some] symbols required in libraries to be able to use them).
 
Old 12-04-2019, 04:19 PM   #8
TheRealGrogan
Member
 
Registered: Oct 2010
Location: Ontario, Canada
Distribution: Slackware, LFS, Manjaro (for gaming)
Posts: 234

Rep: Reputation: 173Reputation: 173
Yes, but taking more space on disk means more gyrations (seeking) to find what it needs to load at runtime. I'd agree that static libraries don't matter, but I want binaries and shared libraries stripped.

It can actually be quite significant if something is compiled with -g, as much as 10 times the size in some cases I've noticed. For example:

Code:
[grogan@getstuffed:dri]$ pwd
/usr/X11R7/lib/dri
[grogan@getstuffed:dri]$ ls -l r300_dri.so
-rwxr-xr-x 8 root root 19341472 Nov 25 05:49 r300_dri.so
Those files in there were 150 Mb+ each before stripping.

P.S. Mechanical storage here.

Last edited by TheRealGrogan; 12-04-2019 at 04:29 PM.
 
Old 12-05-2019, 03:01 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,290

Rep: Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207Reputation: 4207
Hm. Linux is able to read only parts (blocks), no need to put the whole executable into RAM, therefore that debug info is probably not read at all. It is not that trivial.
Anyway, I wanted only say: without stripping everything will work without problems.
 
Old 12-05-2019, 07:26 AM   #10
TheRealGrogan
Member
 
Registered: Oct 2010
Location: Ontario, Canada
Distribution: Slackware, LFS, Manjaro (for gaming)
Posts: 234

Rep: Reputation: 173Reputation: 173
I didn't mean that, just that more crap on disk generally means more seeking. Yes, of course binaries and libraries will work if not stripped (it says so right there in the book, too), otherwise how could you even have symbols? What's not trivial is just how much larger debugging symbols can make the objects.

When done, I tar my results up from off system (tar czfp to preserve), format and tar it back again to write a more optimized access pattern after all that make installing and stripping. That makes a difference on mechanical storage.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT: strip: Unable to recognise the format of the input file: doesn't strip any libraries c_kvasud Linux - Newbie 3 06-05-2017 08:27 PM
[SOLVED] Problems in glibc section section 5.7.1 lfs 6.7 abhiklall Linux From Scratch 1 04-19-2011 03:42 AM
Stripping lines versus stripping bytes in a bash subshell. poorman_installer Programming 9 10-21-2009 09:36 AM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 07:02 PM
man "New Commands" Section Broken? tortle LQ Suggestions & Feedback 3 12-05-2004 12:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration