alpha: allocate .got contents after relaxation has sized them

elf64_alpha_early_size_sections sizes and merges the .got subsections and
then allocates each one's contents buffer.  elf64_alpha_relax_section runs
afterwards and calls elf64_alpha_size_got_sections again with may_merge
true.  That re-merge zeroes and recomputes every subsection size, and it
can make a subsection larger than it was when its buffer was allocated.
The comment there asserts that "relaxation only shrinks the table", which
is true of the table as a whole but not of an individual subsection: a
merge moves entries into one subsection and empties another.

Relaxation is not limited to --relax links.  ld/emultempl/alphaelf.em
enables it for -O as well, so an ordinary distribution build using
-Wl,-O1 takes this path.

When a subsection grows, elf64_alpha_relocate_section writes GOT slots past
the end of the allocated buffer, corrupting whatever objalloc placed after
it.  Linking a large C++ shared library with -Bsymbolic or
-Bsymbolic-functions aborts ld with a glibc "free(): invalid next size", or
produces a library whose .rela.dyn is corrupt and which faults at run time
with a GOT slot holding an unrelated pointer.  In one instance a .got
allocated at 57664 bytes grew to 64840, still under the 64K cap so nothing
diagnosed it, and 1796 slot writes fell outside the buffer.

Rather than resizing the buffers whenever relaxation re-runs the sizing,
which would throw away the previous allocation on every relaxation trip,
allocate them once from elf64_alpha_final_link, by which point the sizes
have settled.  Nothing reads or writes the got before then.

The .got subsection of the dynobj was allocated a second time by
elf64_alpha_late_size_sections, along with the real dynamic sections; that
allocation has the same problem and is dropped too.  The other sections
that loop walks are only shrunk by relaxation, so the space allocated for
them there stays big enough.

Route the got slot writes through a new alpha_got_slot, which asserts that
the subsection has had its contents allocated and that the slot lies inside
it.  The assertions do not prevent the write, but they turn a future sizing
mistake of this kind into a reported one rather than a silent overrun.

The test needs the two subsections to be unmergeable when they are first
sized and mergeable once relaxation has dropped some entries, so it pairs
an object holding 8000 entries against preemptible symbols with one whose
250 entries include 150 that relaxation removes.  Without the fix it
reproduces both symptoms: the assertion fires and glibc aborts the link.

	* elf64-alpha.c (alpha_got_slot): New function.
	(elf64_alpha_early_size_sections): Don't allocate the .got
	subsection contents here.
	(elf64_alpha_late_size_sections): Don't allocate .got here either.
	(elf64_alpha_relax_section): Correct stale comment.
	(elf64_alpha_final_link): Allocate the .got subsection contents.
	(elf64_alpha_relocate_section): Use alpha_got_slot.
	(elf64_alpha_finish_dynamic_symbol): Likewise.

ld/
	* testsuite/ld-alpha/got-realloc-a.s: New test.
	* testsuite/ld-alpha/got-realloc-b.s: New test.
	* testsuite/ld-alpha/got-realloc.rd: New test.
	* testsuite/ld-alpha/alpha.exp: Run it.
5 files changed