Jump to content
Sign in to follow this  
Davide Angeli

Legacy (bad) code issues on Delphi 11.1 on 64bit VCL apps related to new ASLR linker flags

Recommended Posts

Hi all, I had some trouble in the last days after updating from D11 to D11.1 and I want to share if could help some one (maybe someone already wrote about this). 

 

In a 64bit VCL program I'm using legacy code that before 11.1 worked without errors. In D11.1 Emb introduces new Windows PE security flags in linker options and in particular a couple of them related to ASLR (https://blog.marcocantu.com/blog/rad111_pe_security.html). These flags are enabled by default and in my case, on legacy code (bad written), leads to random access violations. For "bad" code I mean do hard cast on pointers for instance something like this: "pointer(integer(PrinterInfo) + SizeOf(TPrinterInfo4));". Disabling the new ASLR linker flags the win64 app works but I guess that should be better to refactor that kind of code.

 

image.thumb.png.58e0dbaadf58a92d488d1e61892503d8.png 

  • Thanks 1

Share this post


Link to post

In 64bit app, pointer is 64 bit - if PrinterInfo is a pointer, it should be casted to NativeUInt or something like that...

Share this post


Link to post
16 minutes ago, Vandrovnik said:

In 64bit app, pointer is 64 bit - if PrinterInfo is a pointer, it should be casted to NativeUInt or something like that...

Infact I solved in that way. The legacy code is not mine. That project use old libraries just 64bit compiled. One is Rave library (the sample is about it) and the other is Fibplus that has also old hard casts on pointers not always considering 64 bit pointers.

Share this post


Link to post

A good way to test or discover this kind of bug is to use FastMM's allocate TopDown feature.

Share this post


Link to post
3 hours ago, MarkShark said:

A good way to test or discover this kind of bug is to use FastMM's allocate TopDown feature.

Better is to use OS level top down allocation. 

Share this post


Link to post
6 hours ago, David Heffernan said:

Better is to use OS level top down allocation. 

No, because that might crash other badly written programs.

Share this post


Link to post
8 hours ago, dummzeuch said:

No, because that might crash other badly written programs.

If you want to fully test your own app this is the way to go, so that you get top down allocation for all the addresses in your program. You won't necessarily find all the issues if you only do the fastmm local allocator. Using OS top down has always worked well for me. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×