Handle non-ELF input for x86-64 common definition.
Fixes a segfault in x86-64 common symbol definition when encountering non-ELF input.
This change prevents a segmentation fault in the x86-64 linker when processing non-ELF input. Previously, elf_x86_64_common_definition would crash if the input file was not in ELF format. The fix ensures that the linker returns SHN_COMMON for non-ELF input, leading to an assertion failure in bfd/coffgen.c instead of a crash, thereby improving stability.
In Details
The elf_x86_64_common_definition function, which determines the section index for common symbols, previously lacked checks for the BFD target flavour. This commit adds a check to ensure the input is ELF formatted before proceeding, preventing a segfault when processing non-ELF files like PE executables. The fallback is to return SHN_COMMON, aligning with expected behavior for such inputs and triggering a more informative assertion failure elsewhere.
- SHN_COMMON
- A special section number in the ELF file format that indicates a common symbol. Common symbols are uninitialized variables that are allocated storage by the linker.
- ELF
- Executable and Linkable Format. A standard file format for object files, executables, shared libraries, and core dumps on many Unix-like systems.
- PE
- Portable Executable. The file format used for executables, DLLs, and object code in Windows operating systems. This commit also affects binutils' handling of PE files.
- Segfault
- A segmentation fault is an error that occurs when a program attempts to access a memory location that it is not allowed to access, often resulting in the program's termination.