New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strconv: "invalid array index" compiler error was reported after changing reloc type #31955
Comments
I haven't yet tracked down the failure, but it's clear that function "_()" was not introduced by my change. In addition, the newly added relocation type R_ARM64_LDST128 has not been correctly identified. |
As the comment says,"Re-run the stringer command to generate them again." When you introduce a new reloc you need to run |
Hi @ianlancetaylor I installed Stringer and re-run the stringer command to generate the strings. |
Sorry I made a stupid mistake, I didn't use a lower version of go to build Go. |
I don't know if I got something wrong, but the problem still exists here. What I did: |
I advise running |
It still doesn't work. |
OK, my instructions were probably bad. When you run But running By the way I think this change is being made in https://golang.org/cl/176697 anyhow, perhaps looking at the CL will suggest something about what is happening with your code. |
https://golang.org/cl/176697 is right, the changes in reloctype.go and reloctype_string.go are what we expect. I don't know which version of stringer he used. In a clean Go project, running $ git diff
diff --git a/src/cmd/internal/objabi/reloctype_string.go b/src/cmd/internal/objabi/reloctype_string.go
index bd6d285617..3c169ffeea 100644
--- a/src/cmd/internal/objabi/reloctype_string.go
+++ b/src/cmd/internal/objabi/reloctype_string.go
@@ -1,12 +1,63 @@
-// Code generated by "stringer -type RelocType"; DO NOT EDIT.
+// Code generated by "stringer -type=RelocType"; DO NOT EDIT.
package objabi
import "strconv"
-const _RelocType_name = "R_ADDRR_ADDRPOWERR_ADDRARM64R_ADDRMIPSR_ADDROFFR_WEAKADDROFFR_SIZER_CALLR_CALLARMR_CALLARM64R_CALL INDR_CALLPOWERR_CALLMIPSR_CONSTR_PCRELR_TLS_LER_TLS_IER_GOTOFFR_PLT0R_PLT1R_PLT2R_USEFIELDR_USETYPER_METHODOFFR_POWER_TOCR_G OTPCRELR_JMPMIPSR_DWARFSECREFR_DWARFFILEREFR_ARM64_TLS_LER_ARM64_TLS_IER_ARM64_GOTPCRELR_ARM64_GOTR_ARM64_PCRELR_ARM64_LDST8 R_ARM64_LDST32R_ARM64_LDST64R_POWER_TLS_LER_POWER_TLS_IER_POWER_TLSR_ADDRPOWER_DSR_ADDRPOWER_GOTR_ADDRPOWER_PCRELR_ADDRPOWER _TOCRELR_ADDRPOWER_TOCREL_DSR_PCRELDBLR_ADDRMIPSUR_ADDRMIPSTLSR_ADDRCUOFFR_WASMIMPORTR_XCOFFREF"
+func _() {
+ // An "invalid array index" compiler error signifies that the constant values have changed.
+ // Re-run the stringer command to generate them again.
+ var x [1]struct{}
+ _ = x[R_ADDR-1]
+ _ = x[R_ADDRPOWER-2]
+ _ = x[R_ADDRARM64-3]
+ _ = x[R_ADDRMIPS-4]
+ _ = x[R_ADDROFF-5]
+ _ = x[R_WEAKADDROFF-6]
+ _ = x[R_SIZE-7]
+ _ = x[R_CALL-8]
+ _ = x[R_CALLARM-9]
+ _ = x[R_CALLARM64-10]
+ _ = x[R_CALLIND-11]
+ _ = x[R_CALLPOWER-12]
+ _ = x[R_CALLMIPS-13]
+ _ = x[R_CONST-14]
+ _ = x[R_PCREL-15]
+ _ = x[R_TLS_LE-16]
+ _ = x[R_TLS_IE-17]
+ _ = x[R_GOTOFF-18]
+ _ = x[R_PLT0-19]
+ _ = x[R_PLT1-20]
+ _ = x[R_PLT2-21]
+ _ = x[R_USEFIELD-22]
+ _ = x[R_USETYPE-23]
+ _ = x[R_METHODOFF-24]
+ _ = x[R_POWER_TOC-25]
+ _ = x[R_GOTPCREL-26]
+ _ = x[R_JMPMIPS-27]
+ _ = x[R_DWARFSECREF-28]
+ _ = x[R_DWARFFILEREF-29]
+ _ = x[R_ARM64_TLS_LE-30]
+ _ = x[R_ARM64_TLS_IE-31]
+ _ = x[R_ARM64_GOTPCREL-32]
+ _ = x[R_POWER_TLS_LE-33]
+ _ = x[R_POWER_TLS_IE-34]
+ _ = x[R_POWER_TLS-35]
+ _ = x[R_ADDRPOWER_DS-36]
+ _ = x[R_ADDRPOWER_GOT-37]
+ _ = x[R_ADDRPOWER_PCREL-38]
+ _ = x[R_ADDRPOWER_TOCREL-39]
+ _ = x[R_ADDRPOWER_TOCREL_DS-40]
+ _ = x[R_PCRELDBL-41]
+ _ = x[R_ADDRMIPSU-42]
+ _ = x[R_ADDRMIPSTLS-43]
+ _ = x[R_ADDRCUOFF-44]
+ _ = x[R_WASMIMPORT-45]
+}
+
+const _RelocType_name = "R_ADDRR_ADDRPOWERR_ADDRARM64R_ADDRMIPSR_ADDROFFR_WEAKADDROFFR_SIZER_CALLR_CALLARMR_CALLARM64R_CALL INDR_CALLPOWERR_CALLMIPSR_CONSTR_PCRELR_TLS_LER_TLS_IER_GOTOFFR_PLT0R_PLT1R_PLT2R_USEFIELDR_USETYPER_METHODOFFR_POWER_TOCR_G OTPCRELR_JMPMIPSR_DWARFSECREFR_DWARFFILEREFR_ARM64_TLS_LER_ARM64_TLS_IER_ARM64_GOTPCRELR_POWER_TLS_LER_POWER_TLS_IER_POWER_T LSR_ADDRPOWER_DSR_ADDRPOWER_GOTR_ADDRPOWER_PCRELR_ADDRPOWER_TOCRELR_ADDRPOWER_TOCREL_DSR_PCRELDBLR_ADDRMIPSUR_ADDRMIPSTLSR_A DDRCUOFFR_WASMIMPORT"
-var _RelocType_index = [...]uint16{0, 6, 17, 28, 38, 47, 60, 66, 72, 81, 92, 101, 112, 122, 129, 136, 144, 152, 160, 166, 1 72, 178, 188, 197, 208, 219, 229, 238, 251, 265, 279, 293, 309, 320, 333, 346, 360, 374, 388, 402, 413, 427, 442, 459, 477, 498, 508, 519, 532, 543, 555, 565}
+var _RelocType_index = [...]uint16{0, 6, 17, 28, 38, 47, 60, 66, 72, 81, 92, 101, 112, 122, 129, 136, 144, 152, 160, 166, 1 72, 178, 188, 197, 208, 219, 229, 238, 251, 265, 279, 293, 309, 323, 337, 348, 362, 377, 394, 412, 433, 443, 454, 467, 478, 490}
func (i RelocType) String() string {
i -= 1
diff --git a/src/cmd/internal/objabi/symkind_string.go b/src/cmd/internal/objabi/symkind_string.go
index 2b9a9080e8..399f9b09dc 100644
--- a/src/cmd/internal/objabi/symkind_string.go
+++ b/src/cmd/internal/objabi/symkind_string.go
@@ -4,6 +4,25 @@ package objabi
import "strconv"
+func _() {
+ // An "invalid array index" compiler error signifies that the constant values have changed.
+ // Re-run the stringer command to generate them again.
+ var x [1]struct{}
+ _ = x[Sxxx-0]
+ _ = x[STEXT-1]
+ _ = x[SRODATA-2]
+ _ = x[SNOPTRDATA-3]
+ _ = x[SDATA-4]
+ _ = x[SBSS-5]
+ _ = x[SNOPTRBSS-6]
+ _ = x[STLSBSS-7]
+ _ = x[SDWARFINFO-8]
+ _ = x[SDWARFRANGE-9]
+ _ = x[SDWARFLOC-10]
+ _ = x[SDWARFMISC-11]
+ _ = x[SABIALIAS-12]
+}
+
const _SymKind_name = "SxxxSTEXTSRODATASNOPTRDATASDATASBSSSNOPTRBSSSTLSBSSSDWARFINFOSDWARFRANGESDWARFLOCSDWARFMISCSABIALIAS "
var _SymKind_index = [...]uint8{0, 4, 9, 16, 26, 31, 35, 44, 51, 61, 72, 81, 91, 100}
|
There is something wrong with your diff. What happened to |
Oh, I found the cause. If we are going to use stringer in go-xxx, we should export the root directory of go-xxx as GOROOT and install stringer with go-xxx. The right steps are as follow:
Then we can rebuild /tmp/go successfully. But even if I did nothing, reloctype_string.go and symkind_string.go would still be modified. I don't know if someone changed some code but didn't run "go generate". In addition, this will lead to a lot of file update in vendor/golang.org/x. I think we should update these vendor files. Thank you for your patient guidance. @ianlancetaylor |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
A small change:
$ cd go/src
$ git diff
$ cd cmd/internal/objabi/
$ stringer -type RelocType
$ git diff
$ cd -
$ ./make.bash
PS: the stringer is the latest version
What did you expect to see?
Go was built and installed successfully.
What did you see instead?
Building Go cmd/dist using /home/erifan01/go-master.
Building Go toolchain1 using /home/erifan01/go-master.
# bootstrap/cmd/internal/objabi
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:48: invalid array index R_POWER_TLS_LE - 38 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:49: invalid array index R_POWER_TLS_IE - 39 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:50: invalid array index R_POWER_TLS - 40 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:51: invalid array index R_ADDRPOWER_DS - 41 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:52: invalid array index R_ADDRPOWER_GOT - 42 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:53: invalid array index R_ADDRPOWER_PCREL - 43 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:54: invalid array index R_ADDRPOWER_TOCREL - 44 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:55: invalid array index R_ADDRPOWER_TOCREL_DS - 45 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:56: invalid array index R_PCRELDBL - 46 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:57: invalid array index R_ADDRMIPSU - 47 (out of bounds for 1-element array)
/home/erifan01/go-for-ldst128/src/cmd/internal/objabi/reloctype_string.go:57: too many errors
go tool dist: FAILED: /home/erifan01/go-master/bin/go install -gcflags=-l -tags=math_big_pure_go compiler_bootstrap bootstrap/cmd/...: exit status 2
The text was updated successfully, but these errors were encountered: