]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: add opcode space safety check
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 17 Jun 2016 19:28:31 +0000 (12:28 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 16 Aug 2016 20:26:16 +0000 (20:26 +0000)
This CL adds a safety mechanism
for changing the number of opcodes
available per architecture.

A subsequent CL will actually make the change.

Change-Id: I6332ed5514f2f153c54d11b7da0cc8a6be1c8066
Reviewed-on: https://go-review.googlesource.com/24222
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/internal/obj/link.go
src/cmd/internal/obj/util.go

index 3c66eecbf0dd803c9d6ea3ddd7e2c2ca0f96318a..edd45d411d143073fedfaa75607b9af808c62b02 100644 (file)
@@ -308,7 +308,8 @@ const (
        ABaseMIPS64
        ABaseS390X
 
-       AMask = 1<<12 - 1 // AND with this to use the opcode as an array index.
+       AllowedOpCodes = 1 << 12            // The number of opcodes available for any given architecture.
+       AMask          = AllowedOpCodes - 1 // AND with this to use the opcode as an array index.
 )
 
 // An LSym is the sort of symbol that is written to an object file.
index a80af26c07264e5f448dca23897e7064d9884e29..1572071ed3d0096d2e340fcccb60b0a478ee0943 100644 (file)
@@ -462,6 +462,9 @@ var aSpace []opSet
 // RegisterOpcode binds a list of instruction names
 // to a given instruction number range.
 func RegisterOpcode(lo As, Anames []string) {
+       if len(Anames) > AllowedOpCodes {
+               panic(fmt.Sprintf("too many instructions, have %d max %d", len(Anames), AllowedOpCodes))
+       }
        aSpace = append(aSpace, opSet{lo, Anames})
 }