View Issue Details

IDProjectCategoryView StatusLast Update
0018833FPCRTLpublic2013-03-05 23:26
ReporterDejan Boras Assigned ToThomas Schatzl  
Status resolvedResolutionfixed 
Product Version2.5.1 
Target Version2.7.1Fixed in Version3.0.0 
Summary0018833: envp is not set correctly under armv5-android
DescriptionThe envp variable in system unit is not set correctly. It is not nil but points to an invalid region of memory (for example an address BECD1068). Attempting to access that part of memory will cause a SIGSEG (SEGV_MAPPER) violation. This for effect also causes the initialization of sysutils unit to cause a violation.

This happens in a shared library under JNI in Android. However, for a regular linux program (which was loaded onto the Android emulator using adb shell) this does not happen, and the address is significantly different (e.g. $0000ECEC).
Steps To ReproduceLoad a library which uses sysutils or tries to access the envp variable in Android via JNI.
TagsNo tags attached.
Fixed in Revision
Attached Files


related to 0020726 resolvedThomas Schatzl Basic support for Android 


Jonas Maebe

2011-02-27 11:12

manager   ~0046290

Android may require special system unit initialisation code if it passes envp in a different way.

Thomas Schatzl

2011-02-27 18:50

developer   ~0046301

Please test with r17033.

On arm/linux there had been the same issue, although it sometimes worked.

I also checked loading a library at runtime that uses sysutils using dynlibs, works too now (e.g. test for 14958).

Dejan Boras

2011-03-01 00:32

reporter   ~0046318

The change made in r17033 does not fix the problem. The argc, argv and envp still contain invalid values.

2011-03-07 11:58


dumbfix.patch (503 bytes)   
Index: rtl/linux/system.pp
--- rtl/linux/system.pp (17059)
+++ rtl/linux/system.pp	(working copy)
@@ -332,6 +332,12 @@
   initialstkptr : Pointer;external name '__stkptr';
+   {this is a stupid fix since these are not set correctly under android,
+   and trying to access argv or envp will make the library crap out}
+   argc := 0; argv := nil; envp := nil;
+   {$ENDIF}
 {$if defined(i386) and not defined(FPC_USE_LIBC)}
dumbfix.patch (503 bytes)   

Dejan Boras

2011-03-07 12:01

reporter   ~0046480

I've attached a simple patch (dumbfix.patch) which provides a dumb fix. It's not a solution, but will allow to build a working armv5-android crosscompiler. The symbol ANDROID must be defined for this to have effect when building the crosscompiler. It simply sets argc, argv and envp to nil values, so sysutils and others don't crash trying to access bogus memory locations.

Thomas Schatzl

2011-09-27 11:20

developer   ~0052220

Some investigation of the dynamic loader showed that on Android argc, argv and envp do not get passed to shared libraries at all. This is a feature of the glibc on Linux, which is not used there.

An alternative could be to parse contents of the proc file system (if it exists on Android) to get argc/argv; where to get envp is still unknown.

Yuriy Sydorov

2013-02-13 20:15

manager   ~0065676

This bug is fixed.
The Android target is now in trunk.

Issue History

Date Modified Username Field Change
2011-02-27 08:51 Dejan Boras New Issue
2011-02-27 11:10 Jonas Maebe FPCOldBugId => 0
2011-02-27 11:10 Jonas Maebe Severity major => feature
2011-02-27 11:10 Jonas Maebe Category Compiler => RTL
2011-02-27 11:12 Jonas Maebe Note Added: 0046290
2011-02-27 18:50 Thomas Schatzl Note Added: 0046301
2011-03-01 00:32 Dejan Boras Note Added: 0046318
2011-03-07 11:58 Dejan Boras File Added: dumbfix.patch
2011-03-07 12:01 Dejan Boras Note Added: 0046480
2011-09-27 11:12 Thomas Schatzl Status new => assigned
2011-09-27 11:12 Thomas Schatzl Assigned To => Thomas Schatzl
2011-09-27 11:20 Thomas Schatzl Note Added: 0052220
2011-11-21 20:05 Felipe Monteiro de Carvalho Relationship added related to 0020726
2013-02-13 20:15 Yuriy Sydorov Note Added: 0065676
2013-02-13 20:15 Yuriy Sydorov Status assigned => resolved
2013-02-13 20:15 Yuriy Sydorov Fixed in Version => 2.7.1
2013-02-13 20:15 Yuriy Sydorov Resolution open => fixed
2013-02-13 20:15 Yuriy Sydorov Target Version => 2.7.1