Recent

Author Topic: [SOLVED] how to turn off PIC on MIPS?  (Read 2730 times)

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
[SOLVED] how to turn off PIC on MIPS?
« on: July 11, 2024, 08:46:38 pm »
Someone set the PIC to default.

If I do:
Code: Pascal  [Select][+][-]
  1. system_mipsel_ps1_info : tsysteminfo =
  2.           (
  3.             system       : system_mipsel_ps1;
  4.             name         : 'PlayStation 1 for MIPSEL';
  5.             shortname    : 'ps1';
  6.             flags        : [tf_no_pic_supported];                <--------------
  7.             cpu          : cpu_mipsel;
  8.  

the PIC is not disabled!

what to do?
« Last Edit: July 15, 2024, 11:19:52 am by Key-Real »

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: turn off PIC
« Reply #1 on: July 11, 2024, 10:16:21 pm »
correction:

si_prc.pp compiles with PIC:
Code: ASM  [Select][+][-]
  1. _start:
  2. .ent SI_PRC_$$__FPC_PROC_START$$LONGINT
  3.         .set    nomips16
  4.         .frame  $sp,112,$ra
  5.         .mask   0xC0000000,-44
  6.         .fmask  0x00000000,0
  7.         .set    noreorder
  8.         .set    nomacro
  9.         addiu   $sp,$sp,-112
  10.         sw      $ra,68($sp)
  11.         sw      $fp,64($sp)
  12.         addiu   $fp,$sp,112
  13. # Using PIC code for a_call_name                                      <----------
  14.         lui     $gp,%hi(_gp)                                                       <----------
  15.         addiu   $gp,$gp,%lo(_gp)                                        <----------
  16.         lw      $t9,%call16(PASCALMAIN)($gp)                        <-----------
  17.         jalr    $t9                                                                       <-----------
  18.         nop
  19.         lw      $fp,64($sp)
  20.         lw      $ra,68($sp)
  21.         jr      $ra
  22.         addiu   $sp,$sp,112
  23.         .set    macro
  24.         .set    reorder
  25. .end SI_PRC_$$__FPC_PROC_START$$LONGINT
  26.  


my Programm whithout:
Code: ASM  [Select][+][-]
  1. main:
  2. .globl  PASCALMAIN
  3. PASCALMAIN:
  4. .ent main
  5.         .set    nomips16
  6.         .frame  $sp,104,$ra
  7.         .mask   0xC0000000,-36
  8.         .fmask  0x00000000,0
  9.         .set    noreorder
  10.         .set    nomacro
  11.         addiu   $sp,$sp,-104
  12.         sw      $ra,68($sp)
  13.         sw      $fp,64($sp)
  14.         addiu   $fp,$sp,104
  15.         jal     fpc_initializeunits
  16.         nop
  17. ...
  18.  



how can this be?

dbannon

  • Hero Member
  • *****
  • Posts: 3019
    • tomboy-ng, a rewrite of the classic Tomboy
Re: turn off PIC
« Reply #2 on: July 12, 2024, 02:46:36 am »
Don't know amything about mips, but the build script for my app is used to make a powerpc64el binary and hardening does not work as it should on that cpu.

The hardening is turned ON with a string like this on the fpc command line

FPCHARD=" -Cg  -k-pie -k-znow "

And when building for power, that is left out. So, that says to me, hardening is off by default, turned on with command line switches.

Davo

 
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #3 on: July 12, 2024, 08:43:26 am »
ok,

it seems the
Code: Pascal  [Select][+][-]
  1. [tf_no_pic_supported]
works only for the main program not for units.

Is there another switch specially for units?

tetrastes

  • Hero Member
  • *****
  • Posts: 517

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #5 on: July 12, 2024, 10:39:45 am »
this doesn't work :(

Code: Pascal  [Select][+][-]
  1. {$SMARTLINK OFF}
  2. {$PIC OFF}
  3. unit si_prc;
  4. interface
  5.  
  6. implementation
  7.  
  8. procedure PascalMain; external name 'PASCALMAIN';
  9.  
  10.  
  11. { this function must be the first in this unit which contains code }
  12. function _FPC_proc_start: longint; cdecl; public name '_start';
  13. begin
  14.                 PascalMain;
  15. end;
  16.  
  17. begin
  18. end.
  19.  

is compiled:

Code: ASM  [Select][+][-]
  1.         .file "si_prc.pp"
  2.         .module nomips16
  3. # Begin asmlist al_procedures
  4.  
  5. .section .text,"ax"
  6.         .balign 4
  7. .globl  SI_PRC_$$__FPC_PROC_START$$LONGINT
  8. SI_PRC_$$__FPC_PROC_START$$LONGINT:
  9. .globl  _start
  10. _start:
  11. .ent SI_PRC_$$__FPC_PROC_START$$LONGINT
  12.         .set    nomips16
  13.         .frame  $sp,112,$ra
  14.         .mask   0xC0000000,-44
  15.         .fmask  0x00000000,0
  16.         .set    noreorder
  17.         .set    nomacro
  18.         addiu   $sp,$sp,-112
  19.         sw      $ra,68($sp)
  20.         sw      $fp,64($sp)
  21.         addiu   $fp,$sp,112
  22. # Using PIC code for a_call_name
  23.         lui     $gp,%hi(_gp)
  24.         addiu   $gp,$gp,%lo(_gp)
  25.         lw      $t9,%call16(PASCALMAIN)($gp)
  26.         jalr    $t9
  27.         nop
  28.         lw      $fp,64($sp)
  29.         lw      $ra,68($sp)
  30.         jr      $ra
  31.         addiu   $sp,$sp,112
  32.         .set    macro
  33.         .set    reorder
  34. .end SI_PRC_$$__FPC_PROC_START$$LONGINT
  35. # End asmlist al_procedures
  36.  

with PIC code!

dbannon

  • Hero Member
  • *****
  • Posts: 3019
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to turn off PIC on MIPS?
« Reply #6 on: July 12, 2024, 11:06:45 am »
The point is Key-Real, PIC is off by default, you turn it ON with either -Cg or the define tetrastes pointed to.

So, you should be looking for where, in your code (?) its turned on.  Unless there is some difference with mips ?? Seems unlikely.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #7 on: July 12, 2024, 11:23:59 am »
I'm trying to see where it is turned ON,

but I can't find it... there is a lots of code.

someone hints?

dbannon

  • Hero Member
  • *****
  • Posts: 3019
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to turn off PIC on MIPS?
« Reply #8 on: July 12, 2024, 12:03:22 pm »
Hmm, I guess it has to that directive that tetrastes pointed to. So, search the source dir for "PIC" ?

If you are on linux, cd to top of source tree and type

$> grep -niR PIC *

I guess there must be some way to search all the code on Windows but I am not the person to ask I am afraid.

Have all the units been rebuilt ?  I am not sure if you are using Lazarus here, "clean up and build" would be good. If not, maybe blow away the lib dir in the source dir ?

Have you tried a simple hello world app ?  Just to be sure the basics are working ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #9 on: July 12, 2024, 12:10:02 pm »
I use SublimeText, so I am making a full search on the whole compiler folder....

It is a lot code to go through.

Yes my hello world binary is compiled whitout PIC, only the units :(


I'm under Linux

dbannon

  • Hero Member
  • *****
  • Posts: 3019
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to turn off PIC on MIPS?
« Reply #10 on: July 12, 2024, 02:31:11 pm »
Yes my hello world binary is compiled whitout PIC, only the units :(

Thats good !  So, its got to be either that one or more units were compiled with the -Cg to fpc OR that directive !  You are almost there Key-Real !

Must be a lot of code .....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #11 on: July 14, 2024, 11:02:19 am »
no it is not so good news :(

because somewhere in
current_settings.moduleswitches it was set to cs_create_pic
only for units....

so, where?

AND why the MIPS developers leave me alone?

and yes, I'm almost there, because I had it working and I knew the next steps (except the current issue)....

https://www.youtube.com/shorts/gF90iw39Dpo

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #12 on: July 14, 2024, 12:06:36 pm »
After I looked at the commits of the ./compiler/MIPS folder, changes I didn't knew about were made not there.

Somebody changed the global compiler behavior like:
Code: Pascal  [Select][+][-]
  1. procedure TLinkerPS1.InitSysInitUnitName;
  2. begin
  3.   sysinitunit:='si_prc';              <--------------
  4. end;
  5.  

so I think the forced unit PIC default set was done by not a MIPS developer.

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #13 on: July 14, 2024, 12:24:09 pm »
on the over side, if I look to the compiler commits itself, I cant fined no changes pointing to my issue (at least not form commit messages)

Key-Real

  • Sr. Member
  • ****
  • Posts: 362
Re: how to turn off PIC on MIPS?
« Reply #14 on: July 14, 2024, 05:00:05 pm »
Where ist the place to Set

current_settings.moduleswitches

Perhaps ist is messed Up Somethere there

 

TinyPortal © 2005-2018