# Stripping Binaries

## satanail

Hello Gentoo users! I have been searching for this, but obviously my SE guru skills didn't work this time, so I'm reaching out to you. I've noticed (dynamically linked) binaries have a lot of raw text, paths, gcc compiler info, etc in every binary. Can I safely strip all of this 'raw text' from the ELF binaries? I checked and saw GCC binaries aren't stripped, would it be safe to strip them? LDFLAGS = " ... --strip-all " doesn't do anything. Some directions how should I approach to this 'issue' will be appreciated. Thanks!

----------

## mike155

I use 'strip' to discard symbols.

Look at the example below:

```
$ cat hello.c

   #include <stdio.h>

   int main( void ) {

       printf( "Hello, world\n" );

   }

$ gcc -o hello hello.c

$ ls -la hello

-rwxr-x--- 1 mike mike 7912 Jan 15 01:44 hello

$ strip hello

$ ls -la hello

-rwxr-x--- 1 mike mike 6136 Jan 15 01:44 hello

```

Programs will still run after you stripped them, but it will be harder to debug them.

----------

## satanail

 *mike155 wrote:*   

> I use 'strip' to discard symbols.
> 
> Look at the example below:
> 
> ```
> ...

 

Exactly what my point is to make debugging closer to impossible.

I already know about strip, but try to open the generated ELF binary with for ex. vim and search for gentoo or linux, you'll clearly see a lot of raw text, including the ld path, and quite a lot of info actually. Also try to statically link it $ gcc -static -o hello hello.c and then you'll see a whole lot of plain text in the binary. I really don't like this, is there a way to cut this off?

----------

## mike155

 *Quote:*   

> I really don't like this, is there a way to cut this off?

 

'strip' will remove more data if you add some CLI arguments. Please look at this article, especially at the last 2 lines.

----------

## satanail

 *mike155 wrote:*   

>  *Quote:*   I really don't like this, is there a way to cut this off? 
> 
> 'strip' will remove more data if you add some CLI arguments. Please look at this article, especially at the last 2 lines.

 

Thanks for the link. Stripping comment and note* section was indeed half of what I wanted. What about stripping the library path? Is it possible? How can the linker then see where's the libc.so? I guess using a bash variable? What about things that aren't started from the terminal? ... Of course stripping .rodata (the section I call plaintext) obviously cannot be stripped as there would be nothing to display, I guess the only option to get rid of that visibly, would be compression. One more thing, is there any way that gentoo provides for a default 'strip' command behavior? Like STRIP_FLAGS in make.conf for example or should I just create a wrapper for it, or maybe editing flag-o-matic.eclass? What's the best way to strip sections globally?

----------

## Hu

What is your goal here?  Are you trying to save space by minimizing file size?  You mentioned making debugging difficult, but that's a bit of an odd goal when the input files are from open source software.

----------

## satanail

 *Hu wrote:*   

> What is your goal here?  Are you trying to save space by minimizing file size?  You mentioned making debugging difficult, but that's a bit of an odd goal when the input files are from open source software.

 

I just mentioned it, because I wanted to emphasize and be clear that I want maximum strip. Usually 'strip -s' is enough and I don't know why it doesn't trim comment/note sections as well, maybe because it's pointless from a size point of view... I already know how to trim things down, because I'm running LFS on a 32mb RAM MIPS device. It runs only from RAM with only 5 mb of usage. And also just because I don't have a lot of posts don't immediately assume that I don't have any self written software. I always research and do things on my own, but this time I wanted to take advantage of the forum, can't I get lazy and ask questions too?

----------

## proteusx

Here is some info I found helpful when I needed to minimize my ELFs.

http://timelessname.com/elfbin/

http://www.muppetlabs.com/~breadbox/software/tiny/

----------

## satanail

 *proteusx wrote:*   

> Here is some info I found helpful when I needed to minimize my ELFs.
> 
> http://timelessname.com/elfbin/
> 
> http://www.muppetlabs.com/~breadbox/software/tiny/

 

Even though runtime performance is not an issue and I'm not enforced to strip things as much as possible, it was definitely an extremely good and fun read, which I'll go to for when I need to! Bookmarked  :Smile:  Thank you!

----------

## Hu

 *satanail wrote:*   

>  *Hu wrote:*   What is your goal here?  Are you trying to save space by minimizing file size?  You mentioned making debugging difficult, but that's a bit of an odd goal when the input files are from open source software. 
> 
> I just mentioned it, because I wanted to emphasize and be clear that I want maximum strip. Usually 'strip -s' is enough and I don't know why it doesn't trim comment/note sections as well, maybe because it's pointless from a size point of view... I already know how to trim things down, because I'm running LFS on a 32mb RAM MIPS device. It runs only from RAM with only 5 mb of usage. And also just because I don't have a lot of posts don't immediately assume that I don't have any self written software. I always research and do things on my own, but this time I wanted to take advantage of the forum, can't I get lazy and ask questions too?

 It is quite common for people to bring us X-Y problems.  Such problems are often characterized by a request, such as yours, for something that has little apparent value, which the poster has decided is the best solution to their perceived and unstated problem.  Asking the poster to explain their problem, rather than their desired solution, often lets us give them a proper solution that is both easier and more effective than what they originally requested.

Where did I assume you don't have any self-written things?  I asserted there was no point in making it difficult to debug things which are open source, because the program could easily be rebuilt with symbols again.  That extends to personal projects for which you have the source, even if you don't give it to us.

----------

## satanail

 *Hu wrote:*   

>  *satanail wrote:*    *Hu wrote:*   What is your goal here?  Are you trying to save space by minimizing file size?  You mentioned making debugging difficult, but that's a bit of an odd goal when the input files are from open source software. 
> 
> I just mentioned it, because I wanted to emphasize and be clear that I want maximum strip. Usually 'strip -s' is enough and I don't know why it doesn't trim comment/note sections as well, maybe because it's pointless from a size point of view... I already know how to trim things down, because I'm running LFS on a 32mb RAM MIPS device. It runs only from RAM with only 5 mb of usage. And also just because I don't have a lot of posts don't immediately assume that I don't have any self written software. I always research and do things on my own, but this time I wanted to take advantage of the forum, can't I get lazy and ask questions too? It is quite common for people to bring us X-Y problems.  Such problems are often characterized by a request, such as yours, for something that has little apparent value, which the poster has decided is the best solution to their perceived and unstated problem.  Asking the poster to explain their problem, rather than their desired solution, often lets us give them a proper solution that is both easier and more effective than what they originally requested.
> 
> Where did I assume you don't have any self-written things?  I asserted there was no point in making it difficult to debug things which are open source, because the program could easily be rebuilt with symbols again.  That extends to personal projects for which you have the source, even if you don't give it to us.

 

I didn't mention getting rid of symbols, but obviously some sections, which other user pointed me to. I didn't care about being able to debug, because 99% of the time the first step to cutting binaries is getting rid of debugging. Maybe it's of no value to you, but it's of to me, so I don't you see your point. You are free to keep compiler info/package versions in your binaries/libraries, you'll do someone's favour. I'm interested in everything software related, so I like the 'minimizing elf links' as well, learning assembly is a future goal of mine too. I don't really like the quality of the 'legacy tools', which LSB brings, so rewriting some bits and creating my own baked ELF's is another future goal too. If you have anything of that feel free to share something, if you read the thread's name and re-read it again, you can clearly see I had solved my 'problem', and see that I'm also open to whatever people think is appropriate to be linked in here. Your inability to understand /this/ or what I asked for in the first place, could be solved by safely passing the thread, because all you currently do is called "spamming".

----------

## Hu

Spammers are very aggressively purged.  I was trying to help you by prompting you to explain what you wanted, so that we could propose a useful solution to your real problem.

----------

## Ant P.

What is your goal? "Maximum strip" is a meaningless phrase here. Most people know what they're trying to achieve, but you're just being needlessly argumentative and evasive. You would get a lot further if you simply tell the truth, and Ask Questions The Smart Way.

----------

## satanail

 *Hu wrote:*   

> Spammers are very aggressively purged.  I was trying to help you by prompting you to explain what you wanted, so that we could propose a useful solution to your real problem.

 

I understand that, but I got kinda mad, because I got what I wanted, before you even commented...

 *Ant P. wrote:*   

> What is your goal? "Maximum strip" is a meaningless phrase here. Most people know what they're trying to achieve, but you're just being needlessly argumentative and evasive. You would get a lot further if you simply tell the truth, and Ask Questions The Smart Way.

 

At first I was questioning my English skills for the inability to ask, but then I realized you guys are the only people that didn't understand what I was looking for, unlike other people, so I scratch that. Maybe I overreacted a bit, but it seems you guys came here just to criticize my ability to ask questions and nothing else. These are simply empty talks to me. What truth do you want to know? Why do you keep provoking me, while you see I'm pretty new to asking questions?

----------

## Mad Merlin

 *satanail wrote:*   

>  *Hu wrote:*   Spammers are very aggressively purged.  I was trying to help you by prompting you to explain what you wanted, so that we could propose a useful solution to your real problem. 
> 
> I understand that, but I got kinda mad, because I got what I wanted, before you even commented...
> 
>  *Ant P. wrote:*   What is your goal? "Maximum strip" is a meaningless phrase here. Most people know what they're trying to achieve, but you're just being needlessly argumentative and evasive. You would get a lot further if you simply tell the truth, and Ask Questions The Smart Way. 
> ...

 

There are many goals that could be achieved by stripping binaries. For example, making it more difficult to debug, or reducing disk space usage. There are also many other ways to achieve the aforementioned goals.

You've stated the mechanism that you're using, but not the end goal. What is your end goal? We may know other ways to get there.

----------

