View Issue Details

IDProjectCategoryView StatusLast Update
0035641FPCCompilerpublic2020-01-19 21:33
ReporterBenito van der ZanderAssigned ToYuriy Sydorov 
Status resolvedResolutionfixed 
PlatformOSAndroidOS Version8
Product Version3.3.1Product Buildr40721 
Target VersionFixed in Version3.3.1 
Summary0035641: fpc_LibInitializeUnits crashes on x86 Android
Descriptionfpc_LibInitializeUnits cannot write to IsLibrary anymore.

Probably nothing can write to any global variable

(gdb) disassemble
Dump of assembler code for function fpc_libinitializeunits:
   0x96f54640 <+0>: lea esp,[esp-0xc]
   0x96f54644 <+4>: mov DWORD PTR [esp],ebx
   0x96f54647 <+7>: mov DWORD PTR [esp+0x4],esi
   0x96f5464b <+11>: call 0x96f476e0 <SYSTEM_$$_FPC_GETEIPASECX$$POINTER>
   0x96f54650 <+16>: add ecx,0x19b5fc
   0x96f54656 <+22>: mov esi,ecx
   0x96f54658 <+24>: mov eax,DWORD PTR [esi+0x5b40]
=> 0x96f5465e <+30>: mov BYTE PTR [eax],0x1
   0x96f54661 <+33>: mov eax,DWORD PTR [esi+0x4ee8]
   0x96f54667 <+39>: mov BYTE PTR [eax],0x1
   0x96f5466a <+42>: mov ebx,esi
   0x96f5466c <+44>: call 0x96f545c0 <fpc_initializeunits>
   0x96f54671 <+49>: mov ebx,DWORD PTR [esp]
   0x96f54674 <+52>: mov esi,DWORD PTR [esp+0x4]
   0x96f54678 <+56>: lea esp,[esp+0xc]
   0x96f5467c <+60>: ret
End of assembler dump.

(gdb) print/x $eax
$9 = 0x970f6770

That does not look like a writeable address:

96f16000-970ee000 r-xp 00000000 fc:00 336 /data/app/de.benibela.videlibri.debug-L0gf5huaCqbDOhNLKP_FYw==/lib/x86/
970ee000-970ef000 ---p 00000000 00:00 0
970ef000-97167000 r--p 001d8000 fc:00 336 /data/app/de.benibela.videlibri.debug-L0gf5huaCqbDOhNLKP_FYw==/lib/x86/
Additional Information$ ~/bin/i686-linux-android-ld.bfd --version
GNU ld (GNU Binutils)
TagsNo tags attached.
Fixed in Revision44002
Attached Files


Benito van der Zander

2019-05-27 23:50

reporter   ~0116441

So it appears to work with "GNU ld (GNU Binutils) 2.21"

PS: When I install a new ld or change -Fl in fpc.cfg, do I need to rebuild all of fpc?

jamie philbrook

2019-05-28 02:07

reporter   ~0116442

Do you have the Writable Constant flag turned on ?

Benito van der Zander

2019-05-28 12:25

reporter   ~0116443

It is not a constant

  ExitCode : Longint; public name 'operatingsystem_result';
  RandSeed : Cardinal;
  { Delphi compatibility }

  IsLibrary : boolean = false; public name 'operatingsystem_islibrary';
  IsLibrary = false;

procedure fpc_LibInitializeUnits;[public,alias:'FPC_LIBINITIALIZEUNITS'];compilerproc;
  { must also be set to true for packages when implemented }

jamie philbrook

2019-05-28 13:25

reporter   ~0116444

The use of {$Else FPC_HAS_FEATURE_DYNLIBS} is eluding me ?
 Maybe it is also eluding the compiler? I don't remember ever marking the ELSE like that, I just use {$ELSE} etc...

Sven Barth

2019-05-31 15:23

manager   ~0116480

Everything behind a $ELSE or a $ENDIF/$IFEND is treated as a comment. It's a usual style inside the RTL to mark compiler conditionals like this so that one can easily see which condition ended.

Benito van der Zander

2019-12-11 14:40

reporter   ~0119751

It is caused by the relro protection

When readelf -l *.so prints a line with GNU_RELRO, it does not start.

With the -k-znorelro option it works

Yuriy Sydorov

2020-01-19 21:33

manager   ~0120561

Fixed in r44002. Please test and close the issue.

Issue History

Date Modified Username Field Change
2019-05-27 23:32 Benito van der Zander New Issue
2019-05-27 23:50 Benito van der Zander Note Added: 0116441
2019-05-28 02:07 jamie philbrook Note Added: 0116442
2019-05-28 12:25 Benito van der Zander Note Added: 0116443
2019-05-28 13:25 jamie philbrook Note Added: 0116444
2019-05-31 15:23 Sven Barth Note Added: 0116480
2019-12-11 14:40 Benito van der Zander Note Added: 0119751
2020-01-19 21:33 Yuriy Sydorov Assigned To => Yuriy Sydorov
2020-01-19 21:33 Yuriy Sydorov Status new => resolved
2020-01-19 21:33 Yuriy Sydorov Resolution open => fixed
2020-01-19 21:33 Yuriy Sydorov Fixed in Version => 3.3.1
2020-01-19 21:33 Yuriy Sydorov Fixed in Revision => 44002
2020-01-19 21:33 Yuriy Sydorov FPCTarget => -
2020-01-19 21:33 Yuriy Sydorov Note Added: 0120561