1 /* tc-loongarch.h -- Header file for tc-loongarch.c.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 Contributed by Loongson Ltd.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the license, or
10 (at your option) any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
24 #include "opcode/loongarch.h"
26 #define TARGET_BYTES_BIG_ENDIAN 0
27 #define TARGET_ARCH bfd_arch_loongarch
29 #define TARGET_MACH (loongarch_mach ())
30 extern unsigned long loongarch_mach (void);
32 #define WORKING_DOT_WORD 1
33 #define REPEAT_CONS_EXPRESSIONS
35 #define md_end loongarch_md_end
36 extern void loongarch_md_end (void);
38 /* Early than md_begin. */
39 #define md_after_parse_args loongarch_after_parse_args
40 extern void loongarch_after_parse_args (void);
42 extern void loongarch_pop_insert (void);
43 #define md_pop_insert() loongarch_pop_insert ()
45 #define TARGET_FORMAT loongarch_target_format ()
46 extern const char *loongarch_target_format (void);
48 #define md_relax_frag(segment, fragp, stretch) \
49 loongarch_relax_frag (segment, fragp, stretch)
50 extern int loongarch_relax_frag (asection
*, struct frag
*, long);
51 #define md_section_align(seg, size) (size)
52 #define md_undefined_symbol(name) (0)
55 extern bool loongarch_frag_align_code (int, int);
56 #define md_do_align(N, FILL, LEN, MAX, LABEL) \
57 if ((N) != 0 && !(FILL) && !need_pass_2 && subseg_text_p (now_seg)) \
59 if (loongarch_frag_align_code (N, MAX)) \
63 /* The following two macros let the linker resolve all the relocs
66 This is called to see whether a reloc against a defined symbol
67 should be converted into a reloc against a section.
69 If relax and norelax have different value may cause ld ".eh_frame_hdr
70 refers to overlapping FDEs" error when link relax .o and norelax .o. */
71 #define tc_fix_adjustable(fixp) 0
73 /* Tne difference between same-section symbols may be affected by linker
74 relaxation, so do not resolve such expressions in the assembler. */
75 #define md_allow_local_subtract(l,r,s) 0
77 /* If subsy of BFD_RELOC32/64 and PC in same segment, and without relax
78 or PC at start of subsy or with relax but sub_symbol_segment not in
79 SEC_CODE, we generate 32/64_PCREL. */
80 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \
81 (!(LARCH_opts.thin_add_sub \
82 && (BFD_RELOC_32 || BFD_RELOC_64) \
83 && (!LARCH_opts.relax \
84 || S_GET_VALUE (FIX->fx_subsy) \
85 == FIX->fx_frag->fr_address + FIX->fx_where \
86 || (LARCH_opts.relax \
87 && ((S_GET_SEGMENT (FIX->fx_subsy)->flags & SEC_CODE) == 0)))))
89 #define TC_VALIDATE_FIX_SUB(FIX, SEG) 1
90 #define DIFF_EXPR_OK 1
92 /* Postpone text-section label subtraction calculation until linking, since
93 linker relaxations might change the deltas. */
94 #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEC) \
96 (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEC) \
97 || ((SEC)->flags & SEC_CODE) != 0) \
98 : (GENERIC_FORCE_RELOCATION_SUB_SAME (FIX, SEC))) \
100 #define TC_LINKRELAX_FIXUP(seg) ((seg->flags & SEC_CODE) \
101 || (seg->flags & SEC_DEBUGGING))
103 #define TC_FORCE_RELOCATION_LOCAL(FIX) 1
105 /* Values passed to md_apply_fix don't include symbol values. */
106 #define MD_APPLY_SYM_VALUE(FIX) 0
108 #define TARGET_USE_CFIPOP 1
109 /* Adjust debug_line after relaxation. */
110 #define DWARF2_USE_FIXED_ADVANCE_PC 1
112 /* FDE Data Alignment Factor.
113 FDE Code Alignment Factor (DWARF2_LINE_MIN_INSN_LENGTH) should be 1
114 because DW_CFA_advance_loc need to be relocated in bytes
115 when linker relaxation. */
116 #define DWARF2_CIE_DATA_ALIGNMENT (-8)
117 #define DWARF2_DEFAULT_RETURN_COLUMN 1 /* FDE Return Address Register. */
119 #define tc_cfi_frame_initial_instructions \
120 loongarch_cfi_frame_initial_instructions
121 extern void loongarch_cfi_frame_initial_instructions (void);
123 #define tc_symbol_new_hook(sym) \
124 if (0 == strcmp (sym->bsym->name, FAKE_LABEL_NAME)) \
125 S_SET_OTHER (sym, STV_HIDDEN);
127 #define tc_parse_to_dw2regnum tc_loongarch_parse_to_dw2regnum
128 extern void tc_loongarch_parse_to_dw2regnum (expressionS
*);
130 extern void loongarch_pre_output_hook (void);
131 #define md_pre_output_hook loongarch_pre_output_hook ()
132 #define GAS_SORT_RELOCS 1
134 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
136 #define HANDLE_ALIGN(fragp) loongarch_handle_align (fragp)
137 extern void loongarch_handle_align (struct frag
*);
138 #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4)
140 #define elf_tc_final_processing loongarch_elf_final_processing
141 extern void loongarch_elf_final_processing (void);
143 #define MAX_RELOC_NUMBER_A_INSN 20
147 bfd_reloc_code_real_type type
;
151 #define md_finish loongarch_md_finish
152 extern void loongarch_md_finish (void);