binutils-gdb/ld/testsuite
H.J. Lu 50c95a739c x86: Propery check PC16 reloc overflow in 16-bit mode instructions
commit a7664973b2
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Apr 26 10:41:35 2021 +0200

    x86: correct overflow checking for 16-bit PC-relative relocs

caused linker failure when building 16-bit program in a 32-bit ELF
container.  Update GNU_PROPERTY_X86_FEATURE_2_USED with

 #define GNU_PROPERTY_X86_FEATURE_2_CODE16 (1U << 12)

to indicate that 16-bit mode instructions are used in the input object:

https://groups.google.com/g/x86-64-abi/c/UvvXWeHIGMA

to indicate that 16-bit mode instructions are used in the object to
allow linker to properly perform relocation overflow check for 16-bit
PC-relative relocations in 16-bit mode instructions.

1. Update x86 assembler to always generate the GNU property note with
GNU_PROPERTY_X86_FEATURE_2_CODE16 for .code16 in ELF object.
2. Update i386 and x86-64 linkers to use 16-bit PC16 relocations if
input object is marked with GNU_PROPERTY_X86_FEATURE_2_CODE16.

bfd/

	PR ld/27905
	* elf32-i386.c: Include "libiberty.h".
	(elf_howto_table): Add 16-bit R_386_PC16 entry.
	(elf_i386_rtype_to_howto): Add a BFD argument.  Use 16-bit
	R_386_PC16 if input has 16-bit mode instructions.
	(elf_i386_info_to_howto_rel): Update elf_i386_rtype_to_howto
	call.
	(elf_i386_tls_transition): Likewise.
	(elf_i386_relocate_section): Likewise.
	* elf64-x86-64.c (x86_64_elf_howto_table): Add 16-bit
	R_X86_64_PC16 entry.
	(elf_x86_64_rtype_to_howto): Use 16-bit R_X86_64_PC16 if input
	has 16-bit mode instructions.
	* elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Set
	elf_x86_has_code16 if relocatable input is marked with
	GNU_PROPERTY_X86_FEATURE_2_CODE16.
	* elfxx-x86.h (elf_x86_obj_tdata): Add has_code16.
	(elf_x86_has_code16): New.

binutils/

	PR ld/27905
	* readelf.c (decode_x86_feature_2): Support
	GNU_PROPERTY_X86_FEATURE_2_CODE16.

gas/

	PR ld/27905
	* config/tc-i386.c (set_code_flag): Update x86_feature_2_used
	with GNU_PROPERTY_X86_FEATURE_2_CODE16 for .code16 in ELF
	object.
	(set_16bit_gcc_code_flag): Likewise.
	(x86_cleanup): Always generate the GNU property note if
	x86_feature_2_used isn't 0.
	* testsuite/gas/i386/code16-2.d: New file.
	* testsuite/gas/i386/code16-2.s: Likewise.
	* testsuite/gas/i386/x86-64-code16-2.d: Likewise.
	* testsuite/gas/i386/i386.exp: Run code16-2 and x86-64-code16-2.

include/

	PR ld/27905
	* elf/common.h (GNU_PROPERTY_X86_FEATURE_2_CODE16): New.

ld/

	PR ld/27905
	* testsuite/ld-i386/code16.d: New file.
	* testsuite/ld-i386/code16.t: Likewise.
	* testsuite/ld-x86-64/code16.d: Likewise.
	* testsuite/ld-x86-64/code16.t: Likewise.
	* testsuite/ld-i386/i386.exp: Run code16.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2021-05-26 12:13:24 -07:00
..
config
ld-aarch64 Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-alpha Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-arc
ld-arm arm: fix fallout from recent thumb2 detection patch 2021-05-12 11:43:59 +01:00
ld-auto-import
ld-avr
ld-bootstrap ld: Properly create a symbolic link to tmpdir/ldscripts 2021-04-23 12:36:45 -07:00
ld-bpf
ld-cdtest
ld-checks
ld-cris Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-crx
ld-csky
ld-ctf libctf, ld: fix test results for upstream GCC 2021-05-06 09:31:31 +01:00
ld-cygwin
ld-d10v
ld-discard
ld-dynamic
ld-elf ld: Add -Bno-symbolic 2021-05-13 12:53:49 +09:30
ld-elfcomm
ld-elfvers
ld-elfvsb
ld-elfweak
ld-fastcall
ld-frv
ld-gc PE image base fallout 2021-03-12 10:41:34 +10:30
ld-h8300
ld-i386 x86: Propery check PC16 reloc overflow in 16-bit mode instructions 2021-05-26 12:13:24 -07:00
ld-ia64 Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-ifunc
ld-libs
ld-linkonce
ld-m68hc11
ld-m68k
ld-mep
ld-metag
ld-mips-elf Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-misc
ld-mmix Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-mn10300
ld-msp430-elf
ld-nds32
ld-nios2
ld-or1k or1k: Support large plt_relocs when generating plt entries 2021-05-06 20:51:25 +09:00
ld-pdp11
ld-pe x86-64/PE: adjust PR ld/26659 testcase for Cygwin 2021-04-22 10:55:07 +02:00
ld-pie
ld-plugin
ld-powerpc PowerPC undefweak testcase 2021-05-05 10:35:31 +09:30
ld-pru
ld-riscv-elf RISC-V: Check the overflow for %pcrel_lo addend more strictly. 2021-05-14 16:14:00 +08:00
ld-s12z
ld-s390 Re: section symbols without a name 2021-05-03 12:42:03 +09:30
ld-scripts PE image base fallout 2021-03-12 10:41:34 +10:30
ld-selective
ld-sh
ld-shared
ld-size
ld-sparc Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-spu
ld-srec PE image base fallout 2021-03-12 10:41:34 +10:30
ld-tic6x Adjust readelf's output so that section symbols without a name as shown with their section name. 2021-04-21 10:34:32 +01:00
ld-tilegx
ld-tilepro
ld-undefined
ld-unique
ld-v850
ld-vax-elf
ld-visium
ld-vxworks
ld-x86-64 x86: Propery check PC16 reloc overflow in 16-bit mode instructions 2021-05-26 12:13:24 -07:00
ld-xc16x
ld-xstormy16
ld-xtensa
ld-z8k
ld-z80
lib Enable linker garbage collection for the PRU target. 2021-05-10 14:00:00 +01:00
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-9303