This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Make ihex writer similar to binary writer
ClosedPublic

Authored by MaskRay on Jun 12 2021, 12:50 PM.

Details

Summary

There is no need to differentiate whether UseSegments is true or
false. Unifying the cases makes the behavior closer to BinaryWriter.

This improves compatibility with objcopy because SHF_ALLOC sections not in
a PT_LOAD will not be skipped. Such cases are usually erroneous input, though.

Diff Detail

Event Timeline

MaskRay created this revision.Jun 12 2021, 12:50 PM
MaskRay requested review of this revision.Jun 12 2021, 12:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2021, 12:50 PM

Just trying to follow the logic through. I think there is a potential behaviour change, which may be fine, but I just want to highlight it to see what others think (I have no use for IHEX myself, so don't feel like I can make a completely fair judgment either way). If I follow it correctly, if a writable section were not in a PT_LOAD segment, then previously it was skipped, if there was at least one writable section that was in such a segment, whereas now it won't be skipped. This is probably harmless (all such sections should have been placed in a segment anyway). Assuming I'm right, should we have a test-case to illustrate this behaviour change?

Just trying to follow the logic through. I think there is a potential behaviour change, which may be fine, but I just want to highlight it to see what others think (I have no use for IHEX myself, so don't feel like I can make a completely fair judgment either way). If I follow it correctly, if a writable section were not in a PT_LOAD segment, then previously it was skipped, if there was at least one writable section that was in such a segment, whereas now it won't be skipped. This is probably harmless (all such sections should have been placed in a segment anyway). Assuming I'm right, should we have a test-case to illustrate this behaviour change?

I think the coverage value is low. SHF_WRITE sections should have the SHF_ALLOC flag and be in a PT_LOAD segment. If not, that looks like an odd case. Not sure such case does arise for ihex users.

mciantyre added a comment.EditedJun 15 2021, 6:27 PM

if a writable section were not in a PT_LOAD segment, then previously it was skipped, if there was at least one writable section that was in such a segment, whereas now it won't be skipped.

We can manually demonstrate this by adding SHF_ALLOC to the .dummy section's flags in ihex-elf-segments.yaml. The .dummy section is intentionally excluded from the segment in that test. As of this patch, when .dummy is SHF_ALLOC, we'll write the section's contents even though its not part of a segment.

GNU objcopy always emits data-containing sections in IHEX output, even if the section is not part of a segment. If meeting parity with GNU objcopy is a goal, this patch makes LLVM objcopy behave similarly. We can check GNU objcopy with the ihex-elf-segments.yaml output, when .dummy is SHF_ALLOC. I tested this with GNU objcopy 2.36.1.

MaskRay updated this revision to Diff 352319.Jun 15 2021, 7:03 PM
MaskRay edited the summary of this revision. (Show Details)

add a test

This revision is now accepted and ready to land.Jun 16 2021, 12:27 AM
This revision was landed with ongoing or failed builds.Jun 16 2021, 10:08 AM
This revision was automatically updated to reflect the committed changes.