[fpc-devel] Some questions about compiler work on x86_64-win64
Sven Barth
pascaldragon at googlemail.com
Fri Mar 17 23:51:05 CET 2017
Am 17.03.2017 22:16 schrieb "Bishop" <cat_shtaer at rambler.ru>:
>
> 03/17/17 11:56:47, Sven Barth via fpc-devel <
fpc-devel at lists.freepascal.org>:
>
> >> 1) EXE-file contained .CRT section. As i understand it contained one
pointer to _FPC_Tls_Callback functions from RTL. Is it used only for this?
> > Correct.
> And main sence of this function is allocated ThreadVar regions for
thread, than was created in initialization code of DLL`s that was loaded
staticaly (OS load them use information in .idata section)?
Bo, the main sense of this is to detect when a new thread is started and
more importantly terminated cause only with this we can free the threadvar
area of the thread accordingly (if the thread is an external one, not one
started using BeginThread or TThread).
>
> > It probably should be .rdata, but I think that older binutils had
problems with that, thus they were put into .data and that was never
changed till now...
> So now it is possible to change it? Plus what about 2nd part of my
question?
>
>
> >Or even possible it must be evicted and replace just with call
instructions? I mean autogeneration of fpc_InitializeUnits and
fpc_FinalizeUnits?
> What reason for we need so strange init/final unit function calling
solution? Autogenerated functions will take less space (direct or
RIP-related address - all functions in same segment), safer than varible in
w/r segment (this is a way to make some atack on application) and faster.
Why *should* it be auto generated if one can use a table and let the RTL do
the rest.
Also with the addition of dynamic packages this will move even more towards
a table based approach.
>
> > I might remember it incorrectly, but I think that Microsoft says that
all accesses should be RIP relative to reduce the need for relocations.
> But EXE generated by FPC dont ASLR aware. This have no needed flags in
EXE file header (I use VMMap to get info about process and it show ASLR
modules). Windows support both type of executable (i dont say about DLL in
this time). Static and ASLR. I think it will be logicaly if FPC can
generate both type of applications (it already have flags for PIC and
RIP-related addressing is a good form of PIC realization). Plus on Linux we
have picture like it. Main binary can be PIC or not-PIC. SO-libraries can
be only PIC (that logicaly because they need relocation, that exe-file can
avoid).
But you can set the corresponding PE flag for ASLR using $SetPEOpts (or
so). No recompilation needed in that case.
Microsoft recommended that approach for Win64 so why should we do the work
and implement it differently even if ASLR isn't enabled by default for FPC
executables?
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20170317/8eb1a017/attachment.html>
More information about the fpc-devel
mailing list