This is an archive of the discontinued LLVM Phabricator instance.

[AVR][MC] Add ELF flag 'EF_AVR_LINKRELAX_PREPARED' to OBJ files
ClosedPublic

Authored by benshi001 on Feb 22 2023, 11:10 PM.

Details

Summary

This is in accordance with avr-gcc, even '-mno-relax' is specified
to avr-gcc, this flag will also be added to the output relocatables.

Diff Detail

Event Timeline

benshi001 created this revision.Feb 22 2023, 11:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2023, 11:10 PM
benshi001 requested review of this revision.Feb 22 2023, 11:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2023, 11:10 PM
benshi001 added inline comments.Feb 22 2023, 11:11 PM
llvm/test/MC/AVR/elf_header.s
71

This is the newly added ELF flag.

benshi001 added a reviewer: MaskRay.

I'm concerned of this change. Do you intend to add linker relaxation to lld/ELF's AVR port? Implementing features is indeed fun but I am unsure whether the use case has a sufficient demand of the feature.
RISC-V linker relaxation has greatly increased code complexity and LoongArch folks want to copy that. I don't want to see a third arch which may use a non-recommended way implementing linker relaxation.

I'm concerned of this change. Do you intend to add linker relaxation to lld/ELF's AVR port? Implementing features is indeed fun but I am unsure whether the use case has a sufficient demand of the feature.
RISC-V linker relaxation has greatly increased code complexity and LoongArch folks want to copy that. I don't want to see a third arch which may use a non-recommended way implementing linker relaxation.

I have no plan for adding linker relaxation to lld/ELF's AVR port, at least, you can deny that if you think it introduces complexity to lld.

However, avr-ld indeed has already implemented linker relaxation, my current patch can make use of it, and clang+avr-ld can generate shorter assembly.

I think we should understand what this flag does and how it affects assemblers/linkers.
If it does not cause behavior difference, I am unsure we should add it.

I think we should understand what this flag does and how it affects assemblers/linkers.
If it does not cause behavior difference, I am unsure we should add it.

This flag does cause difference behavior of gnu ld. With this flag added and --relax specified to gnu-ld, the gnu-ld will optimize long call (4-byte instruction) to short call (2-byte instruction), otherwise either this flag or --relax is absent, gnu-ld will not do the long call to short call optimization.

benshi001 added a comment.EditedFeb 23 2023, 5:27 PM

I think we should understand what this flag does and how it affects assemblers/linkers.
If it does not cause behavior difference, I am unsure we should add it.

This is how gnu ld perform linker relaxation for AVR
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf32-avr.c;h=702719136d09acbc8c98ec49ab8129d0f33fffa8;hb=6777dece58127236db900215857f9070ad63e0bf#l2423

We can see this flag EF_AVR_LINKRELAX_PREPARED does affect
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf32-avr.c;h=702719136d09acbc8c98ec49ab8129d0f33fffa8;hb=6777dece58127236db900215857f9070ad63e0bf#l2533

The gnu ld will optimize long call (absolute address) to short call (PC relative address) only if this flag is set. (Of course --relax must also be specified.)

MaskRay accepted this revision.Feb 23 2023, 6:53 PM

I think we should understand what this flag does and how it affects assemblers/linkers.
If it does not cause behavior difference, I am unsure we should add it.

This is how gnu ld perform linker relaxation for AVR
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf32-avr.c;h=702719136d09acbc8c98ec49ab8129d0f33fffa8;hb=6777dece58127236db900215857f9070ad63e0bf#l2423

We can see this flag EF_AVR_LINKRELAX_PREPARED does affect
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf32-avr.c;h=702719136d09acbc8c98ec49ab8129d0f33fffa8;hb=6777dece58127236db900215857f9070ad63e0bf#l2533

The gnu ld will optimize long call (absolute address) to short call (PC relative address) only if this flag is set. (Of course --relax must also be specified.)

s/gnu ld/GNU ld/. Change the summary to say that it affects GNU ld.

This revision is now accepted and ready to land.Feb 23 2023, 6:53 PM

I think we should understand what this flag does and how it affects assemblers/linkers.
If it does not cause behavior difference, I am unsure we should add it.

This is how gnu ld perform linker relaxation for AVR
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf32-avr.c;h=702719136d09acbc8c98ec49ab8129d0f33fffa8;hb=6777dece58127236db900215857f9070ad63e0bf#l2423

We can see this flag EF_AVR_LINKRELAX_PREPARED does affect
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf32-avr.c;h=702719136d09acbc8c98ec49ab8129d0f33fffa8;hb=6777dece58127236db900215857f9070ad63e0bf#l2533

The gnu ld will optimize long call (absolute address) to short call (PC relative address) only if this flag is set. (Of course --relax must also be specified.)

s/gnu ld/GNU ld/. Change the summary to say that it affects GNU ld.

Thanks for your comment. I will update my commit message when committing.

The commit has Reviewed By: MaskRay, jacquesguan, aykevl but @jacquesguan/@aykevl haven't signed off on the patch so it should just have my username :)

If you use arc amend (https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-command-line), Reviewed By: will be added correctly.