alpha: initialize every field of a new got entry
Initialize all fields of GOT entries, especially flags and plt_offset, to prevent errors.
This patch addresses an initialization issue in the alpha ELF linker where newly allocated GOT (Global Offset Table) entries were not fully initialized, specifically their flags and plt_offset fields. This oversight, found via Valgrind, could lead to incorrect behavior when merging GOT entries or when handling TLS relocations. By using bfd_zalloc to zero-initialize the entries and explicitly assigning only non-zero initial values, the patch ensures all fields are properly set, preventing potential bugs.
In Details
This patch corrects the allocation of alpha_elf_got_entry structures in bfd/elf64-alpha.c. Previously, bfd_alloc was used, leaving fields like flags uninitialized. This could lead to incorrect merging of GOT entries in elf64_alpha_merge_gots or issues in elf64_alpha_relax_tls_get_addr when plt_offset was unexpectedly non-zero. The change replaces bfd_alloc with bfd_zalloc and adjusts assignments to ensure all necessary fields, especially flags, are correctly initialized to zero by default, with only explicitly needed values being set afterwards.
- GOT
- Global Offset Table. A data structure used in position-independent code to hold addresses of global variables and functions, allowing indirect access.
- ELF
- Executable and Linkable Format. A standard file format for executables, object code, shared libraries, and core dumps, commonly used on Unix-like systems.
- relocation
- A process performed by the linker to adjust symbolic references (like function calls or variable accesses) in object code to their final memory addresses in the executable or shared library.
- TLS
- Thread-Local Storage. A mechanism that allows variables to have distinct values for each thread.
- Valgrind
- A debugging and profiling tool suite for Linux and macOS, used here to detect memory management errors.