Recent

Author Topic: [SOLVED]Do we have the plan about adding option -fPIE?  (Read 1891 times)

TYDQ

  • Full Member
  • ***
  • Posts: 102
[SOLVED]Do we have the plan about adding option -fPIE?
« on: August 07, 2024, 09:57:34 am »
gcc's -fPIE option can make the executable loading position independent.It is important that loaded executable files cannot to be affected by other loaded executable files.Do our fpc development team has the plan to add this for further version?
« Last Edit: August 28, 2024, 05:54:23 am by TYDQ »

paweld

  • Hero Member
  • *****
  • Posts: 1187
@TYDQ: I think you can get answers to your questions faster on the mailing list - you have links in the left menu of the page
Best regards / Pozdrawiam
paweld

MarkMLl

  • Hero Member
  • *****
  • Posts: 7503
I've attempted to make that point more than once.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11731
  • FPC developer.
FPC already has that as "-Cg".

MarkMLl

  • Hero Member
  • *****
  • Posts: 7503
FPC already has that as "-Cg".

Frankly I /thought/ there was. The problem appears to be that looking at help output

Code: [Select]
-Cg        Generate PIC code

Ditto in the documentation at https://www.freepascal.org/docs-html/current/user/userap1.html#x171-178000A so it certainly doesn't spring out when one does the sort of quick check I tried earlier... since there's a whole line available I thing the term could usefully be given in full rather than as an acronym.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Khrys

  • Jr. Member
  • **
  • Posts: 81
FPC already has that as "-Cg".

PICPIE  though, right? AFAIK the key thing about position-independent executables is that they are loaded to a different, randomized base address each time they run (ASLR), which in turn requires that the executable be composed entirely of position-independent code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7503
FPC already has that as "-Cg".

PICPIE  though, right? AFAIK the key thing about position-independent executables is that they are loaded to a different, randomized base address each time they run (ASLR), which in turn requires that the executable be composed entirely of position-independent code.

But I think that's what OP's asking about... and https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Code-Gen-Options.html#Code%20Gen%20Options discussed -fpic and fPIC options with no mention of -fPIE.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11731
  • FPC developer.
I also quickly researched, but found no definitive answer. Still it seems to me that -fpie is simply passed to the linker on the final link to set some tags in the ELF header.

So compiling everything with -Cg, and passing -k-pie to the final link might work, give it a try.

Thaddy

  • Hero Member
  • *****
  • Posts: 15531
  • Censorship about opinions does not belong here.
It might work with an external linker, Marco? or does the internal linker support that too?
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11731
  • FPC developer.
It might work with an external linker, Marco? or does the internal linker support that too?

I assumed this was about ELF, where there is an alpha stage internal linker, but default is external.

Afaik win64 EXEs are always position independent.

dbannon

  • Hero Member
  • *****
  • Posts: 3018
    • tomboy-ng, a rewrite of the classic Tomboy
Yes, it does work (sorry for an image instead of text, its in a vm and I'm away from home).

EDIT: posted too early !

FPCHARD=" -Cg  -k-pie -k-znow "
....
Include $FPCHARD on the fpc command line. As you say, its passed to the linker. Seems to work on all except POWER64el

Davo
« Last Edit: August 07, 2024, 01:31:29 pm by dbannon »
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

TYDQ

  • Full Member
  • ***
  • Posts: 102
FPC already has that as "-Cg".
Cg is -fPIC(Position independent code),when PIC object files linked to executable or shared library by linker,they will be not Position independent.
-fPIE is Position independent executable,it is not the same as just compiling position independent object files.
Do you mean it(the -Cg) is same as -fPIE in fpc in linux?

TYDQ

  • Full Member
  • ***
  • Posts: 102
I also quickly researched, but found no definitive answer. Still it seems to me that -fpie is simply passed to the linker on the final link to set some tags in the ELF header.

So compiling everything with -Cg, and passing -k-pie to the final link might work, give it a try.
Thank you for telling me a new method to make the executable which is PIE.

dbannon

  • Hero Member
  • *****
  • Posts: 3018
    • tomboy-ng, a rewrite of the classic Tomboy
My app has been 'PIE' in Debian for several years. I don't do it to the binaries I compile and ship myself because of a measurable (but not really noticeable) slow down. But Debian demand it.

I don't think its really necessary on an app that is used on a personal desktop, most certainly is necessary on a shared system or server. But my app is hardly likely to be running on such as system.

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

Thaddy

  • Hero Member
  • *****
  • Posts: 15531
  • Censorship about opinions does not belong here.
It needs both -Cg and -k-pie, but indeed it works like a charm.
Examined with readelf -d -r <executable name>
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

 

TinyPortal © 2005-2018