AVR: Only set link-relax elf flag when appropriate.
[external/binutils.git] / gas / config / tc-avr.h
1 /* This file is tc-avr.h
2    Copyright (C) 1999-2014 Free Software Foundation, Inc.
3
4    Contributed by Denis Chertykov <denisc@overta.ru>
5
6    This file is part of GAS, the GNU Assembler.
7
8    GAS is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3, or (at your option)
11    any later version.
12
13    GAS is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GAS; see the file COPYING.  If not, write to the Free
20    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21    02110-1301, USA.  */
22
23 /* By convention, you should define this macro in the `.h' file.  For
24    example, `tc-m68k.h' defines `TC_M68K'.  You might have to use this
25    if it is necessary to add CPU specific code to the object format
26    file.  */
27 #define TC_AVR
28
29 /* This macro is the BFD target name to use when creating the output
30    file.  This will normally depend upon the `OBJ_FMT' macro.  */
31 #define TARGET_FORMAT "elf32-avr"
32
33 /* This macro is the BFD architecture to pass to `bfd_set_arch_mach'.  */
34 #define TARGET_ARCH bfd_arch_avr
35
36 /* This macro is the BFD machine number to pass to
37    `bfd_set_arch_mach'.  If it is not defined, GAS will use 0.  */
38 #define TARGET_MACH 0
39
40 /* You should define this macro to be non-zero if the target is big
41    endian, and zero if the target is little endian.  */
42 #define TARGET_BYTES_BIG_ENDIAN 0
43
44 /* If you define this macro, GAS will warn about the use of
45    nonstandard escape sequences in a string.  */
46 #define ONLY_STANDARD_ESCAPES
47
48 /* GAS will call this function for any expression that can not be
49    recognized.  When the function is called, `input_line_pointer'
50    will point to the start of the expression.  */
51 #define md_operand(x)
52
53 typedef struct
54 {
55   /* Name of the expression modifier allowed with .byte, .word, etc.  */
56   const char *name;
57
58   /* Only allowed with n bytes of data.  */
59   int nbytes;
60
61   /* Associated RELOC.  */
62   bfd_reloc_code_real_type reloc;
63
64   /* Part of the error message.  */
65   const char *error;
66 } exp_mod_data_t;
67
68 extern const exp_mod_data_t exp_mod_data[];
69 #define TC_PARSE_CONS_RETURN_TYPE const exp_mod_data_t *
70 #define TC_PARSE_CONS_RETURN_NONE exp_mod_data
71
72 /* You may define this macro to parse an expression used in a data
73    allocation pseudo-op such as `.word'.  You can use this to
74    recognize relocation directives that may appear in such directives.  */
75 #define TC_PARSE_CONS_EXPRESSION(EXPR,N) avr_parse_cons_expression (EXPR, N)
76 extern const exp_mod_data_t *avr_parse_cons_expression (expressionS *, int);
77
78 /* You may define this macro to generate a fixup for a data
79    allocation pseudo-op.  */
80 #define TC_CONS_FIX_NEW avr_cons_fix_new
81 extern void avr_cons_fix_new (fragS *,int, int, expressionS *,
82                               const exp_mod_data_t *);
83
84 /* This should just call either `number_to_chars_bigendian' or
85    `number_to_chars_littleendian', whichever is appropriate.  On
86    targets like the MIPS which support options to change the
87    endianness, which function to call is a runtime decision.  On
88    other targets, `md_number_to_chars' can be a simple macro.  */
89 #define md_number_to_chars number_to_chars_littleendian
90
91 /* `md_short_jump_size'
92    `md_long_jump_size'
93    `md_create_short_jump'
94    `md_create_long_jump'
95    If `WORKING_DOT_WORD' is defined, GAS will not do broken word
96    processing (*note Broken words::.).  Otherwise, you should set
97    `md_short_jump_size' to the size of a short jump (a jump that is
98    just long enough to jump around a long jmp) and
99    `md_long_jump_size' to the size of a long jump (a jump that can go
100    anywhere in the function), You should define
101    `md_create_short_jump' to create a short jump around a long jump,
102    and define `md_create_long_jump' to create a long jump.  */
103 #define WORKING_DOT_WORD
104
105 /* If you define this macro, it means that `tc_gen_reloc' may return
106    multiple relocation entries for a single fixup.  In this case, the
107    return value of `tc_gen_reloc' is a pointer to a null terminated
108    array.  */
109 #undef RELOC_EXPANSION_POSSIBLE
110
111 /* No shared lib support, so we don't need to ensure externally
112    visible symbols can be overridden.  */
113 #define EXTERN_FORCE_RELOC 0
114
115 /* If defined, this macro allows control over whether fixups for a
116    given section will be processed when the linkrelax variable is
117    set. Define it to zero and handle things in md_apply_fix instead.*/
118 #define TC_LINKRELAX_FIXUP(SEG) 0
119
120 /* If this macro returns non-zero, it guarantees that a relocation will be emitted
121    even when the value can be resolved locally. Do that if linkrelax is turned on */
122 #define TC_FORCE_RELOCATION(fix)        avr_force_relocation (fix)
123 #define TC_FORCE_RELOCATION_SUB_SAME(fix, seg) \
124   (! SEG_NORMAL (seg) || avr_force_relocation (fix))
125 extern int avr_force_relocation (struct fix *);
126
127 /* Values passed to md_apply_fix don't include the symbol value.  */
128 #define MD_APPLY_SYM_VALUE(FIX) 0
129
130 /* If you define this macro, it should return the offset between the
131    address of a PC relative fixup and the position from which the PC
132    relative adjustment should be made.  On many processors, the base
133    of a PC relative instruction is the next instruction, so this
134    macro would return the length of an instruction.  */
135 #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from_section (FIX, SEC)
136 extern long md_pcrel_from_section (struct fix *, segT);
137
138 /* The number of bytes to put into a word in a listing.  This affects
139    the way the bytes are clumped together in the listing.  For
140    example, a value of 2 might print `1234 5678' where a value of 1
141    would print `12 34 56 78'.  The default value is 4.  */
142 #define LISTING_WORD_SIZE 2
143
144 /* AVR port uses `$' as a logical line separator.  */
145 #define LEX_DOLLAR 0
146
147 /* An `.lcomm' directive with no explicit alignment parameter will
148    use this macro to set P2VAR to the alignment that a request for
149    SIZE bytes will have.  The alignment is expressed as a power of
150    two.  If no alignment should take place, the macro definition
151    should do nothing.  Some targets define a `.bss' directive that is
152    also affected by this macro.  The default definition will set
153    P2VAR to the truncated power of two of sizes up to eight bytes.  */
154 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) (P2VAR) = 0
155
156 /* We don't want gas to fixup the following program memory related relocations.
157    We will need them in case that we want to do linker relaxation.
158    We could in principle keep these fixups in gas when not relaxing.
159    However, there is no serious performance penalty when making the linker
160    make the fixup work.  Check also that fx_addsy is not NULL, in order to make
161    sure that the fixup refers to some sort of label.  */
162 #define TC_VALIDATE_FIX(FIXP,SEG,SKIP)                       \
163   if (   (FIXP->fx_r_type == BFD_RELOC_AVR_7_PCREL           \
164        || FIXP->fx_r_type == BFD_RELOC_AVR_13_PCREL          \
165        || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_PM        \
166        || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_GS        \
167        || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_PM        \
168        || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_GS        \
169        || FIXP->fx_r_type == BFD_RELOC_AVR_HH8_LDI_PM        \
170        || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_PM_NEG    \
171        || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_PM_NEG    \
172        || FIXP->fx_r_type == BFD_RELOC_AVR_HH8_LDI_PM_NEG    \
173        || FIXP->fx_r_type == BFD_RELOC_AVR_8_LO              \
174        || FIXP->fx_r_type == BFD_RELOC_AVR_8_HI              \
175        || FIXP->fx_r_type == BFD_RELOC_AVR_8_HLO             \
176        || FIXP->fx_r_type == BFD_RELOC_AVR_16_PM)            \
177       && FIXP->fx_addsy != NULL                              \
178       && FIXP->fx_subsy == NULL)                             \
179     {                                                        \
180       symbol_mark_used_in_reloc (FIXP->fx_addsy);            \
181       goto SKIP;                                             \
182     }
183
184 /* This macro is evaluated for any fixup with a fx_subsy that
185    fixup_segment cannot reduce to a number.  If the macro returns
186    false an error will be reported. */
187 #define TC_VALIDATE_FIX_SUB(fix, seg)   avr_validate_fix_sub (fix)
188 extern int avr_validate_fix_sub (struct fix *);
189
190 /* This target is buggy, and sets fix size too large.  */
191 #define TC_FX_SIZE_SLACK(FIX) 2
192
193 /* AVR instructions are 2 or 4 bytes long.  */
194 #define DWARF2_LINE_MIN_INSN_LENGTH     2
195
196 /* 32 bits pseudo-addresses are used on AVR.  */
197 #define DWARF2_ADDR_SIZE(bfd) 4
198
199 /* Enable cfi directives.  */
200 #define TARGET_USE_CFIPOP 1
201
202 /* The stack grows down, and is only byte aligned.  */
203 #define DWARF2_CIE_DATA_ALIGNMENT -1
204
205 /* Define the column that represents the PC.  */
206 #define DWARF2_DEFAULT_RETURN_COLUMN  36
207
208 /* Define a hook to setup initial CFI state.  */
209 extern void tc_cfi_frame_initial_instructions (void);
210 #define tc_cfi_frame_initial_instructions tc_cfi_frame_initial_instructions
211
212 /* The difference between same-section symbols may be affected by linker
213    relaxation, so do not resolve such expressions in the assembler.  */
214 #define md_allow_local_subtract(l,r,s) avr_allow_local_subtract (l, r, s)
215 extern bfd_boolean avr_allow_local_subtract (expressionS *, expressionS *, segT);
216
217 #define elf_tc_final_processing         avr_elf_final_processing
218 extern void avr_elf_final_processing (void);