View Issue Details

IDProjectCategoryView StatusLast Update
0035107FPCRTLpublic2019-10-30 18:34
ReporterBenito van der Zander Assigned ToJonas Maebe  
Status resolvedResolutionno change required 
Product Version3.3.1 
Summary0035107: TLS initialization crashes for 32 bit crosscompiled on 64-bit x86
DescriptionA 32-bit program does not start when compiled and run on 64-bit due to INITTLS failure. Even if it is just begin end.
Additional InformationStarting program: /tmp/project1

Program received signal SIGSEGV, Segmentation fault.
0x08069710 in SYSTEM_$$_INITTLS ()
(gdb) bt
0 0x08069710 in SYSTEM_$$_INITTLS ()
1 0x0804902b in SI_PRC_$$__FPC_PROC_START ()
(gdb) disassemble
Dump of assembler code for function SYSTEM_$$_INITTLS:
   0x08069670 <+0>: push ebp
   0x08069671 <+1>: mov ebp,esp
   0x08069673 <+3>: lea esp,[esp-0xc]
   0x08069677 <+7>: push ebx
   0x08069678 <+8>: push esi
   0x08069679 <+9>: push edi
   0x0806967a <+10>: mov edx,DWORD PTR ds:0x8073d50
   0x08069680 <+16>: jmp 0x806968b <SYSTEM_$$_INITTLS+27>
   0x08069682 <+18>: lea esi,[esi+0x0]
   0x08069688 <+24>: add edx,0x4
   0x0806968b <+27>: cmp DWORD PTR [edx],0x0
   0x0806968e <+30>: jne 0x8069688 <SYSTEM_$$_INITTLS+24>
   0x08069690 <+32>: add edx,0x4
   0x08069693 <+35>: mov DWORD PTR [ebp-0xc],0x0
   0x0806969a <+42>: xor ecx,ecx
   0x0806969c <+44>: jmp 0x80696e3 <SYSTEM_$$_INITTLS+115>
   0x0806969e <+46>: mov esi,esi
   0x080696a0 <+48>: mov eax,DWORD PTR [edx]
   0x080696a2 <+50>: cmp eax,0x3
   0x080696a5 <+53>: jl 0x80696e0 <SYSTEM_$$_INITTLS+112>
   0x080696a7 <+55>: sub eax,0x3
   0x080696aa <+58>: je 0x80696c0 <SYSTEM_$$_INITTLS+80>
   0x080696ac <+60>: sub eax,0x2
   0x080696af <+63>: je 0x80696d0 <SYSTEM_$$_INITTLS+96>
   0x080696b1 <+65>: jmp 0x80696e0 <SYSTEM_$$_INITTLS+112>
   0x080696b3 <+67>: lea esi,[esi+eiz*1+0x0]
   0x080696ba <+74>: lea esi,[esi+0x0]
   0x080696c0 <+80>: mov eax,DWORD PTR [edx+0x4]
   0x080696c3 <+83>: mov DWORD PTR [ebp-0xc],eax
   0x080696c6 <+86>: jmp 0x80696e0 <SYSTEM_$$_INITTLS+112>
   0x080696c8 <+88>: lea esi,[esi+eiz*1+0x0]
   0x080696cf <+95>: nop
   0x080696d0 <+96>: mov ecx,DWORD PTR [edx+0x4]
   0x080696d3 <+99>: lea esi,[esi+eiz*1+0x0]
   0x080696da <+106>: lea esi,[esi+0x0]
   0x080696e0 <+112>: add edx,0x8
   0x080696e3 <+115>: cmp DWORD PTR [edx],0x0
   0x080696e6 <+118>: jne 0x80696a0 <SYSTEM_$$_INITTLS+48>
   0x080696e8 <+120>: mov BYTE PTR [ebp-0x8],0x0
   0x080696ec <+124>: mov DWORD PTR [ebp-0x4],0x0
   0x080696f3 <+131>: mov di,cx
   0x080696f6 <+134>: cmp di,0x1
   0x080696fb <+139>: jl 0x8069769 <SYSTEM_$$_INITTLS+249>
   0x08069701 <+145>: xor bx,bx
   0x08069704 <+148>: lea esi,[esi+eiz*1+0x0]
   0x08069708 <+152>: add bx,0x1
--Type <RET> for more, q to quit, c to continue without paging--
   0x0806970d <+157>: mov eax,DWORD PTR [ebp-0xc]
