Recent

Author Topic: Cross compiling to Android "pie executable" results in "LSB shared object"  (Read 1338 times)

han

  • Full Member
  • ***
  • Posts: 117
I have Fpcupdeluxe installed. I want to cross compile from Linux to Android pie executable.

Compiling a Hello Word program to Linux using options  -k-pie -k-znow -Cg  gives the following Linux executable:

file test2
test2: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, with debug_info, not stripped

Changing the platform to Android gives the following result:

ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter libdl.so, BuildID[sha1]=9eab5a4e162e001f4892880a899c0843f5cea6eb, with debug_info, not stripped

So a shared object instead of the pie executable.

With only option -Cg-,  I can get an Android executable but it is not Pie, so it doesn't work for Android 5+. Note the option -Cg-.
test2: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter libdl.so, BuildID[sha1]=79cf6dff7bf31d286eaed661e4e9dc02dda7df79, with debug_info, not stripped


How can I cross compile to an Android pie executable? Or is this caused by a problem with the cross compiler?

Han





han

  • Full Member
  • ***
  • Posts: 117
I have also compiled to Android using LAMW_manager. Same result. The result is still a shared object and not a pie executable.

nobody.00

  • New Member
  • *
  • Posts: 11
I have Fpcupdeluxe installed. I want to cross compile from Linux to Android pie executable.

Compiling a Hello Word program to Linux using options  -k-pie -k-znow -Cg  gives the following Linux executable:

file test2
test2: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, with debug_info, not stripped

Changing the platform to Android gives the following result:

ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter libdl.so, BuildID[sha1]=9eab5a4e162e001f4892880a899c0843f5cea6eb, with debug_info, not stripped

So a shared object instead of the pie executable.

With only option -Cg-,  I can get an Android executable but it is not Pie, so it doesn't work for Android 5+. Note the option -Cg-.
test2: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter libdl.so, BuildID[sha1]=79cf6dff7bf31d286eaed661e4e9dc02dda7df79, with debug_info, not stripped


How can I cross compile to an Android pie executable? Or is this caused by a problem with the cross compiler?

Han
Compile first as -o file.o
After using ld passing pie options
I have tais problem recently , after i put a detailed command to help you

han

  • Full Member
  • ***
  • Posts: 117
Thanks. I assume you suggest to use the produced  .o file but how is unclear to me.

There are some hints here:
https://wiki.freepascal.org/hardening
This suggest to add {$linklib c} to the source code. The output is still a LSB shared object. Puzzling.


han

  • Full Member
  • ***
  • Posts: 117
From the link below it seem that a pie executable can be reported as a shared object. But both Lubuntu 22 and Debian 12 report my command-line program as a shared object.

https://forum.lazarus.freepascal.org/index.php/topic,56842.30.html
https://forum.lazarus.freepascal.org/index.php/topic,39338.msg451236.html#msg451236

I got a report that this command seems to makes the program executable in Android:
patchelf --set-interpreter /system/bin/linker64  yourprogram


han

  • Full Member
  • ***
  • Posts: 117
At moment I understand that a shared object is the same as a pie executable. So that is no longer a problem. However the interpreter for Android is wrongly defined as libdl.so. It should be  /system/bin/linker64 or  /system/bin/linker for 32 bit:

This is what is reported after entering in Linux: file yourprogram:
yourprogram: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter libdl.so, BuildID[sha1]=8eeee3c498f7728fe5428122b4acb179362e7bc3, stripped

The interpreter can be corrected using the patchelf program as follows:

patchelf --set-interpreter /system/bin/linker64 ./yourprogram

This results in:
yourprogram: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, BuildID[sha1]=2bf966cbb671b53c38504d838ff2d4c6b4979095, stripped

The options -Cg -k-pie -k-znow are not required. Default for Android?

The outstanding question is now how to get the correct Android interpreter without using patchelf.
« Last Edit: June 28, 2024, 09:21:40 pm by han »

han

  • Full Member
  • ***
  • Posts: 117
« Last Edit: July 17, 2024, 11:09:22 am by han »

 

TinyPortal © 2005-2018