Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit 11e0255

Browse files
author
Andrew Waterman
committed
Don't define our own implementation of p2align
Instead, define md_do_align to override handling of code alignment.
1 parent a72b098 commit 11e0255

File tree

2 files changed

+22
-44
lines changed

2 files changed

+22
-44
lines changed

gas/config/tc-riscv.c

+14-44
Original file line numberDiff line numberDiff line change
@@ -2078,63 +2078,36 @@ s_bss (int ignore ATTRIBUTE_UNUSED)
20782078
demand_empty_rest_of_line ();
20792079
}
20802080

2081-
/* Align to a given power of two. */
2081+
/* Called from md_do_align. Used to create an alignment frag in a
2082+
code section by emitting a worst-case NOP sequence that the linker
2083+
will later relax to the correct number of NOPs. We can't compute
2084+
the correct alignment now because of other linker relaxations. */
20822085

2083-
static void
2084-
s_align (int bytes_p)
2086+
void
2087+
riscv_frag_align_code (int n, int max)
20852088
{
2086-
int fill_value = 0, fill_value_specified = 0;
2087-
int min_text_alignment = riscv_opts.rvc ? 2 : 4;
2088-
int alignment = get_absolute_expression (), bytes;
2089+
bfd_vma bytes = (bfd_vma)1 << n;
2090+
bfd_vma min_text_alignment = riscv_opts.rvc ? 2 : 4;
20892091

2090-
if (bytes_p)
2092+
if (bytes > min_text_alignment)
20912093
{
2092-
bytes = alignment;
2093-
if (bytes < 1 || (bytes & (bytes-1)) != 0)
2094-
as_bad (_("alignment not a power of 2: %d"), bytes);
2095-
for (alignment = 0; bytes > 1; bytes >>= 1)
2096-
alignment++;
2097-
}
2098-
2099-
bytes = 1 << alignment;
2100-
2101-
if (alignment < 0 || alignment > 31)
2102-
as_bad (_("unsatisfiable alignment: %d"), alignment);
2103-
2104-
if (*input_line_pointer == ',')
2105-
{
2106-
++input_line_pointer;
2107-
fill_value = get_absolute_expression ();
2108-
fill_value_specified = 1;
2109-
}
2110-
2111-
if (!fill_value_specified
2112-
&& subseg_text_p (now_seg)
2113-
&& bytes > min_text_alignment)
2114-
{
2115-
/* Emit the worst-case NOP string. The linker will delete any
2116-
unnecessary NOPs. This allows us to support code alignment
2117-
in spite of linker relaxations. */
2118-
bfd_vma i, worst_case_bytes = bytes - min_text_alignment;
2094+
bfd_vma worst_case_bytes = bytes - min_text_alignment;
21192095
char *nops = frag_more (worst_case_bytes);
2096+
expressionS ex;
2097+
bfd_vma i;
2098+
21202099
for (i = 0; i < worst_case_bytes - 2; i += 4)
21212100
md_number_to_chars (nops + i, RISCV_NOP, 4);
2101+
21222102
if (i < worst_case_bytes)
21232103
md_number_to_chars (nops + i, RVC_NOP, 2);
21242104

2125-
expressionS ex;
21262105
ex.X_op = O_constant;
21272106
ex.X_add_number = worst_case_bytes;
21282107

21292108
fix_new_exp (frag_now, nops - frag_now->fr_literal, 0,
21302109
&ex, FALSE, BFD_RELOC_RISCV_ALIGN);
21312110
}
2132-
else if (alignment)
2133-
frag_align (alignment, fill_value, 0);
2134-
2135-
record_alignment (now_seg, alignment);
2136-
2137-
demand_empty_rest_of_line ();
21382111
}
21392112

21402113
int
@@ -2381,9 +2354,6 @@ static const pseudo_typeS riscv_pseudo_table[] =
23812354
{"dtprelword", s_dtprel, 4},
23822355
{"dtpreldword", s_dtprel, 8},
23832356
{"bss", s_bss, 0},
2384-
{"align", s_align, 0},
2385-
{"p2align", s_align, 0},
2386-
{"balign", s_align, 1},
23872357
{"uleb128", s_riscv_leb128, 0},
23882358
{"sleb128", s_riscv_leb128, 1},
23892359

gas/config/tc-riscv.h

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ extern int riscv_relax_frag (asection *, struct frag *, long);
4848
#define md_undefined_symbol(name) (0)
4949
#define md_operand(x)
5050

51+
extern void riscv_frag_align_code (int, int);
52+
#define md_do_align(N, FILL, LEN, MAX, LABEL) \
53+
if (FILL == NULL && (N) != 0 && ! need_pass_2 && subseg_text_p (now_seg)) \
54+
{ \
55+
riscv_frag_align_code (N, MAX); \
56+
goto LABEL; \
57+
}
58+
5159
/* FIXME: it is unclear if this is used, or if it is even correct. */
5260
#define MAX_MEM_FOR_RS_ALIGN_CODE (1 + 2)
5361

0 commit comments

Comments
 (0)