Recent

Author Topic: [Solved] Generating PIC, but reference is not PIC-safe  (Read 2960 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 2509
    • StrumPract is the musicians best friend
[Solved] Generating PIC, but reference is not PIC-safe
« on: October 22, 2021, 07:27:57 pm »
Hello.

I am able to use -k-pie -k-znow -Cg for all my projects thanks to fpc 3.3.1. and create a pie executable.

But in a project that uses asm code there is that error at linking:

Quote
Generating PIC, but reference is not PIC-safe

This point to 2 asm lines:

Code: Pascal  [Select][+][-]
  1. procedure teefo.MemWD;
  2.   var
  3.     f : byte;
  4. begin
  5. gev.wd := 0;
  6. for f := 0 to 6 do if ListWD[f] then gev.wd := gev.wd or (1 shl f);
  7.  if tun.engtrue_calend_fmt then begin
  8.  asm
  9.      push ax
  10.      mov  al, gev.wd  // This line point to gev.wd
  11.      mov  ah, al
  12.      and  al, Byte(1{bit1})
  13.      shl  al, 7
  14.      or   ah, al
  15.      ror  ah, 1
  16.      mov  gev.wd, ah  // This line point to gev.wd
  17.      pop  ax
  18.  end;
  19.  end;
  20. end;

If, for workaround, those 2 lines are commented, the compilation + link is ok.

Sadly my asm knowledge are too poor and I dont see how to fix it.
Does somebody have a idea?

Thanks.

Fre;D

« Last Edit: October 22, 2021, 07:56:52 pm by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 2509
    • StrumPract is the musicians best friend
Re: Generating PIC, but reference is not PIC-safe
« Reply #1 on: October 22, 2021, 07:55:44 pm »
Hello.

OK, solved using a temp variable:
Code: Pascal  [Select][+][-]
  1. procedure teefo.MemWD;
  2.   var
  3.     f, wdtmp : byte;  
  4. begin
  5. gev.wd := 0;
  6. wdtmp := gev.wd;
  7.  
  8. for f := 0 to 6 do if ListWD[f] then
  9. begin
  10.  gev.wd := gev.wd or (1 shl f);
  11.  wdtmp := gev.wd;
  12. end;
  13.  
  14.  if tun.engtrue_calend_fmt then begin
  15.  asm
  16.      push ax
  17.      mov  al, wdtmp
  18.      mov  ah, al
  19.      and  al, Byte(1{bit1})
  20.      shl  al, 7
  21.      or   ah, al
  22.      ror  ah, 1
  23.      mov  wdtmp, ah
  24.      pop  ax
  25.  end;
  26.  end;
  27. end;

Sorry for the noise.

Fre;D
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

 

TinyPortal © 2005-2018