Recent

Author Topic: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH  (Read 1131 times)

cryborg2

  • New Member
  • *
  • Posts: 11
Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« on: July 10, 2020, 03:06:11 pm »
With Delphi

  asm
    //...
    CALL  System.@LStrSetLength
    //...
  end;

It works.


With FP/Lazarus

// asm mode: intel

  asm
    //...
    CALL  @fpc_ansistr_setlength
    //...
  end;

it should work, but actually not, it gives: "Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH"

I have no clue about what's going on at this moment. Any help will be appreciated.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1922
  • Compiler Developer
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #1 on: July 10, 2020, 04:32:27 pm »
With FP/Lazarus

// asm mode: intel

  asm
    //...
    CALL  @fpc_ansistr_setlength
    //...
  end;

it should work, but actually not, it gives: "Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH"

I have no clue about what's going on at this moment. Any help will be appreciated.

You need to reimport the procedure and then call that:

Code: Pascal  [Select][+][-]
  1. Procedure fpc_AnsiStr_SetLength (Var S : RawByteString; l : SizeInt{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});external 'FPC_ANSISTR_SETLENGTH';
  2.  
  3. procedure Test;
  4. begin
  5.   asm
  6.     call fpc_ansistr_setlength
  7.   end;
  8. end;
  9.  

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 746
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #2 on: July 10, 2020, 06:09:33 pm »
I would strongly recommend against doing that. This is a routine that is only accessible by the compiler itself by design. There are no guarantees regarding its signature or behaviour in detail, definitely not across versions. If you want this, define your own procedure that in turn calls setlength. It will be slightly slower, but setlength itself generally does so much work that it probably won't be noticeable.

cryborg2

  • New Member
  • *
  • Posts: 11
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #3 on: July 11, 2020, 08:48:05 am »
With FP/Lazarus

// asm mode: intel

  asm
    //...
    CALL  @fpc_ansistr_setlength
    //...
  end;

it should work, but actually not, it gives: "Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH"

I have no clue about what's going on at this moment. Any help will be appreciated.

You need to reimport the procedure and then call that:

Code: Pascal  [Select][+][-]
  1. Procedure fpc_AnsiStr_SetLength (Var S : RawByteString; l : SizeInt{$ifdef FPC_HAS_CPSTRING}; cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});external 'FPC_ANSISTR_SETLENGTH';
  2.  
  3. procedure Test;
  4. begin
  5.   asm
  6.     call fpc_ansistr_setlength
  7.   end;
  8. end;
  9.  

I have tried it as you mentioned (with a slight modification as I still using the good old FP 2.6.4):
procedure fpc_AnsiStr_SetLength (Var S: AnsiString; l: SizeInt{$ifdef FPC_HAS_CPSTRING};cp: TSystemCodePage{$endif FPC_HAS_CPSTRING}); external 'FPC_ANSISTR_SETLENGTH';

It says: FPC_ANSISTR_SETLENGTH.dll not found.

Then I changed the DLL name to 'TEST.EXE', an gave it another try: The application was unable to start correctly (0xc000007b).


PascalDragon

  • Hero Member
  • *****
  • Posts: 1922
  • Compiler Developer
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #4 on: July 11, 2020, 11:08:52 am »
I have tried it as you mentioned (with a slight modification as I still using the good old FP 2.6.4):
procedure fpc_AnsiStr_SetLength (Var S: AnsiString; l: SizeInt{$ifdef FPC_HAS_CPSTRING};cp: TSystemCodePage{$endif FPC_HAS_CPSTRING}); external 'FPC_ANSISTR_SETLENGTH';

Ah, sorry, I meant external name 'FPC_ANSISTR_SETLENGTH'.

But I'd head Jonas' advice as well: write your own function that calls SetLength.

cryborg2

  • New Member
  • *
  • Posts: 11
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #5 on: July 11, 2020, 12:07:35 pm »
I have tried it as you mentioned (with a slight modification as I still using the good old FP 2.6.4):
procedure fpc_AnsiStr_SetLength (Var S: AnsiString; l: SizeInt{$ifdef FPC_HAS_CPSTRING};cp: TSystemCodePage{$endif FPC_HAS_CPSTRING}); external 'FPC_ANSISTR_SETLENGTH';

Ah, sorry, I meant external name 'FPC_ANSISTR_SETLENGTH'.

But I'd head Jonas' advice as well: write your own function that calls SetLength.

Oh, it working, thank you! ;)
I am not planning to use any new version of FPC, because 3.0.4 generated code is erratic, so I think I can kindly ignore the latter advices.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1922
  • Compiler Developer
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #6 on: July 11, 2020, 02:47:55 pm »
I am not planning to use any new version of FPC, because 3.0.4 generated code is erratic, so I think I can kindly ignore the latter advices.

In how far is it erratic? Do you have an example? If we don't know about it, we can't fix it. Though you could also test whether 3.2 solves it.

cryborg2

  • New Member
  • *
  • Posts: 11
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #7 on: July 11, 2020, 03:30:59 pm »
I am not planning to use any new version of FPC, because 3.0.4 generated code is erratic, so I think I can kindly ignore the latter advices.

In how far is it erratic? Do you have an example? If we don't know about it, we can't fix it. Though you could also test whether 3.2 solves it.

