-1

Applications like busybox and dropbear contain several programs in a single binary.

Are there tools out there that facilitate this process? Could I compile several C programs from different authors into a single binary relatively easy?

I ask because I'm compiling a few things for a small Linux embedded device and I'm trying to save as much space as possible.

3
  • It depends, can you invoke these programs from within your resulting program? Commented Feb 7, 2015 at 4:00
  • FYI, busybox is a single program written to do the same function as multiple programs. It is written as modules for sets of "emulated" programs but everything is compiled together. Commented Feb 9, 2015 at 3:17
  • Voting to close. Asking for a tool recommendation it considered an opinion-based question. Commented Jul 28 at 12:51

3 Answers 3

3

No, this isn't a form of data compression. You generally can't take two similar applications and leverage their functional similarities to save disk space.

What those applications do is check the value of the first command-line argument, argv[0], which tells how the binary was invoked. Then the program does the right thing.

If you have access to the source code of a few applications and you know that they are reduplicating the exact same code (i.e., they are incorporating functions from the same static library), you have a couple choices:

  • Move the duplicated code (static libraries) into a shared library.
  • Try to implement your proposed strategy by writing your own main function, and compiling them all simultaneously.

It's hard to know how much work this would be without seeing the build systems for the programs in question, but it will probably not be "fairly easy."

If there's not any common static library, but they're just doing similar things, then you're talking about refactoring them. That could easily turn into a complete rewrite of all the programs. Could be worth it, if the result will be more than the sum of its parts, and it's perhaps easier than starting from scratch, but categorically we can say "lots of work."

Sign up to request clarification or add additional context in comments.

Comments

2

I'm not aware of any general tool to do this, and in any case, it's only a space-saving measure when there's a large overlap between the code for the programs to be combined. For busybox the savings are not so much overlap between the code for the individual applets, but rather sharing a single copy of a static-linked libc. For dynamic linking, much of that benefit disappears.

Comments

0

This is not a general solution, but should work for go tools: https://github.com/u-root/gobusybox

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.