binutils-gdb/ld/testsuite/ld-avr
Senthil Kumar Selvaraj b660e9eb7a Fix PR21404 - assertion fail when calculating symbol size
Fix a host of problems related to adjustment of
symbol values and sizes when relaxing for avr.

1. Adjust symbol size first before adjusting symbol
value. Otherwise, a symbol whose value just got adjusted to the
relaxed address also ends up getting resized. See pr21404-1.s.

2. Reduce symbol sizes only if their span is below an
alignment boundary. Otherwise, the size gets decremented once when the
actual instruction is relaxed and padding bytes are added, and again
when the padding bytes are deleted (if padding ends up being unnecessary).
pr21404-2.s addresses that, and this bug is really the root cause of PR21404.

3. Adjust all symbol values before an alignment boundary.
Previous code did not adjust symbol values if they fell in the
would-be padded area, resulting in incorrect symbol values in some
cases (see pr21404-3.s).

4. Increase symbol sizes if alignment directives require so.
As pr21404-4.s shows
.global nonzero_sym
L1:
    jmp  L1
nonzero_sym:
    nop
    nop
    .p2align 2
.size nonzero_sym, .-nonzero_sym

The two nops satisfy the 4 byte alignment at assembly time and
therefore the size of nonzero_sym is 4. Relaxation shortens
the 4 byte jmp to a 2 byte rjmp, and to satisfy 4 byte alignment
the code places 2 extra padding bytes after the nops, increasing
nonzero_sym's size by 2. This wasn't handled before.

If the assembly code does not have any align directives, then the
boundary is the section size, and symbol values and sizes == boundary
should also get adjusted. To handle that case, add a did_pad variable
and use that to determine whether it should use < boundary or <= boundary.

Also get rid of reloc_toaddr, which is now redundant.  toaddr is now not
adjusted to handle the above case - the newly added
did_pad variable does the job.

pr21404-{5,6,7,8} are the same testcases written for local symbols, as
the code handles them slightly differently.
2017-05-04 10:34:29 +05:30
..
avr-prop-1.d
avr-prop-1.s
avr-prop-2.d
avr-prop-2.s
avr-prop-3.d
avr-prop-3.s
avr-prop-4.d
avr-prop-4.s
avr-prop-5.d
avr-prop-5.s
avr-prop-6.d
avr-prop-6.s
avr-prop-7.d
avr-prop-7.s
avr-prop-8.d
avr-prop-8.s
avr.exp
gc-section-debugline.d
lds-mega.d
lds-mega.s
lds-tiny.d
lds-tiny.s
norelax_diff.d
per-function-debugline.s
pr20789.d
pr20789.s
pr21404-1.d
pr21404-1.s
pr21404-2.d
pr21404-2.s
pr21404-3.d
pr21404-3.s
pr21404-4.d
pr21404-4.s
pr21404-5.d
pr21404-5.s
pr21404-6.d
pr21404-6.s
pr21404-7.d
pr21404-7.s
pr21404-8.d
pr21404-8.s
region_overflow.d
region_overflow.s
relax_diff.d
relax-02.d
relax-02.s
relax-03.d
relax-03.s
relax-elf-flags-01.d
relax-elf-flags-02.d
relax-elf-flags-03.d
relax-elf-flags-04.d
relax-elf-flags-05.d
relax-elf-flags-06.d
relax-elf-flags-07.d
relax-elf-flags-08.d
relax-elf-flags-a.s
relax-elf-flags-b.s
relax.s