Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQ INFO] How to cross-compile SHC to arm/arm64 ? #33

Open
nightmare007 opened this issue Apr 30, 2017 · 2 comments
Open

[REQ INFO] How to cross-compile SHC to arm/arm64 ? #33

nightmare007 opened this issue Apr 30, 2017 · 2 comments

Comments

@nightmare007
Copy link

nightmare007 commented Apr 30, 2017

Hello @neurobin

I tried for hours now, to compile SHC for arm & arm64, but without success.

so far, I only managed to SUCCESFULLY compile SHC for i386 ( see my below method ), then to use it, to create compiled bash-based binaries as arm/arm64 compatible.
This is only HALF the solution, since I need a PC for the bash->bin convertion.
( I wish to use SHC on phones ).

Can you please direct me on how to compile SHC for arm/arm 64 ?


P.S - for the internet record....
Thanks to a post by @Thiago Zilli Sarmento I managed to compile my bash script to arm & arm64 ( for android ) !!!! :-)

few notes:

  1. for some reason, not "gcc-arm-linux-gnueabihf-gcc" nor
    "gcc-arm-linux-gnueabihf-gcc-6" was willing to compile at all - only
    when I used "gcc-arm-linux-gnueabihf-gcc-4.9" -> it worked (for arm)

  2. 'make' didn't work till I installed 'automake'

  3. I too get wierd output when I compiled of:
    "strip: Unable to recognise the format of the input file `SCRIPT_NAME'
    shc: never mind"
    just ignor it... no harm exist, AFAIK.

  4. NEXT IMPORTANT STEP: what's left is to understand how to cross-compile SHC itself to arm/arm64 so that itself can run on these arch types.

  5. here are the nessesary steps on lubuntu 16.04 i368 ( i.e x32 ):


aptitude install crossbuild-essential-armhf crossbuild-essential-arm64 automake gcc-4.9-arm-linux-gnueabihf
git clone https://github.com/neurobin...
cd shc

./configure --prefix=$prefix
make clean
make


** to compile script to ARM, run:


CC="arm-linux-gnueabihf-gcc-4.9" CFLAGS="-march=armv7-a -static" ./src/shc -r -f SCRIPT_NAME
mv SCRIPT_NAME.x SCRIPT_ARM


** to compile script to ARM64 (AARCH64), run:


CC="aarch64-linux-gnu-gcc" CFLAGS="-march=armv8-a -static" ./src/shc -r -f SCRIPT_NAME
mv SCRIPT_NAME.x SCRIPT_AARCH64


@nightmare007
Copy link
Author

nightmare007 commented Apr 30, 2017

UPDATE:
I think I managed to compile SHC to arm/arm64...
cd ../shc/src
aarch64-linux-gnu-gcc shc.c -static -o shc_arm64
arm-linux-gnueabihf-gcc-4.9 shc.c -static -o shc_arm

When I transfered the compiled shc to my phone, I do indeed can exec shc, but for some-reason, I can't compile THE SAME script I managed to compile on my pc.
This time I only get *.x.c file and NOT *.x file.... well... i'm close..

maybe gcc is missing on my android phone ?

EDIT:
I also tried to run, without success, the following in SHC sources root folder:
./configure --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc-4.9 CFLAGS="-march=armv7-a -static -Os" make clean make
I get:

Making all in src
make[1]: Entering directory '/home/lubuntu/shc/src'
arm-linux-gnueabihf-gcc-4.9 -DPACKAGE_NAME="shc" -DPACKAGE_TARNAME="shc" -DPACKAGE_VERSION="3.9.3" -DPACKAGE_STRING="shc\ 3.9.3" -DPACKAGE_BUGREPORT="http://github.com/neurobin/shc/issues\" -DPACKAGE_URL="" -DPACKAGE="shc" -DVERSION="3.9.3" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_FCNTL_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STRUCT_STAT_ST_RDEV=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=0 -Dmalloc=rpl_malloc -DTIME_WITH_SYS_TIME=1 -DHAVE_SYS_TIME_H=1 -DHAVE_UNISTD_H=1 -DHAVE_ALARM=1 -DHAVE_STDLIB_H=1 -DHAVE_REALLOC=0 -Drealloc=rpl_realloc -DHAVE_MEMSET=1 -DHAVE_PUTENV=1 -DHAVE_STRCHR=1 -DHAVE_STRDUP=1 -DHAVE_STRRCHR=1 -I. -march=armv7-a -static -Os -MT shc.o -MD -MP -MF .deps/shc.Tpo -c -o shc.o shc.c
mv -f .deps/shc.Tpo .deps/shc.Po
arm-linux-gnueabihf-gcc-4.9 -march=armv7-a -static -Os -o shc shc.o
shc.o: In function eval_shell': shc.c:(.text+0x17c): undefined reference to rpl_malloc'
shc.c:(.text+0x184): undefined reference to rpl_malloc' shc.c:(.text+0x190): undefined reference to rpl_malloc'
shc.c:(.text+0x1ec): undefined reference to rpl_realloc' shc.c:(.text+0x2e6): undefined reference to rpl_realloc'
shc.o: In function read_script': shc.c:(.text+0x3aa): undefined reference to rpl_malloc'
shc.c:(.text+0x3cc): undefined reference to rpl_realloc' shc.c:(.text+0x3f6): undefined reference to rpl_realloc'
shc.o: In function write_C': shc.c:(.text+0x778): undefined reference to rpl_realloc'
shc.c:(.text+0x82a): undefined reference to rpl_realloc' shc.o: In function make':
shc.c:(.text+0xc7e): undefined reference to `rpl_realloc'
collect2: error: ld returned 1 exit status
Makefile:326: recipe for target 'shc' failed
make[1]: *** [shc] Error 1
make[1]: Leaving directory '/home/lubuntu/shc/src'
Makefile:413: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

@neurobin
Copy link
Owner

neurobin commented May 29, 2017

On your android phone, you need both gcc and the shell that will be executing the script, installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants