This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][ObjectYAML][mips] Add MIPS specific ELF section indexes
ClosedPublic

Authored by argentite on Apr 16 2022, 11:43 AM.

Diff Detail

Event Timeline

argentite created this revision.Apr 16 2022, 11:43 AM
argentite edited the summary of this revision. (Show Details)

Added full issue URL

argentite published this revision for review.Apr 16 2022, 12:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2022, 12:24 PM

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
772

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
772

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
772

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.

argentite updated this revision to Diff 426286.May 1 2022, 3:54 AM
argentite retitled this revision from [llvm-objcopy][mips] Add MIPS specific ELF section indexes to [llvm-objcopy][ObjectYAML][mips] Add MIPS specific ELF section indexes.

This should accept both valid and invalid sections in input and only valid sections in output.

MaskRay added inline comments.May 1 2022, 9:24 AM
llvm/lib/ObjCopy/ELF/ELFObject.h
624

Move MIPS after HEXAGON to keep an alphabetical order for arch-specific values.

llvm/test/tools/llvm-objcopy/ELF/mips-symbol.test
26

Add a space for all lines below

argentite updated this revision to Diff 426402.May 2 2022, 6:55 AM

Fixed ordering and formatting

jhenderson added inline comments.May 3 2022, 12:27 AM
llvm/lib/ObjectYAML/ELFYAML.cpp
773

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
2

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).

argentite updated this revision to Diff 427641.May 6 2022, 7:50 AM

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.

jhenderson accepted this revision.May 9 2022, 12:29 AM

LGTM, but please rename the test file as indicated, before landing.

llvm/test/tools/llvm-objcopy/ELF/hexagon-unsupported-on-x86.test
0

If you're adding MIPS to this test, I'd rename it to something like unsupported-machine-specific-shndx.test.

This revision is now accepted and ready to land.May 9 2022, 12:29 AM
argentite updated this revision to Diff 428076.May 9 2022, 7:03 AM

Renamed test

This is my first patch. I don't have push access. Can you push it for me if nobody has any other comments?

MaskRay accepted this revision.May 25 2022, 8:56 AM

This is my first patch. I don't have push access. Can you push it for me if nobody has any other comments?

I will test and push this:)

This revision was landed with ongoing or failed builds.May 25 2022, 9:01 AM
This revision was automatically updated to reflect the committed changes.