mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
x86: check reloc types for relaxable branches
Bypassing _reloc() isn't a good idea, as there are various errors checked for there. For example 16-bit JMP or Jcc may not use the @plt form (resulting in a 32-bit relocation to be emitted for a 16-bit field), which so far we only reject for 16-bit CALL. In exchange this allows simplifying the setting up of the "reloc_type" local variable.
This commit is contained in:
@@ -16154,18 +16154,15 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
|
|||||||
int old_fr_fix;
|
int old_fr_fix;
|
||||||
fixS *fixP = NULL;
|
fixS *fixP = NULL;
|
||||||
|
|
||||||
if (fragP->fr_var != NO_RELOC)
|
reloc_type = (enum bfd_reloc_code_real) fragP->fr_var;
|
||||||
reloc_type = (enum bfd_reloc_code_real) fragP->fr_var;
|
|
||||||
else if (size == 2)
|
|
||||||
reloc_type = BFD_RELOC_16_PCREL;
|
|
||||||
#ifdef OBJ_ELF
|
#ifdef OBJ_ELF
|
||||||
else if (fragP->tc_frag_data.code == CODE_64BIT
|
if (reloc_type == NO_RELOC
|
||||||
&& fragP->fr_offset == 0
|
&& size != 2
|
||||||
&& need_plt32_p (fragP->fr_symbol))
|
&& fragP->tc_frag_data.code == CODE_64BIT
|
||||||
|
&& fragP->fr_offset == 0
|
||||||
|
&& need_plt32_p (fragP->fr_symbol))
|
||||||
reloc_type = BFD_RELOC_X86_64_PLT32;
|
reloc_type = BFD_RELOC_X86_64_PLT32;
|
||||||
#endif
|
#endif
|
||||||
else
|
|
||||||
reloc_type = BFD_RELOC_32_PCREL;
|
|
||||||
|
|
||||||
old_fr_fix = fragP->fr_fix;
|
old_fr_fix = fragP->fr_fix;
|
||||||
opcode = (unsigned char *) fragP->fr_opcode;
|
opcode = (unsigned char *) fragP->fr_opcode;
|
||||||
@@ -16179,7 +16176,9 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
|
|||||||
fixP = fix_new (fragP, old_fr_fix, size,
|
fixP = fix_new (fragP, old_fr_fix, size,
|
||||||
fragP->fr_symbol,
|
fragP->fr_symbol,
|
||||||
fragP->fr_offset, 1,
|
fragP->fr_offset, 1,
|
||||||
reloc_type);
|
_reloc (size, 1, 1, reloc_type,
|
||||||
|
fragP->tc_frag_data.code == CODE_64BIT,
|
||||||
|
fragP->fr_file, fragP->fr_line));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COND_JUMP86:
|
case COND_JUMP86:
|
||||||
@@ -16198,7 +16197,9 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
|
|||||||
fix_new (fragP, old_fr_fix + 2, 2,
|
fix_new (fragP, old_fr_fix + 2, 2,
|
||||||
fragP->fr_symbol,
|
fragP->fr_symbol,
|
||||||
fragP->fr_offset, 1,
|
fragP->fr_offset, 1,
|
||||||
reloc_type);
|
_reloc (size, 1, 1, reloc_type,
|
||||||
|
fragP->tc_frag_data.code == CODE_64BIT,
|
||||||
|
fragP->fr_file, fragP->fr_line));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Fall through. */
|
/* Fall through. */
|
||||||
@@ -16224,7 +16225,9 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
|
|||||||
fixP = fix_new (fragP, old_fr_fix + 1, size,
|
fixP = fix_new (fragP, old_fr_fix + 1, size,
|
||||||
fragP->fr_symbol,
|
fragP->fr_symbol,
|
||||||
fragP->fr_offset, 1,
|
fragP->fr_offset, 1,
|
||||||
reloc_type);
|
_reloc (size, 1, 1, reloc_type,
|
||||||
|
fragP->tc_frag_data.code == CODE_64BIT,
|
||||||
|
fragP->fr_file, fragP->fr_line));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -881,6 +881,7 @@ if {[is_elf_format] || [istarget "*-*-vxworks*"]} then {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_dump_test "code16-2"
|
run_dump_test "code16-2"
|
||||||
|
run_list_test "reloc16"
|
||||||
|
|
||||||
if {![istarget "*-*-dragonfly*"]
|
if {![istarget "*-*-dragonfly*"]
|
||||||
&& ![istarget "*-*-gnu*"]
|
&& ![istarget "*-*-gnu*"]
|
||||||
|
|||||||
4
gas/testsuite/gas/i386/reloc16.l
Normal file
4
gas/testsuite/gas/i386/reloc16.l
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.*: Assembler messages:
|
||||||
|
.*:4: Error: .*4-byte reloc.*2-byte field.*
|
||||||
|
.*:5: Error: .*4-byte reloc.*2-byte field.*
|
||||||
|
.*:6: Error: .*4-byte reloc.*2-byte field.*
|
||||||
6
gas/testsuite/gas/i386/reloc16.s
Normal file
6
gas/testsuite/gas/i386/reloc16.s
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.code16
|
||||||
|
.text
|
||||||
|
plt:
|
||||||
|
call func@plt
|
||||||
|
jz func@plt
|
||||||
|
jmp func@plt
|
||||||
Reference in New Issue
Block a user