]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/loong64: use BREAK 0 as the code pad sequence
authorWANG Xuerui <git@xen0n.name>
Sat, 11 Mar 2023 14:38:01 +0000 (22:38 +0800)
committerM Zhuo <mzh@golangcn.org>
Wed, 15 Mar 2023 07:19:39 +0000 (07:19 +0000)
As the comment on CodePad goes, we "might want to pad with a trap
instruction to catch wayward programs". The current behavior of
zero-padding is equivalent to padding with an instruction of 0x00000000,
which is invalid according to the LoongArch manuals nevertheless, but
rumor has it that some early and/or engineering samples of Loongson
3A5000 recognized it (maybe behaving like NOP). It is better to avoid
undocumented behavior and ensure execution flow would not overflow the
pads.

Change-Id: I531b1eabeb355e9ad4a2d5340e61f2fe71349297
Reviewed-on: https://go-review.googlesource.com/c/go/+/475616
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/link/internal/loong64/obj.go

index 0f2ca2ebc700f26b42854f2c0e13cd2d300a45c6..c3f6ed9386c19c88fa20515f1d77ad639ff720c8 100644 (file)
@@ -19,6 +19,7 @@ func Init() (*sys.Arch, ld.Arch) {
                Minalign:         minAlign,
                Dwarfregsp:       dwarfRegSP,
                Dwarfreglr:       dwarfRegLR,
+               CodePad:          []byte{0x00, 0x00, 0x2a, 0x00}, // BREAK 0
                Adddynrel:        adddynrel,
                Archinit:         archinit,
                Archreloc:        archreloc,