This fixes https://github.com/llvm/llvm-project/issues/53998
and displays correct information in obj2yaml for SHN_MIPS_*
sections according to
https://refspecs.linuxfoundation.org/elf/mipsabi.pdf
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Could you add some testing, please? If you grep llvm/test for SHN_HEXAGON_SCOMMON, you'll find 3 tests that use it, and I imagine you'll want equivalent testing for your new values.
llvm/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
569–573 | Comments should start with a capital letter, as per the prevailing style in this file. | |
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
768 | This if isn't present for other machines (see the below Hexagon and AMDGPU values), and I'm not convinced we want it here. It is sometimes useful to be able to write YAML that uses one of these properties, but is not for MIPS. In this case, the value would be used, but it would be meaningless. |
Fix comment capitalization
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
---|---|---|
768 | Apologies if my understanding is incorrect but it seems like without the machine check, the first case matching the value will be shown in obj2yaml. Some of the values such as SHN_MIPS_SCOMMON and SHN_HEXAGON_SCOMMON_4 conflict with each other (0xff03), so whichever appears first in the code will be displayed (also leading to some test failures like tools/obj2yaml/ELF/special-symbol-indices.yaml). |
Your patch summary should probably have an [ObjectYAML] tag too, since it impacts more than just [llvm-objcopy].
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
---|---|---|
768 | If I'm not mistaken (it's been a while since I really dug into this code, so I could be), this piece of code is used for both obj2yaml and yaml2obj. We probably DO want it to work for yaml2obj, since there's no reason why it shouldn't, and it makes writing tests such as tools/llvm-objcopy/ELF/hexagon-unsupported-on-x86.test easier to write. I see your point about the other way around though: could you make the conditional also conditioned on it being the obj2yaml direction? If you do that, you should probably make a small follow-up patch to do the same for the AMDGPU and Hexagon values below, or this code will be left in an inconsistent state. |
This should accept both valid and invalid sections in input and only valid sections in output.
llvm/lib/ObjectYAML/ELFYAML.cpp | ||
---|---|---|
769 | I'd like to see test cases in yaml2obj and obj2yaml showing that the MIPS-specific values are understood under the right circumstances only. I think extending obj2yaml\ELF\special-symbol-indices.yaml should be a minimum for that. | |
llvm/test/tools/llvm-objcopy/ELF/mips-symbol.test | ||
1 ↗ | (On Diff #426402) | You may also wish to rename and extend llvm-objcopy\ELF\hexagon-unsupported-on-x86.test, or alternatively, modify this test to cover that case, by attempting the same run, but with a different value for the Machine field (you can use yaml2obj's -D option to parameterise the field without needing to duplicate the document). |
This handles the testing partially. I think it can only be properly done when the condition has been added for Hexagon and AMDGPU as well beacuse currently it falls back to Hexagon if MIPS does not match.
LGTM, but please rename the test file as indicated, before landing.
llvm/test/tools/llvm-objcopy/ELF/hexagon-unsupported-on-x86.test | ||
---|---|---|
1 ↗ | (On Diff #427641) | If you're adding MIPS to this test, I'd rename it to something like unsupported-machine-specific-shndx.test. |
This is my first patch. I don't have push access. Can you push it for me if nobody has any other comments?
Comments should start with a capital letter, as per the prevailing style in this file.