mirror of
https://github.com/bminor/binutils-gdb.git
synced 2026-02-04 12:21:30 +00:00
aarch64: Don't relax relocations to static function symbols
The aarch64 ABI states that long branch veneers may be added to facilitate linking code that is beyond the range of a 26-bit call or branch; but it requires that the target symbol be a function symbol. Ensure that this latter condition is maintained by rejecting relaxation of a static function symbol to it's section symbol. Note that there should probably be a fix to the linker to enforce this during link time. I've not done this for now because that might break some existing object code that has been built with older versions of gas. At some point we should revisit this. This change also causes a small change in the LD testsuite: instead of generating some veneers with the section name we now (correctly) generate them using the name of the called function.
This commit is contained in:
@@ -10259,6 +10259,24 @@ cons_fix_new_aarch64 (fragS * frag, int where, int size, expressionS * exp)
|
||||
fix_new_exp (frag, where, size, exp, pcrel, type);
|
||||
}
|
||||
|
||||
/* Implement tc_fix_adjustable().
|
||||
On aarch64 a jump or call to a function symbol must not be relaxed to
|
||||
some other type of symbol: the linker uses this information to determine
|
||||
when it is safe to insert far-branch veneers. */
|
||||
|
||||
bool
|
||||
aarch64_fix_adjustable (fixS *fixp)
|
||||
{
|
||||
if (fixp->fx_addsy == NULL)
|
||||
return true;
|
||||
|
||||
/* Preserve relocations against function symbols. */
|
||||
if (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Implement md_after_parse_args. This is the earliest time we need to decide
|
||||
ABI. If no -mabi specified, the ABI will be decided by target triplet. */
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ extern void aarch64_after_parse_args (void);
|
||||
#define md_after_parse_args() aarch64_after_parse_args ()
|
||||
|
||||
# define EXTERN_FORCE_RELOC 1
|
||||
# define tc_fix_adjustable(FIX) 1
|
||||
# define tc_fix_adjustable(FIX) aarch64_fix_adjustable (FIX)
|
||||
|
||||
/* Values passed to md_apply_fix don't include the symbol value. */
|
||||
# define MD_APPLY_SYM_VALUE(FIX) 0
|
||||
@@ -360,6 +360,7 @@ extern void aarch64_init_frag (struct frag *, int);
|
||||
extern void aarch64_handle_align (struct frag *);
|
||||
extern int tc_aarch64_regname_to_dw2regnum (char *regname);
|
||||
extern void tc_aarch64_frame_initial_instructions (void);
|
||||
extern bool aarch64_fix_adjustable (struct fix *);
|
||||
|
||||
#ifdef TE_PE
|
||||
|
||||
|
||||
11
gas/testsuite/gas/aarch64/fix-adj.d
Normal file
11
gas/testsuite/gas/aarch64/fix-adj.d
Normal file
@@ -0,0 +1,11 @@
|
||||
#objdump: -r
|
||||
#notarget: *-*-*coff
|
||||
# Relocations to functions should point to the symbol, not the section.
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
RELOCATION RECORDS FOR \[\.text\.2\]:
|
||||
OFFSET TYPE VALUE
|
||||
0+0 R_AARCH64_CALL26 f1
|
||||
0+4 R_AARCH64_JUMP26 f1
|
||||
#...
|
||||
13
gas/testsuite/gas/aarch64/fix-adj.s
Normal file
13
gas/testsuite/gas/aarch64/fix-adj.s
Normal file
@@ -0,0 +1,13 @@
|
||||
.section .text.1, "ax", @progbits
|
||||
.type f1, %function
|
||||
.p2align 2
|
||||
nop
|
||||
f1:
|
||||
nop
|
||||
.section .text.2, "ax", @progbits
|
||||
.global f2
|
||||
.type f2, %function
|
||||
.p2align 2
|
||||
f2:
|
||||
bl f1
|
||||
b f1
|
||||
Reference in New Issue
Block a user