mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2026-08-27 00:26:02 -04:00
LoongArch: Enforce 4-byte align for machine instructions
If no alignment is specified in the assembly file, LoongArch will not perform forced alignment. When this object file (.o) is linked into an executable, instructions may not be 4-byte aligned, which will eventually cause instruction fetch errors. For example, the above issue can occur when generating a shared object file (.so) with the -nostdlib option.
This commit is contained in:
parent
df03e2328e
commit
2e5f3d9f05
3 changed files with 16 additions and 0 deletions
|
|
@ -1432,6 +1432,11 @@ loongarch_assemble_INSNs (char *str, unsigned int expand_from_macro)
|
|||
if (*str == '\0')
|
||||
break;
|
||||
|
||||
/* LoongArch instructions require 4-byte alignment. When emitting
|
||||
instructions into any section, record the appropriate section
|
||||
alignment. */
|
||||
record_alignment (now_seg, 2);
|
||||
|
||||
struct loongarch_cl_insn the_one;
|
||||
memset (&the_one, 0, sizeof (the_one));
|
||||
the_one.name = str;
|
||||
|
|
|
|||
7
gas/testsuite/gas/loongarch/insn_align_4.d
Normal file
7
gas/testsuite/gas/loongarch/insn_align_4.d
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#as:
|
||||
#readelf: -S
|
||||
|
||||
#...
|
||||
\[ [0-9]+\] \.text PROGBITS [0-9a-f]{16} [0-9a-f]{8}
|
||||
[0-9a-f]{16} [0-9a-f]{16} AX 0 0 4
|
||||
#...
|
||||
4
gas/testsuite/gas/loongarch/insn_align_4.s
Normal file
4
gas/testsuite/gas/loongarch/insn_align_4.s
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.type test, @function
|
||||
test:
|
||||
jirl $ra, $ra, 0
|
||||
.size test, .-test
|
||||
Loading…
Add table
Add a link
Reference in a new issue