Recent

Author Topic: [SOLVED] FreePascal version information.  (Read 954 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 12974
[SOLVED] FreePascal version information.
« on: March 24, 2023, 10:17:46 am »
I just found some old code of mine I wrote as an internal test for an accepted patch to system that I wrote (OpaqueData):
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. var
  3.   sfpcv : TOpaqueData;external name '__fpc_ident';
  4. begin
  5.   Writeln(PChar(@sfpcv));
  6. end.
  7.  

Is this always guaranteed to work? Then I can add that test to the wiki or even create a function for it.
What it does that it retrieves the compiler version, compiler date and platform from the binary for which it is compiled.
( You can do this with any section, but this one seems very useful )

Probably only a compiler dev can answer this. I tested on my usual platforms.
« Last Edit: March 25, 2023, 07:57:41 am by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

Red_prig

  • Jr. Member
  • **
  • Posts: 99
Re: FreePascal version information.
« Reply #1 on: March 24, 2023, 12:16:00 pm »
Code search results in this:
https://gitlab.com/freepascal.org/fpc/source/-/blob/main/compiler/ngenutil.pas
so it's probably still relevant.

Thaddy

  • Hero Member
  • *****
  • Posts: 12974
Re: FreePascal version information.
« Reply #2 on: March 24, 2023, 12:19:05 pm »
Code search results in this:
https://gitlab.com/freepascal.org/fpc/source/-/blob/main/compiler/ngenutil.pas
so it's probably still relevant.
That info is known to me and how I could write it.
I merely want to know if it is safe in all or most platforms.

Otherwise it can be a false impression.

But thanks for the contribution: I think... it is still relevant too. That's why I ask.
Except for the macro's there is not really a PUBLISHED efficient way to detect with what compiler version a FPC/Lazarus version is compiled.
« Last Edit: March 24, 2023, 12:27:12 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

Red_prig

  • Jr. Member
  • **
  • Posts: 99
Re: FreePascal version information.
« Reply #3 on: March 24, 2023, 12:28:31 pm »
A quick look shows that this is always initialized in InsertMemorySizes, but in the 8086 and jvm platforms the function code is overridden, so it looks like except for these 2 cases.

Bart

  • Hero Member
  • *****
  • Posts: 4974
    • Bart en Mariska's Webstek
Re: FreePascal version information.
« Reply #4 on: March 24, 2023, 01:28:47 pm »
AFAIK the recommended way is to use {$I xxx} for that, see https://www.freepascal.org/docs-html/prog/progsu41.html#x48-470001.2.41.
This is guaranteed to work at all times.

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 12974
Re: FreePascal version information.
« Reply #5 on: March 24, 2023, 04:35:46 pm »
@Bart
I know that too, but that is different information.
I actually get compliments for being rude... (well, Dutch, but that is the same)

Thaddy

  • Hero Member
  • *****
  • Posts: 12974
Re: FreePascal version information.
« Reply #6 on: March 24, 2023, 04:41:30 pm »
A quick look shows that this is always initialized in InsertMemorySizes, but in the 8086 and jvm platforms the function code is overridden, so it looks like except for these 2 cases.
Those two are  always cross-compiled platforms. I checked, and my code works to identify the compiler. Thanks again for looking into this.

Same as my answer to Bart: my question is very, very particular: can it be relied upon in each and every case?
Should it be considered hackery or useful?
That is not because this particular example, but about any section in the code being accessible.
And the code is definitely public - through the external modifier - but the double underscore tells me I may not rely on it. Except maybe for pure assembler, which is the real use case.
And don't be confused with Opaquedata: that is simply a feature I added for external libraries.
I left out the above example in my patch request, probably for that reason, but its use looks just fine.

Hence I wrote: probably only answerable by compiler devs. I will ask on the development list just in case.
« Last Edit: March 24, 2023, 05:16:06 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

Kays

  • Hero Member
  • *****
  • Posts: 505
  • Whasup!?
    • KaiBurghardt.de
Re: FreePascal version information.
« Reply #7 on: March 24, 2023, 09:06:16 pm »
[…] Is this always guaranteed to work? […]
If isn’t documented, it doesn’t exist. I couldn’t find any documentation for __fpc_ident therefore it doesn’t exist. More specifically it may be removed without notice.
Yours Sincerely
Kai Burghardt

PascalDragon

  • Hero Member
  • *****
  • Posts: 5051
  • Compiler Developer
Re: FreePascal version information.
« Reply #8 on: March 24, 2023, 10:17:17 pm »
Probably only a compiler dev can answer this. I tested on my usual platforms.

While currently the compiler inserts that information always, this is not documented and thus must be considered an implementation detail that may change from version to version (unlikely it will, like most implementation details, but not guaranteed).

Thaddy

  • Hero Member
  • *****
  • Posts: 12974
Re: FreePascal version information.
« Reply #9 on: March 25, 2023, 07:50:52 am »
OK, then I will not pursue it and keep it under the hood. IOW not document it any further.
I already came to that conclusion, but still it is a nice one-liner.. ;)  8) :-X

Tnx Sarah.
[edit]
But programmers who need to access sections may take advantage from it. I now remember one of the compiler dev's gave me this trickery. May well have been you  8) Now I have the code marked as NOT recommended.
I was actually looking for some even older code to help out the Asio/VST question when I found this.
Motto: don't throw your hard disks away even if the computer has been pushing up daisies.
« Last Edit: March 25, 2023, 08:48:01 am by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5051
  • Compiler Developer
Re: FreePascal version information.
« Reply #10 on: March 25, 2023, 04:27:31 pm »
OK, then I will not pursue it and keep it under the hood. IOW not document it any further.
I already came to that conclusion, but still it is a nice one-liner.. ;)  8) :-X

All information except the date the compiler had been built at can be retrieved using the {$I ...} directive.

Thaddy

  • Hero Member
  • *****
  • Posts: 12974
Re: [SOLVED] FreePascal version information.
« Reply #11 on: March 25, 2023, 04:56:39 pm »
I know. But it is a one liner and more complete.
I actually get compliments for being rude... (well, Dutch, but that is the same)

 

TinyPortal © 2005-2018