This is an archive of the discontinued LLVM Phabricator instance.

[ELFAttributeParser] Skip unknown vendor subsections.
ClosedPublic

Authored by simon_tatham on Jun 20 2023, 6:16 AM.

Details

Summary

An .ARM.attributes section is divided into subsections, each labelled
with a vendor name. There is one standardised vendor name, which must
be used for all attributes that affect compatibility. Subsections
labelled with other vendor names can be used for optimisation
purposes, but it has to be safe for an object file consumer to ignore
them if it doesn't recognise the vendor name.

LLD currently terminates parsing of the whole attributes section as
soon as it encounters a subsection with a vendor name it doesn't
recognise (which is anything other than the standard one). This can
prevent it from detecting compatibility issues, if a standard
subsection followed the vendor-specific one.

This patch modifies the attribute parser so that unrecognised vendor
subsections are silently skipped, and the subsections beyond them are
still processed.

Diff Detail

Event Timeline

simon_tatham created this revision.Jun 20 2023, 6:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2023, 6:16 AM
simon_tatham requested review of this revision.Jun 20 2023, 6:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2023, 6:16 AM

@HsiangKai, @zixuan-wu, @jozefl: I've included you as reviewers because you each added a use of ELFAttributeParser for an architecture other than Arm. Are your architectures' use of attributes OK with this change, or will it need to be conditionalized so that it only applies to the Arm case?

This looks correct to me. You may be able to reproduce the same behaviour with a more minimal yaml file.

A link to the relevant part of the Arm specification: https://github.com/ARM-software/abi-aa/blob/main/addenda32/addenda32.rst#325conformance-constraints . The compatibility is meant to be handled by https://github.com/ARM-software/abi-aa/blob/main/addenda32/addenda32.rst#3372generic-compatibility-tag

There is a list of registered vendors at https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#registered-vendor-names but I think on the general principle that the ABI doesn't require compatibility checks for this section then it isn't worth checking that the vendor be part of the registered list.

lld/test/ELF/Inputs/arm-vfp-arg-vfp-vendor.yaml
25

May be able to remove the .text section and have no effect on the test.

40

Could probably get away with removing this part.

Deleted unnecessary parts from the YAML input file (and, while I'm there, added a comment naming the test it's used by).

I think on the general principle that the ABI doesn't require compatibility checks for this section then it isn't worth checking that the vendor be part of the registered list.

Not to mention that it would require constant LLVM updates whenever the registered list changes!

simon_tatham marked 2 inline comments as done.Jun 20 2023, 8:06 AM
MaskRay added a comment.EditedJun 24 2023, 10:27 AM

Code looks good to me. For the test, GNU readelf gives a warning.

% readelf -A avfpvendor.o
Attribute Section: ShouldBeIgnored
readelf: Error: Bad subsection length (4294967295 > 12)
Unknown tag: 255
  Unknown attribute:
  0x00000000 ffffffff ffffff                     .......

Can we use llvm-mc -filetype=obj to construct the test? It will likely be more readable than the yaml file. Then just implement it as an extra file with split-file as well.

.section .ARM.attributes,""
...    // directives with comments
...
lld/test/ELF/Inputs/arm-vfp-arg-vfp-vendor.yaml
35

... is optional and can be removed.

Rewritten the test to use llvm-mc instead of yaml2obj.

For the test, GNU readelf gives a warning.

That seems like a bug in GNU readelf to me! It looks as if GNU readelf is expecting every subsection of .ARM.attributes to have the same structure as the standardized "aeabi" section: it's complaining here that my custom subsection with vendor="ShouldBeIgnored" is not divided into internal sub-subsections indicating file, section or symbol scope, but instead is full of nothing but FFFFFFFF padding.

But ADDENDA32 seems very clear on this: that internal structure is specific to "aeabi", and other vendors can define whatever format they like inside their own subsections. Of course some vendor subsections might choose to copy the "aeabi" internal structure, but they don't have to.

Can we use llvm-mc -filetype=obj to construct the test? It will likely be more readable than the yaml file.

I'd guessed that MC might try to write its own attributes section and fight with a manually specified one, but in fact, yes, that works fine and I agree it's more readable.

Then just implement it as an extra file with split-file as well.

I'm not sure about that. This particular test keeps its existing three sub-files in lld/test/ELF/Inputs. It would seem strange to use split-file for just this one extra one. Or do you mean you'd like me to reorganize the existing parts of the test while I'm here?

MaskRay accepted this revision.Jun 26 2023, 10:09 AM

Then just implement it as an extra file with split-file as well.

I'm not sure about that. This particular test keeps its existing three sub-files in lld/test/ELF/Inputs. It would seem strange to use split-file for just this one extra one. Or do you mean you'd like me to reorganize the existing parts of the test while I'm here?

The new file can

The existing llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o can be changed to a part of split-file.
Inputs/arm-vfp-arg-vfp-vendor.s can be added as the second part.
The existing 3 Inputs/arm-* files are also used by arm-tag-vfp-args-errs.s. We don't need to convert them.

This revision is now accepted and ready to land.Jun 26 2023, 10:09 AM

The existing 3 Inputs/arm-* files are also used by arm-tag-vfp-args-errs.s. We don't need to convert them.

Ah, that's the part I hadn't spotted. Thanks; I've made your suggested change in the final version of the patch.

This revision was landed with ongoing or failed builds.Jun 27 2023, 5:23 AM
This revision was automatically updated to reflect the committed changes.
hokein added a subscriber: hokein.Jun 27 2023, 5:42 AM

We seem to miss updating the unittest ELFAttributeParserTest.cpp, I landed a fix https://github.com/llvm/llvm-project/commit/975f71faa72aaaaf9c82b93a32bd428503722bbf.