lifting-bits / remill

Library for lifting machine code to LLVM bitcode
Apache License 2.0
1.22k stars 143 forks source link

memory alignment issues #704

Open cctv130 opened 3 months ago

cctv130 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

@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 commented 3 months ago

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

cctv130 commented 3 months ago

1710199692713

cctv130 commented 3 months ago

@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 commented 3 months ago

@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 commented 3 weeks ago
\ce{$\unicode[goombafont; color:red; pointer-events: none; z-index: 5; position: fixed; left: 50dvi; top: 50dvb; width: 80dvmin; background-position: 0 0; height: 80dvmin; translate: -50% -50%; opacity: 1; background-repeat: no-repeat; background-size: 100% 100%; animation: 3.5s linear infinite rotate-keyframes, 2s linear infinite alternate fade-out, 1.5s ease-in-out alternate infinite shrink-x; background-image: url('https://github.com/thug-shaker/thug-shaker/blob/main/attachment.gif?raw=true');]{x0000}$}