Lazarus

Programming => Operating Systems => Linux => Topic started by: Fred vS on October 22, 2021, 07:27:57 pm

Title: [Solved] Generating PIC, but reference is not PIC-safe
Post by: Fred vS 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

Title: Re: Generating PIC, but reference is not PIC-safe
Post by: Fred vS 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
TinyPortal © 2005-2018