No, I have failed to make any example. I has only the whole code in which the error appears repeatedly at the same exact point.
I have managed to find its location, but was unable to reproduce it within a test example program.
I cannot put together a report in the absence of an example. So I gave up.
I used to report every new issues I encountered, and I used to solve them myself and send my patches or suggestions of solution.
But it was an exception.  :(

PascalDragon

  • Hero Member
  • *****
  • Posts: 1922
  • Compiler Developer
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #8 on: July 11, 2020, 05:36:27 pm »
You say that you managed to locate it. Is it wrongly generated assembly code? Does it occur only on specific platforms? Does it only occur with specific optimization settings? Is the function inlined? Are generics involved? Did the problems also occur with 3.0.2 or 3.0.0?

Maybe indeed do a test with 3.2, many things were fixed in the code generator and parser. You could maybe also do a test with 3.3.1.

cryborg2

  • New Member
  • *
  • Posts: 11
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #9 on: July 16, 2020, 12:18:00 am »
You say that you managed to locate it. Is it wrongly generated assembly code? Does it occur only on specific platforms? Does it only occur with specific optimization settings? Is the function inlined? Are generics involved? Did the problems also occur with 3.0.2 or 3.0.0?

Maybe indeed do a test with 3.2, many things were fixed in the code generator and parser. You could maybe also do a test with 3.3.1.

Sigh.. I cannot promise anything.

cryborg2

  • New Member
  • *
  • Posts: 11
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #10 on: July 26, 2020, 08:03:20 am »
You say that you managed to locate it. Is it wrongly generated assembly code? Does it occur only on specific platforms? Does it only occur with specific optimization settings? Is the function inlined? Are generics involved? Did the problems also occur with 3.0.2 or 3.0.0?

Maybe indeed do a test with 3.2, many things were fixed in the code generator and parser. You could maybe also do a test with 3.3.1.

Now I did it! An error always there with fpc version >= 3.0.0
I'm not sure if it causes one error or more.

But I have succesfully pluck my original code to create an example to reproduce one. All we need is a Button, and the Dialogs unit:


function GetScriptResult: Boolean;
  var s: string;
begin
  s:='('+#176+')';
  Result:=Copy(s, 2, 1)=#176;
end;

procedure TForm1.ButtonClick_CalculateAll(Sender: TObject);
begin
  if GetScriptResult then
    ShowMessage('Ok, it works!')
  else
    ShowMessage('ERROR, OUCH!');
end;

My program uses byte code in strings as commands, and this just breaks it.  %)

Aidex

  • Jr. Member
  • **
  • Posts: 54
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #11 on: July 26, 2020, 09:27:43 am »
#176 is not a valid UTF8 character.
You should try RawByteString instead of String!

In your example, s[2] (a single character) could give a different result than Copy(s,2,1) (an Utf8 string).

You can't compare an incorrectly encoded string to a correctly encoded UTF8 string constant.
The character #176 as UTF8-string is not that single character #176, but its UTF8 encoded representation! Therefore the comparison fails.
« Last Edit: July 26, 2020, 09:44:45 am by Aidex »

cryborg2

  • New Member
  • *
  • Posts: 11
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #12 on: July 27, 2020, 12:56:10 am »
#176 is not a valid UTF8 character.
You should try RawByteString instead of String!

In your example, s[2] (a single character) could give a different result than Copy(s,2,1) (an Utf8 string).

You can't compare an incorrectly encoded string to a correctly encoded UTF8 string constant.
The character #176 as UTF8-string is not that single character #176, but its UTF8 encoded representation! Therefore the comparison fails.

 >:( Who talking about UTF8? Who expecting UTF8? Everythig worked perfectly with fpc 2.6.4. It's not supposed to handle it that way. If so, then they changed it arbitrarily. Originally, I used this charceter/string constant '°' (AltGr + 5), and {$codepage cp437} was set at the top of the Pascal unit with the same result. With 2.6.4 it was OK, from 3.0.0 it wasn't.

PascalDragon

  • Hero Member
  • *****
  • Posts: 1922
  • Compiler Developer
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #13 on: July 27, 2020, 09:19:22 am »
There is nothing arbitrary about this. The code page aware AnsiString type was the big feature (and change) in FPC 3.0.0 (see here which also references this). The FPC RTL itself initializes with the code page of the operating system, but Lazarus forces this to be UTF-8 (see here), thus why you don't have any problem with a command line application, but see this issue with a LCL GUI application.

To better explain where your problem is:

Code: Pascal  [Select][+][-]
  1. s:='('+#176+')';
  2. Result:=Copy(s, 2, 1)=#176;

The string constant at the right side of the assignment to s is in your system's code page. Due to the LCL's setting of using UTF-8 by default the assignment will convert the string to UTF-8 (you can see this by using Length(s), it will return a value > 3). Thus the following Copy will extract only a part of the UTF-8 character for #176, thus the comparison will fail.

cryborg2

  • New Member
  • *
  • Posts: 11
Re: Error: Unknown label identifier @FPC_ANSISTR_SETLENGTH
« Reply #14 on: July 28, 2020, 08:29:25 am »
There is nothing arbitrary about this. The code page aware AnsiString type was the big feature (and change) in FPC 3.0.0 (see here which also references this). The FPC RTL itself initializes with the code page of the operating system, but Lazarus forces this to be UTF-8 (see here), thus why you don't have any problem with a command line application, but see this issue with a LCL GUI application.

To better explain where your problem is:

Code: Pascal  [Select][+][-]
  1. s:='('+#176+')';
  2. Result:=Copy(s, 2, 1)=#176;

The string constant at the right side of the assignment to s is in your system's code page. Due to the LCL's setting of using UTF-8 by default the assignment will convert the string to UTF-8 (you can see this by using Length(s), it will return a value > 3). Thus the following Copy will extract only a part of the UTF-8 character for #176, thus the comparison will fail.

When implementing a new feature, it should be introduced as an extra option beside the well-known old one, not by replacing it!
I still don't understand, why they blatantly REPLACING something with a totally different incompatible thing, messing up existing codes.  :o

 

TinyPortal © 2005-2018