=> 0x08069710 <+160>: mov edx,DWORD PTR [eax]
   0x08069712 <+162>: cmp edx,0x2
   0x08069715 <+165>: jb 0x8069760 <SYSTEM_$$_INITTLS+240>
   0x08069717 <+167>: sub edx,0x2
   0x0806971a <+170>: je 0x80697a7 <SYSTEM_$$_INITTLS+311>
   0x08069720 <+176>: sub edx,0x5
   0x08069723 <+179>: jne 0x8069760 <SYSTEM_$$_INITTLS+240>
   0x08069725 <+181>: lea esi,[esi+eiz*1+0x0]
   0x0806972c <+188>: lea esi,[esi+eiz*1+0x0]
   0x08069730 <+192>: mov BYTE PTR [ebp-0x8],0x1
   0x08069734 <+196>: mov eax,DWORD PTR [ebp-0xc]
   0x08069737 <+199>: mov edx,DWORD PTR [eax+0x14]
   0x0806973a <+202>: add DWORD PTR [ebp-0x4],edx
   0x0806973d <+205>: mov eax,DWORD PTR [ebp-0xc]
   0x08069740 <+208>: mov esi,DWORD PTR [eax+0x1c]
   0x08069743 <+211>: lea eax,[esi-0x1]
   0x08069746 <+214>: add eax,DWORD PTR [ebp-0x4]
   0x08069749 <+217>: mov ecx,eax
   0x0806974b <+219>: xor edx,edx
   0x0806974d <+221>: div esi
   0x0806974f <+223>: mov eax,ecx
   0x08069751 <+225>: sub eax,edx
   0x08069753 <+227>: mov DWORD PTR [ebp-0x4],eax
   0x08069756 <+230>: lea esi,[esi+eiz*1+0x0]
   0x0806975d <+237>: lea esi,[esi+0x0]
   0x08069760 <+240>: add DWORD PTR [ebp-0xc],0x20
   0x08069764 <+244>: cmp di,bx
   0x08069767 <+247>: jg 0x8069708 <SYSTEM_$$_INITTLS+152>
   0x08069769 <+249>: mov al,BYTE PTR [ebp-0x8]
   0x0806976c <+252>: test al,al
   0x0806976e <+254>: je 0x80697a7 <SYSTEM_$$_INITTLS+311>
   0x08069770 <+256>: mov eax,DWORD PTR [ebp-0x4]
   0x08069773 <+259>: lea edx,[eax+0xfff]
   0x08069779 <+265>: mov eax,edx
   0x0806977b <+267>: and eax,0xfff
   0x08069780 <+272>: sub edx,eax
   0x08069782 <+274>: lea eax,[edx+0x4]
   0x08069785 <+277>: mov DWORD PTR [ebp-0x4],eax
   0x08069788 <+280>: push 0x22
   0x0806978a <+282>: push 0xffffffff
   0x0806978c <+284>: push 0x0
   0x0806978e <+286>: push 0x0
   0x08069790 <+288>: mov edx,DWORD PTR [ebp-0x4]
   0x08069793 <+291>: mov ecx,0x3
   0x08069798 <+296>: xor eax,eax
--Type <RET> for more, q to quit, c to continue without paging--
   0x0806979f <+303>: mov edx,DWORD PTR [ebp-0x4]
   0x080697a2 <+306>: call 0x8069600 <SYSTEM_$$_FPSET_TLS$POINTER$LONGWORD$$LONGINT>
   0x080697a7 <+311>: pop edi
   0x080697a8 <+312>: pop esi
   0x080697a9 <+313>: pop ebx
   0x080697aa <+314>: mov esp,ebp
   0x080697ac <+316>: pop ebp
   0x080697ad <+317>: ret
End of assembler dump.

But it works with uses cthreads;
TagsNo tags attached.
Fixed in Revision
Attached Files


has duplicate 0036233 closedFlorian fpc not compile after revision 40272 on i386 linux 



2019-02-17 02:24

reporter   ~0114206

Last edited: 2019-02-17 02:25

View 2 revisions

Can you try the latest patch attached on this bug report?

Jonas Maebe

2019-02-17 14:07

manager   ~0114217

Under Linux, with FPC rhe main difference between cross-compiling and native compiling is that with cross-compiling the compiler uses a linker script that's built into the compiler, while with native compiling the default linker script of the linker is used.

The built-in linker scripts haven't always been kept up to date, so they probably should just be removed (or at least only used if the -X9 parameter is used). When I added support for using the linker's own linker scripts (which requires binutils 2.19.1 or later), I did not have time to test cross-compiling and hence left that as it was.

You could try replacing the "if sysrootpath='' then" check in compiler/systems/t_linux.pas with "if true then" to see if cross-compiling still works, and if it solves the problem.

Jonas Maebe

2019-05-12 12:51

manager   ~0116147

Last edited: 2019-05-12 13:58

View 2 revisions

Pierre noticed this issue was introduced in GNU Binutils 2.31 and seems to be solved if you use GNU Binutils 2.32. Are you using 2.31 or 2.31.1?

Benito van der Zander

2019-05-19 12:38

reporter   ~0116262

I am using 2.31

Benito van der Zander

2019-06-10 17:28

reporter   ~0116659

It is working with 2.32

Jonas Maebe

2019-06-10 17:30

manager   ~0116660

Thanks for verifying.

Issue History

Date Modified Username Field Change
2019-02-17 00:43 Benito van der Zander New Issue
2019-02-17 02:24 Cyrax Note Added: 0114206
2019-02-17 02:25 Cyrax Note Edited: 0114206 View Revisions
2019-02-17 14:07 Jonas Maebe Note Added: 0114217
2019-05-12 12:51 Jonas Maebe Note Added: 0116147
2019-05-12 13:58 Jonas Maebe Note Edited: 0116147 View Revisions
2019-05-19 12:38 Benito van der Zander Note Added: 0116262
2019-06-10 17:28 Benito van der Zander Note Added: 0116659
2019-06-10 17:30 Jonas Maebe Assigned To => Jonas Maebe
2019-06-10 17:30 Jonas Maebe Status new => resolved
2019-06-10 17:30 Jonas Maebe Resolution open => no change required
2019-06-10 17:30 Jonas Maebe FPCTarget => -
2019-06-10 17:30 Jonas Maebe Note Added: 0116660
2019-10-30 18:34 Florian Relationship added has duplicate 0036233