diff options
| author | zhaozhou <zhaozhou@loongson.cn> | 2026-04-16 17:31:41 +0800 |
|---|---|---|
| committer | mengqinggang <mengqinggang@loongson.cn> | 2026-04-27 16:31:33 +0800 |
| commit | 2e5f3d9f0596e60031d7c56cf943cf00e81fe53d (patch) | |
| tree | 8a94a41741bb80e5c933f9ae63559dd6e859ca97 | |
| parent | df03e2328eefb2543445740c096cc40510fa0f24 (diff) | |
| download | binutils-2e5f3d9f0596e60031d7c56cf943cf00e81fe53d.tar.gz binutils-2e5f3d9f0596e60031d7c56cf943cf00e81fe53d.tar.bz2 binutils-2e5f3d9f0596e60031d7c56cf943cf00e81fe53d.zip | |
LoongArch: Enforce 4-byte align for machine instructionsinsn-4-byte-align
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.
| -rw-r--r-- | gas/config/tc-loongarch.c | 5 | ||||
| -rw-r--r-- | gas/testsuite/gas/loongarch/insn_align_4.d | 7 | ||||
| -rw-r--r-- | gas/testsuite/gas/loongarch/insn_align_4.s | 4 |
3 files changed, 16 insertions, 0 deletions
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 1eb35f2c75e..d067318ce24 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -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; diff --git a/gas/testsuite/gas/loongarch/insn_align_4.d b/gas/testsuite/gas/loongarch/insn_align_4.d new file mode 100644 index 00000000000..31a5d352a76 --- /dev/null +++ b/gas/testsuite/gas/loongarch/insn_align_4.d @@ -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 +#... diff --git a/gas/testsuite/gas/loongarch/insn_align_4.s b/gas/testsuite/gas/loongarch/insn_align_4.s new file mode 100644 index 00000000000..7b4922c113f --- /dev/null +++ b/gas/testsuite/gas/loongarch/insn_align_4.s @@ -0,0 +1,4 @@ +.type test, @function +test: + jirl $ra, $ra, 0 +.size test, .-test |
