This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF][AVR] Propagate ELF flags to the linked image
ClosedPublic

Authored by LemonBoy on Apr 1 2021, 11:13 AM.

Details

Summary

The e_flags for a ELF file targeting the AVR ISA contains two fields at the time of writing:

  • A 7-bit integer field specifying the ISA revision being targeted
  • A 1-bit flag specifying whether the object files being linked are suited for applying the relaxations at link time

The linked ELF file is blessed with the arch revision shared among all the files.
The behaviour in case of mismatch is purposefully different than the one implemented in libbfd: LLD will raise a fatal error while libbfd silently picks a default value of avr2.
The relaxation-ready flag is handled as done by libbfd, in order for it to appear in the linked object every source object must be tagged with it.

Diff Detail

Event Timeline

LemonBoy created this revision.Apr 1 2021, 11:13 AM
LemonBoy requested review of this revision.Apr 1 2021, 11:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2021, 11:13 AM
LemonBoy updated this revision to Diff 335896.Apr 7 2021, 12:01 PM

Ping (& fix one small style issue pointed out by clang-tidy)

llvm/BinaryFormat/ELF.h is typically added along with tests to llvm-readobj/yaml2obj/obj2yaml. See D95728 for an example.

lld/ELF/Arch/AVR.cpp
213

The code style does not tend to insert so many empty lines.

llvm/BinaryFormat/ELF.h is typically added along with tests to llvm-readobj/yaml2obj/obj2yaml. See D95728 for an example.

Apologies for the missing tests, I've just realized I forgot to git add them before sending out the patch.
This said I'm not using yaml2obj to generate the test cases but I see that's a better strategy than using llvm-mc, I'll patch the tools (and ELF.h) in a separate preparatory patch.

I think assembly tests in fine in lld/test/ELF and they typically improve readability. yaml2obj tests tend to be verbose.

If you look at my SHF_GNU_RETAIN change or earlier contributions, I usually organize features in three patches:

  • BinaryFormat/ELF.h yaml2obj/obj2yaml/llvm-readobj
  • llvm-mc and tests in llvm/test/MC
  • lld/ELF
LemonBoy updated this revision to Diff 336650.Apr 11 2021, 3:26 AM

Clean up. To be applied on top of D100250.

LemonBoy updated this revision to Diff 337748.Apr 15 2021, 7:01 AM

Rebase to kick off the automatic builds.

MaskRay accepted this revision.Apr 15 2021, 10:25 PM
MaskRay added inline comments.
lld/test/ELF/avr-flags.s
9

Newer tests use ;; for non-CHECK non-RUN comments.

11

See some newer tests where error: is always added.

This revision is now accepted and ready to land.Apr 15 2021, 10:25 PM
LemonBoy updated this revision to Diff 338023.Apr 16 2021, 1:35 AM

Minor touch-ups for the test case.

This revision was landed with ongoing or failed builds.Apr 16 2021, 1:40 AM
This revision was automatically updated to reflect the committed changes.