View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038471 | FPC | Compiler | public | 2021-02-11 01:22 | 2021-04-10 10:49 |
Reporter | shiraishi | Assigned To | Jonas Maebe | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | Intel Mac | OS | OS 10.15 | ||
Fixed in Version | 3.3.1 | ||||
Summary | 0038471: MAC(Intel) FPC 3.2.0: An assembler function causes an error on linking | ||||
Description | Set Project Option - parsing - Assembler Style Intel The following goes on Quick Compile, but not on Compile. unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type TForm1 = class(TForm) private public end; var Form1: TForm1; implementation {$R *.lfm} function neg(a:shortint):shortint;assembler; asm mov al,a neg al end; end. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
|
|
What error are you getting? Is it possible for you to provide an assembler dump with the -a option? That might offer some clues. |
|
Warning: (9011) Object unit1.o not found, Linking may fail ! (9015) Linking /Users/shiraishi/tmp2/project1 ld: file not found: unit1.o An error occurred while linking Error: (9013) Error while linking Fatal: (10026) There were 1 errors compiling module, stopping Fatal: (1018) Compilation aborted Error: /usr/local/bin/ppcx64 returned an error exitcode |
|
Good function neg(a:longint):longint;assembler; asm mov eax,a neg eax end; Good function neg(a:longint):longint;assembler; asm mov eax,a neg eax end; Good function neg(a:shortint):shortint;assembler; asm mov ax,a neg ax end; Good function neg(a:smallint):shortint;assembler; asm mov al,a neg ax end; NG function neg(a:byte):byte;assembler; asm mov al,a //neg al end; The following reports warning but compile goes. Compile Project, Target: project1: Success, Warnings: 1 unit1.pas(41,18) Warning: Size suffix and destination or source size do not match function neg(a:shortint):shortint;assembler; asm mov eax,a neg al end; |
|
a is shortint so 8bit while eax register is 32bit. Use: mov al,a |
|
or use movsx. https://www.felixcloutier.com/x86/movsx:movsxd |
|
also function neg(a:shortint):shortint;assembler; asm mov al,a neg al end; No good. |
|
It may be related to the fact that the Darwin/i386 ABI requires that 8/16 bit parameters are extended to 32 bits on the caller side. The assembler reader should use the callee side location information though, and that one should be untouched. So there's definitely a bug somewhere. On the other hand, the Darwin/i386 ABI also requires that all returned 8/16 bit values are extended to 32 bits, so make sure to do that in your pure assembler functions. |
|
Also an assembler procedure can not be compiled. procedure neg(a:shortint);assembler; asm mov al,a neg al end; |
|
This fault does not happen for regular functions. For example, the following can be compiled. function neg(a:shortint):shortint; begin asm mov al,a neg al end; end; |
|
That's because if it's not a pure assembler routine, the compiler moves the parameter to a local alias of the right size in the entry code. |
|
> Also an assembler procedure can not be compiled. Yes, parameters to functions and procedures are handled the same way. My remark about functions was about how you have to also make sure that you sign/zero-extend your function results in pure assembler functions (the compiler is not be able to give an error if you forget that). |
|
This actually already works on current trunk. It's not fixed in 3.2.2 though. Also, as mentioned earlier, the Darwin/x86-64 ABI requires that all returned 8/16 bit values are extended to 32 bits, so you will have to write this even on trunk: function neg(a:shortint):shortint;assembler; asm movsx eax,a neg eax end; |
Date Modified | Username | Field | Change |
---|---|---|---|
2021-02-11 01:22 | shiraishi | New Issue | |
2021-02-11 01:22 | shiraishi | File Added: tmp2.zip | |
2021-02-18 22:59 | Jonas Maebe | Project | Lazarus => FPC |
2021-02-18 23:25 | J. Gareth Moreton | Note Added: 0129006 | |
2021-02-28 23:28 | shiraishi | Note Added: 0129262 | |
2021-03-01 10:15 | shiraishi | Note Added: 0129264 | |
2021-03-01 11:40 | ravi dion | Note Added: 0129270 | |
2021-03-01 12:09 | Thaddy de Koning | Note Added: 0129272 | |
2021-03-01 12:35 | shiraishi | Note Added: 0129275 | |
2021-03-01 21:52 | Jonas Maebe | Note Added: 0129294 | |
2021-03-01 22:03 | shiraishi | Note Added: 0129295 | |
2021-03-01 22:11 | shiraishi | Note Added: 0129296 | |
2021-03-01 22:16 | Jonas Maebe | Note Added: 0129297 | |
2021-03-01 22:42 | Jonas Maebe | Note Added: 0129298 | |
2021-04-10 10:49 | Jonas Maebe | Assigned To | => Jonas Maebe |
2021-04-10 10:49 | Jonas Maebe | Status | new => resolved |
2021-04-10 10:49 | Jonas Maebe | Resolution | open => fixed |
2021-04-10 10:49 | Jonas Maebe | Fixed in Version | => 3.3.1 |
2021-04-10 10:49 | Jonas Maebe | FPCTarget | => - |
2021-04-10 10:49 | Jonas Maebe | Note Added: 0130216 |