Fix alignment issue in D34020, by aligning all sections to 8 bytes.
Details
Diff Detail
Event Timeline
llvm/lib/Object/WindowsResource.cpp | ||
---|---|---|
511 ↗ | (On Diff #102098) | Do you have to memorize how large was a padding? I mean you may be able to do this. Current = alignTo(Current, 8) |
llvm/lib/Object/WindowsResource.cpp | ||
---|---|---|
511 ↗ | (On Diff #102098) | Hmm doesn't that depend on the way the loader aligns cvtres in memory? For example, it could be possible for the system to align the FileOutputBuffer on 4 bytes instead of 8 bytes. So aligning to 8 bytes would actually be aligning to 4 bytes. |
llvm/lib/Object/WindowsResource.cpp | ||
---|---|---|
511 ↗ | (On Diff #102098) | Not sure I follow your comment here. If the system aligns the FileOutputBuffer to 4 bytes (let's be explicit and say it puts it at address 4), and you call Current = alignTo(Current, 8) then after that call Current will be equal to 8, which is what you want, isn't it? Seems to me like calling X = OffsetToAlignment(Number, Align) Number += X; is mathematically equivalent to: Number = alignTo(Number, Align); |
llvm/lib/Object/WindowsResource.cpp | ||
---|---|---|
511 ↗ | (On Diff #102098) | No....this won't be what we want to do. The end goal is to have the final COFF file be aligned on 8 bytes. Therefore, we want to align with 8 bytes relative to the FileOutputBuffer base address, without regard to the buffer starting alignment. If the address of the buffer starts at 4 and then we say |
So you're aligning the offset, not the absolute address. In that it might be more intuitive to isntead of storing Current, which is actually a pointer, to store Base and Offset separately, and only operate on (and align) Offset, then compute Base+Offset every time you want to write?
I think you might have gotten this patch combined with the other patch, because now there are a lot of unrelated changes showing up. regardless, lgtm with the new change, but please separate them out again before committing.
The last diff incorrectly grouped this patch together with the testing infrastructure patch (D34047)
llvm/trunk/lib/Object/WindowsResource.cpp | ||
---|---|---|
35 | static? The following two constants are not ALL_IN_UPPERCAPS, but this is. Since it is not a CPP macro or something, this should be SectionAlignment. Also, why sizeof(uint64_t) instead of just 8? | |
469 | It is better to increment CurrentOffset in a function that writes something rather than incrementing it in a function that is called after you write it. So move this to writeCOFFHeader. | |
601–603 | write32le(BufferStart + CurrentOffset, 0); |
static?
The following two constants are not ALL_IN_UPPERCAPS, but this is. Since it is not a CPP macro or something, this should be SectionAlignment.
Also, why sizeof(uint64_t) instead of just 8?