Skip to content
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

memory alignment issues #704

Open
cctv130 opened this issue Mar 11, 2024 · 7 comments
Open

memory alignment issues #704

cctv130 opened this issue Mar 11, 2024 · 7 comments

Comments

@cctv130
Copy link
Contributor

cctv130 commented Mar 11, 2024

311718034-ab4ab888-c596-4071-a9d1-fa3d2cd0b88a

There should be a problem with this piece of code. kEightyBitsInBytes should not be equal to 10. Modify this constant to equal 16. Although it is equal to 10 after the compiler is packed on Linux, it is equal to 16 on Windows and remove the attribute of the structure. ((packed)) attribute, so that struct will not have memory alignment operations, union will have memory alignment operations, and both windows and linux will display 16 bytes. On the linux platform, long double occupies 16 bytes, so modify kEightyBitsInBytes=16 is more appropriate, so that we can simulate long double even if Xclang pf80 is enabled on windows. I don't know if my verification is correct, please give your opinion.
There is also a compiled version for Windows, you can test it when you have time.
https://github.com/lifting-bits/remill/files/14559396/remill-lift-17.zip
https://godbolt.org/z/8Tfc7eEhW

311725799-7d02e48b-b14f-4975-97bb-9340414d0783

@pgoodman
Copy link
Collaborator

Is the problem that __attribute__((packed)) does no achieve the desired result of making it 10 bytes in size? The union_ld data structure exists to access fp80 values regardless of padding. It seems as though you've found an issue where our intent (float80_t being 10 bytes) does not match the reality.

@cctv130
Copy link
Contributor Author

cctv130 commented Mar 11, 2024

@pgoodman Yes, Linux's longdouble = 16 bytes, but linux nan80_t in math.h outputs 10 bytes after attribute((packed)). I tested it on Windows and it outputs 16 bytes. If Windows also outputs 10 bytes, then attribute((packed)) makes sense.

@pgoodman
Copy link
Collaborator

Does #pragma pack(push) and #pragma pack(pop) resolve this problem?

@cctv130
Copy link
Contributor Author

cctv130 commented Mar 11, 2024

1710199692713

@cctv130
Copy link
Contributor Author

cctv130 commented Mar 11, 2024

@pgoodman If want to align to 10 bytes on windows might want to enable a flag bit like gcc_bitfield in llvm,But this flag bit does not appear to exist at the moment

@cctv130
Copy link
Contributor Author

cctv130 commented Mar 11, 2024

@pgoodman You can use a virtual machine to test the exe I compiled to see if there is any problem with the output ir

@thug-shaker

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants