neurobin / shc

Shell script compiler

Home Page:https://neurobin.org/projects/softwares/unix/shc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shellscript compiled in latest gcc wont run in older bash

opened this issue · comments

Hi team,

I have compiled a bash script in latest gcc aka 8.xx and glibc 2.28. When I try to run in older kernels/gcc env, I always get that latest gcc or glibc is not found.

Regards,
Muralidhar N

This is not a shc issue per say. Its just the way shared libraries work. Think of how frustrating you felt when windows said it couldnt find a certain DLL file. Well, its the same.

Executables can be linked either dynamically or statically

you should try to link your executables either with a 'common/stable/average' version of libc in order to ensure that your programs can be run most everywhere you want to move them.

Also, linking against static libraries is the other option. It does produce alot bigger files but that just how it goes. You can't travel around the world without a suitcase if you are expected to carry all you will ever need to function, right? Same goes for the executables. Packing-in (linking statically) the dependancies/libraries does increase size considerably but ensures maximum portability by providing a standalone executable that can run well...at least on similar/same archchitecture systems.

libc will add about 700-900 kb to your finished (non upx/packed) executables. Linking with a smaller, portable libc alternative will considerably reduce your executable size, cutting down on the bloat while keeping just enough (and sometimes well, barely) to run anywhere.

Linking against either musl libc or diet libc will both produce executables with an overhead (all deps included, standalone) considerably smaller than standard libc

here, for comparison sake, a simple 'hello world' script compiled using the 3 methods and the output binary sizes

- Straight shc, dynamic link (uses shared libraries) - 12 kb
- Straight shc, static link (standalone) glibc standard - 788 kb
- Straight shc, static link (standalone) musl-libc - 44 kb

You can find more on shared/static libraries at tldp.org