-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfault on FPC when FPC_REQUIRES_PROPER_ALIGNMENT is enabled #251
Comments
Regexpr.pas has several usages of that define, e.g.
please help to correct the code inside, as I don't know how to do that. |
I don’t have aarch64 hardware so cannot help. |
I don't know exactly what the code is trying to do.... I only had a very quick look at it / not much time... Line 899 in c022def
Lines 2263 to 2264 in c022def
So the 2nd bit of code does the following.
So then
Now, for that bit of code, I would guess (and really guess, as I have not looked beyond those few lines), that it should be and should modify p, to the same as the result. There may be more issues like the one above.... |
If you only do aligns as the above -> that is align individual values in an allocated memory block/stream -> try forcing FPC_REQUIRES_PROPER_ALIGNMENT on for your test build. Howewer if you do stuff like
So you try to match the mem layout of a compiled in record, then you can not force it on. Because the record will still be unaligned on your test system. Instead do
|
I guess you are right, but I don't have the aarch64 hardware to test this. |
I have a VM running macOS 11 on aarch64, with FPC/Lazarus installed. I can give you SSH and RDP access to that machine. Would you be willing to take a look at this issue? |
@Alexey-T Just compile the code with -dFPC_REQUIRES_PROPER_ALIGNMENT (force it on). And then fix the issues on intel/amd. (Search does not show any "matching inside a record" aligns, so that should work) At least that will catch the issue I described. |
Now I have the aarch64 hardware. Ok, but what is this?
I added {$undef FPC_REQUIRES_PROPER_ALIGNMENT} @User4martin Do you know why it works? |
I posted the pull req which undefines that word. |
AArch64 permits unaligned access to regular memory, so technically FPC_REQUIRES_PROPER_ALIGNMENT does not need to be defined at all. This is documented on ARM's website and mentioned in this discussion. So locally undefining FPC_REQUIRES_PROPER_ALIGNMENT for RegExpr will make it work on AArch64. Having said that, on any platform that does not permit unaligned access RegExpr may not work regardless of this change. That would be some minor/unpopular CPUs. |
Let’s keep this opened until I find the hardware (which requires aligned access)... |
Thanks for the great library.
I just wanted to point out an issue on platforms for which FPC defines FPC_REQUIRES_PROPER_ALIGNMENT. In my case I am using TRegExpr on macOS with FPC.
When compiling for macOS x86_64 FPC_REQUIRES_PROPER_ALIGNMENT is not defined and TRegExpr works fine.
When compiling for macOS aarch64 FPC_REQUIRES_PROPER_ALIGNMENT is defined, which makes TRegExpr use pointer alignment. The following code causes a segfault:
I can work around this by undefining FPC_REQUIRES_PROPER_ALIGNMENT, so TRegExpr will not align pointers for aarch64. It works, but to the best of my knowledge when FPC_REQUIRES_PROPER_ALIGNMENT is defined, pointers should be aligned.
Therefore, there seems to be a bug in TRegExpr on platforms that require aligned pointers.
The text was updated successfully, but these errors were encountered: