Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Stripping Binaries
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
satanail
n00b
n00b


Joined: 18 Feb 2018
Posts: 21

PostPosted: Tue Jan 15, 2019 12:34 am    Post subject: Stripping Binaries Reply with quote

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!
Back to top
View user's profile Send private message
mike155
Veteran
Veteran


Joined: 17 Sep 2010
Posts: 1651
Location: Frankfurt, Germany

PostPosted: Tue Jan 15, 2019 1:47 am    Post subject: Reply with quote

I use 'strip' to discard symbols.

Look at the example below:
Code:
$ 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.
Back to top
View user's profile Send private message
satanail
n00b
n00b


Joined: 18 Feb 2018
Posts: 21

PostPosted: Tue Jan 15, 2019 3:23 am    Post subject: Reply with quote

mike155 wrote:
I use 'strip' to discard symbols.

Look at the example below:
Code:
$ 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.


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?
Back to top
View user's profile Send private message
mike155
Veteran
Veteran


Joined: 17 Sep 2010
Posts: 1651
Location: Frankfurt, Germany

PostPosted: Tue Jan 15, 2019 3:32 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
satanail
n00b
n00b


Joined: 18 Feb 2018
Posts: 21

PostPosted: Tue Jan 15, 2019 4:13 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14270

PostPosted: Tue Jan 15, 2019 4:33 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
satanail
n00b
n00b


Joined: 18 Feb 2018
Posts: 21

PostPosted: Tue Jan 15, 2019 4:59 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
proteusx
Apprentice
Apprentice


Joined: 21 Jan 2008
Posts: 249

PostPosted: Tue Jan 15, 2019 6:57 am    Post subject: Reply with quote

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/
Back to top
View user's profile Send private message
satanail
n00b
n00b


Joined: 18 Feb 2018
Posts: 21

PostPosted: Tue Jan 15, 2019 5:20 pm    Post subject: Reply with quote

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 :) Thank you!
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14270

PostPosted: Wed Jan 16, 2019 2:30 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
satanail
n00b
n00b


Joined: 18 Feb 2018
Posts: 21

PostPosted: Wed Jan 16, 2019 11:48 pm    Post subject: Reply with quote

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".
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14270

PostPosted: Thu Jan 17, 2019 3:56 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5956

PostPosted: Thu Jan 17, 2019 6:08 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
satanail
n00b
n00b


Joined: 18 Feb 2018
Posts: 21

PostPosted: Thu Jan 17, 2019 11:29 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Mad Merlin
Veteran
Veteran


Joined: 09 May 2005
Posts: 1155

PostPosted: Fri Jan 18, 2019 1:26 am    Post subject: Reply with quote

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.


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?


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.
_________________
Game! - Where the stick is mightier than the sword!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum