diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-05-26 12:13:13 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-05-26 12:13:24 -0700 |
commit | 50c95a739c91ae70cf8481936611aa1f5397a384 (patch) | |
tree | f539432154713f55c321e9dbd16251eb4f51eec7 /ld | |
parent | 11bb5c41eb98d8e7d4d75dfcf620f6f627523e77 (diff) | |
download | gdb-50c95a739c91ae70cf8481936611aa1f5397a384.zip gdb-50c95a739c91ae70cf8481936611aa1f5397a384.tar.gz gdb-50c95a739c91ae70cf8481936611aa1f5397a384.tar.bz2 |
x86: Propery check PC16 reloc overflow in 16-bit mode instructions
commit a7664973b24a242cd9ea17deb5eaf503065fc0bd
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.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/code16.d | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/code16.t | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-i386/i386.exp | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/code16.d | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/code16.t | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/x86-64.exp | 1 |
7 files changed, 64 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index fca75bd..8d25dd87 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,5 +1,15 @@ 2021-05-26 H.J. Lu <hongjiu.lu@intel.com> + 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 H.J. Lu <hongjiu.lu@intel.com> + * testsuite/ld-x86-64/ilp32-12.d: New file. * testsuite/ld-x86-64/ilp32-12.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run ilp32-12. diff --git a/ld/testsuite/ld-i386/code16.d b/ld/testsuite/ld-i386/code16.d new file mode 100644 index 0000000..8b67861 --- /dev/null +++ b/ld/testsuite/ld-i386/code16.d @@ -0,0 +1,19 @@ +#name: i386 R_386_PC16 reloc in 16-bit mode +#as: --32 -mx86-used-note=no --generate-missing-build-notes=no +#source: ${srcdir}/../../../gas/testsuite/gas/i386/code16-2.s +#ld: -T code16.t +#objdump: -dw -Mi8086 + +.*: +file format .* + + +Disassembly of section .text.default_process_op.isra.0: + +0+737c <default_process_op.isra.0>: + +[a-f0-9]+: 66 c3 retl + +Disassembly of section .text.mpt_scsi_process_op: + +0+f869 <mpt_scsi_process_op>: + +[a-f0-9]+: e9 10 7b jmp 737c <default_process_op.isra.0> +#pass diff --git a/ld/testsuite/ld-i386/code16.t b/ld/testsuite/ld-i386/code16.t new file mode 100644 index 0000000..0cf9904 --- /dev/null +++ b/ld/testsuite/ld-i386/code16.t @@ -0,0 +1,7 @@ +OUTPUT_FORMAT("elf32-i386") +OUTPUT_ARCH("i386") +SECTIONS +{ +.text.default_process_op.isra.0 0x737c : { *(.text.default_process_op.isra.0) } +.text.mpt_scsi_process_op 0xf869 : { *(.text.mpt_scsi_process_op) } +} diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index d0b3f69..3d6047b 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -492,6 +492,7 @@ run_dump_test "property-x86-isa2" run_dump_test "property-x86-isa3" run_dump_test "property-x86-isa4" run_dump_test "pr26869" +run_dump_test "code16" if { !([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"] diff --git a/ld/testsuite/ld-x86-64/code16.d b/ld/testsuite/ld-x86-64/code16.d new file mode 100644 index 0000000..20096ab --- /dev/null +++ b/ld/testsuite/ld-x86-64/code16.d @@ -0,0 +1,19 @@ +#name: x86-64 R_X86_64_PC16 reloc in 16-bit mode +#as: --64 -mx86-used-note=no --generate-missing-build-notes=no +#source: ${srcdir}/../../../gas/testsuite/gas/i386/code16-2.s +#ld: -T code16.t +#objdump: -dw -Mi8086 + +.*: +file format .* + + +Disassembly of section .text.default_process_op.isra.0: + +0+737c <default_process_op.isra.0>: + +[a-f0-9]+: 66 c3 retl + +Disassembly of section .text.mpt_scsi_process_op: + +0+f869 <mpt_scsi_process_op>: + +[a-f0-9]+: e9 10 7b jmp 737c <default_process_op.isra.0> +#pass diff --git a/ld/testsuite/ld-x86-64/code16.t b/ld/testsuite/ld-x86-64/code16.t new file mode 100644 index 0000000..9ef00a3 --- /dev/null +++ b/ld/testsuite/ld-x86-64/code16.t @@ -0,0 +1,7 @@ +OUTPUT_FORMAT("elf64-x86-64") +OUTPUT_ARCH("i386:x86-64") +SECTIONS +{ +.text.default_process_op.isra.0 0x737c : { *(.text.default_process_op.isra.0) } +.text.mpt_scsi_process_op 0xf869 : { *(.text.mpt_scsi_process_op) } +} diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 37cf998..8071666 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -474,6 +474,7 @@ run_dump_test "property-x86-isa3" run_dump_test "property-x86-isa3-x32" run_dump_test "property-x86-isa4" run_dump_test "property-x86-isa4-x32" +run_dump_test "code16" if ![istarget "x86_64-*-linux*"] { return |