From 68f55700320cb6d4d5a63a6c1e0f2c4f31c01203 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 20 Apr 2015 11:53:20 +1200 Subject: [PATCH] cmd/link, cmd/internal/goobj: update constants, regenerate testdata The constants in cmd/internal/goobj had gone stale (we had three copies of these constants, working on reducing that was what got me to noticing this). Some of the changes to link.hello.darwin.amd64 are the change from absolute to %rip-relative addressing, a change which happened quite a while ago... Depends on http://golang.org/cl/9113. Fixes #10501. Change-Id: Iaa1511f458a32228c2df2ccd0076bb9ae212a035 Reviewed-on: https://go-review.googlesource.com/9105 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/cmd/internal/goobj/read.go | 68 +++++++++--------- src/cmd/link/load.go | 20 ++---- src/cmd/link/pclntab.go | 3 +- src/cmd/link/testdata/Makefile | 2 +- src/cmd/link/testdata/autosection.6 | Bin 942 -> 937 bytes src/cmd/link/testdata/autoweak.6 | Bin 387 -> 386 bytes src/cmd/link/testdata/dead.6 | Bin 854 -> 849 bytes src/cmd/link/testdata/hello.6 | Bin 233 -> 229 bytes src/cmd/link/testdata/layout.6 | Bin 391 -> 396 bytes src/cmd/link/testdata/link.hello.darwin.amd64 | 37 +++++----- src/cmd/link/testdata/pclntab.6 | Bin 3809 -> 3804 bytes 11 files changed, 63 insertions(+), 67 deletions(-) diff --git a/src/cmd/internal/goobj/read.go b/src/cmd/internal/goobj/read.go index 79a83e59a6..1b0c9646bc 100644 --- a/src/cmd/internal/goobj/read.go +++ b/src/cmd/internal/goobj/read.go @@ -12,6 +12,7 @@ package goobj import ( "bufio" "bytes" + "cmd/internal/obj" "errors" "fmt" "io" @@ -31,45 +32,46 @@ const ( _ SymKind = iota // readonly, executable - STEXT - SELFRXSECT + STEXT SymKind = obj.STEXT + SELFRXSECT SymKind = obj.SELFRXSECT // readonly, non-executable - STYPE - SSTRING - SGOSTRING - SGOFUNC - SRODATA - SFUNCTAB - STYPELINK - SSYMTAB // TODO: move to unmapped section - SPCLNTAB - SELFROSECT + STYPE SymKind = obj.STYPE + SSTRING SymKind = obj.SSTRING + SGOSTRING SymKind = obj.SGOSTRING + SGOFUNC SymKind = obj.SGOFUNC + SRODATA SymKind = obj.SRODATA + SFUNCTAB SymKind = obj.SFUNCTAB + STYPELINK SymKind = obj.STYPELINK + SSYMTAB SymKind = obj.SSYMTAB // TODO: move to unmapped section + SPCLNTAB SymKind = obj.SPCLNTAB + SELFROSECT SymKind = obj.SELFROSECT // writable, non-executable - SMACHOPLT - SELFSECT - SMACHO // Mach-O __nl_symbol_ptr - SMACHOGOT - SNOPTRDATA - SINITARR - SDATA - SWINDOWS - SBSS - SNOPTRBSS - STLSBSS + SMACHOPLT SymKind = obj.SMACHOPLT + SELFSECT SymKind = obj.SELFSECT + SMACHO SymKind = obj.SMACHO // Mach-O __nl_symbol_ptr + SMACHOGOT SymKind = obj.SMACHOGOT + SWINDOWS SymKind = obj.SWINDOWS + SELFGOT SymKind = obj.SELFGOT + SNOPTRDATA SymKind = obj.SNOPTRDATA + SINITARR SymKind = obj.SINITARR + SDATA SymKind = obj.SDATA + SBSS SymKind = obj.SBSS + SNOPTRBSS SymKind = obj.SNOPTRBSS + STLSBSS SymKind = obj.STLSBSS // not mapped - SXREF - SMACHOSYMSTR - SMACHOSYMTAB - SMACHOINDIRECTPLT - SMACHOINDIRECTGOT - SFILE - SFILEPATH - SCONST - SDYNIMPORT - SHOSTOBJ + SXREF SymKind = obj.SXREF + SMACHOSYMSTR SymKind = obj.SMACHOSYMSTR + SMACHOSYMTAB SymKind = obj.SMACHOSYMTAB + SMACHOINDIRECTPLT SymKind = obj.SMACHOINDIRECTPLT + SMACHOINDIRECTGOT SymKind = obj.SMACHOINDIRECTGOT + SFILE SymKind = obj.SFILE + SFILEPATH SymKind = obj.SFILEPATH + SCONST SymKind = obj.SCONST + SDYNIMPORT SymKind = obj.SDYNIMPORT + SHOSTOBJ SymKind = obj.SHOSTOBJ ) var symKindStrings = []string{ diff --git a/src/cmd/link/load.go b/src/cmd/link/load.go index ca0c24c978..50602b82a1 100644 --- a/src/cmd/link/load.go +++ b/src/cmd/link/load.go @@ -6,7 +6,10 @@ package main -import "os" +import ( + "cmd/internal/obj" + "os" +) // load allocates segment images, populates them with data // read from package files, and applies relocations to the data. @@ -73,17 +76,6 @@ func (p *Prog) loadPackage(pkg *Package) { } } -// TODO(rsc): Define full enumeration for relocation types. -const ( - R_ADDR = 1 - R_SIZE = 2 - R_CALL = 3 - R_CALLARM = 4 - R_CALLIND = 5 - R_CONST = 6 - R_PCREL = 7 -) - // relocateSym applies relocations to sym's data. func (p *Prog) relocateSym(sym *Sym, data []byte) { for i := range sym.Reloc { @@ -97,9 +89,9 @@ func (p *Prog) relocateSym(sym *Sym, data []byte) { switch r.Type { default: p.errorf("%v: unknown relocation type %d", sym, r.Type) - case R_ADDR, R_CALLIND: + case obj.R_ADDR, obj.R_CALLIND: // ok - case R_PCREL, R_CALL: + case obj.R_PCREL, obj.R_CALL: val -= sym.Addr + Addr(r.Offset+r.Size) } frag := data[r.Offset : r.Offset+r.Size] diff --git a/src/cmd/link/pclntab.go b/src/cmd/link/pclntab.go index 2d131781f2..7f8bf52a9b 100644 --- a/src/cmd/link/pclntab.go +++ b/src/cmd/link/pclntab.go @@ -8,6 +8,7 @@ package main import ( "cmd/internal/goobj" + "cmd/internal/obj" "encoding/binary" "os" "sort" @@ -371,7 +372,7 @@ func (b *SymBuffer) Addr(off int, sym goobj.SymID, symoff int64) int { Size: b.ptrsize, Sym: sym, Add: int(symoff), - Type: R_ADDR, + Type: obj.R_ADDR, }) return off + b.ptrsize } diff --git a/src/cmd/link/testdata/Makefile b/src/cmd/link/testdata/Makefile index e9651a03f6..83e8a05195 100644 --- a/src/cmd/link/testdata/Makefile +++ b/src/cmd/link/testdata/Makefile @@ -9,7 +9,7 @@ ALL=\ all: $(ALL) %.6: %.s - GOARCH=amd64 GOOS=darwin go tool 6a -trimpath=$(shell pwd) $*.s + GOARCH=amd64 GOOS=darwin go tool asm -I $(shell go env GOROOT)/pkg/include -trimpath=$(shell pwd) $*.s pclntab.s: genpcln.go go run genpcln.go >pclntab.s diff --git a/src/cmd/link/testdata/autosection.6 b/src/cmd/link/testdata/autosection.6 index 386f422cf30200674aa2f8676626bb33a126e79e..34aa5d3dbbc9219f9866cc7b0f1933dcc8c1024e 100644 GIT binary patch delta 157 zcmZ3-zLI@{ys}YZijjq}f^UAFf@49Ef{}rOp{13vg_VIBkZowHplxV0(Oq9qjDdkK zv9u(=Br%DBfkA{rY+}2mk`6~zYEeD|g8)#7;h&xmh?kdNP*TLepa2%q+4!iDNlb?? lFFy~Wl7oSPgAt;7awW5@gbvtHunv$Y!~g&3`G&?hDF6l8C({4` delta 186 zcmZ3IIzk{`UVcGI5d(t)SV(K* z-9{#FExx?`JcvpT1_lmBh-wL_AXEd;3;`yP3<&(w0$T<)2`upce|o;5aZU;Vhq^85 diff --git a/src/cmd/link/testdata/autoweak.6 b/src/cmd/link/testdata/autoweak.6 index 5d74d4e2b56448feed209262e4e3aa8e1eed8674..a86b84117137d7a564acb97639707304ac1f06db 100644 GIT binary patch delta 221 zcmZo>ZepGwS8r^Tm||pMtl*oUr{Gvnq+n#AU}$M&Y++?!24owWDrg%T85nRWaxpNZ z=NlU5q%bo4W8x|XLyUoeFR`>Fza%jUC?Nvp7nBqM z`Tv1{pMi;ifsILkflUTT@CmUqu`>Zh7??yr`pQ!iv-OIZ{^?BIHQ7vut++B5CuDAXq=P6$ncMetGFbwsDyz@fq_A62Llj*iNh>R983%he2Jwc`6Y=-Kw%y@ zzo4WD$o~%n{0u-fY)k?SvLJ#_h?R+zi47>nBm&Y`o|>4gSIqQJYvRtyW?F2;mAOC} bpe(~bExwf0#1s?(kOqjsAQk`rLmUVImo7Bx diff --git a/src/cmd/link/testdata/dead.6 b/src/cmd/link/testdata/dead.6 index 9540adc1aff7df54fcb89a845b3d6e988c37a23a..5e9b09c03ee8598c6dd63b0f2efc0e512fe3798e 100644 GIT binary patch delta 227 zcmcb{c9Cs@ys}YZijjq}f^UAFf@49Ef{}rOp{13vg_VIBkZowHplxV0(cMHrjDdkG zC9x#YkcojofP)LjD@m;=F=Sw1kmCT!O-{j?tTNrgF$1qtL>VQo*VqgH8&%p2x!Zn6-1=33Ml0k+6je;nce4NP>s8^6# PSX2jL7edEmOJ-RB_r)`k delta 271 zcmcb}c8zUSqcCj|ha$Uw#b diff --git a/src/cmd/link/testdata/hello.6 b/src/cmd/link/testdata/hello.6 index 67983f1a9f8bfec2d1fac59bcaea3016f3bb3e8c..890cbbd016f76da8ddd5504d6ee9f947d7db038f 100644 GIT binary patch delta 153 zcmaFK_>^&ioR_gtVv3Q4v4U@Yo`PdRk%Ezdf}y3Av4xd^8IWygs-SIXWMIIh$i={r zo^NQJlfuaGkBKk7sKg*XJ)eOofq}tkKO+MJL$B$?9BD^B4lxD>u8h>2oO~t*hW|jo n&j4hwF&Tid8XGGU8xt!Kf&hpV0BU9818dMLX8NZy@q{7(+wLKI literal 233 zcmXv|O>4qH6dWH$N)Wwzd|rA`T6Sab>tugLj}o(MR8|*aG=D94Xb=7`^);dMn8z?M z!(^WQ=3vu;O_G=U6DLPAjoH|%bv!nSiRV$YNz?6?zpde~OU7!-S}mjbQZG1CI_3{G zQz{&WK<4$tnHC<@TjzyZXCAZyR=+I(KSJEP@~SpK{Xjn}@kQLJ`$j;xv(9-DPeC6d mI>a^KI{`IEfWt0Cha`< zg^=VI{>d-d2^8^Xven3$Jbq-z_I&b&Jo!#i^rMjRa2nxCWcYrN7*Y&o^JqG!6EhFS z=m#OCZr=sii6BaO19IZ&N#$04$g1CouJBxVTNH1K>%)nPzKs+M9r9Q7;n* zEo*dOX}bof1+7@Azu3aAyJf6`g{fB{08K*6-s?V-TYE8=k#@>X;!BSd$y@(C8~~?b cACQmkWvZ=V&8S8zEd%WdcU~neir>$>0*(M*1poj5 literal 391 zcmZvYUu(iJ5WueiXDOreL5BErd-cyqYjNt6`xHJ(+Qgz%Gn%;RH{1KZS8LL3w2BuJ z$nSD@Kaxt6@lGTfIm^Gc2V{FbjgX5^k>QXt9?ilqPLjBA8=H zg9yj;jZ*K$14v~s$+!ar>1uJ(Yo%GPfh+-{Z!mH1`0nL0IS7&U0EWuWbF<5khJ{Qa^E@}OU6 diff --git a/src/cmd/link/testdata/link.hello.darwin.amd64 b/src/cmd/link/testdata/link.hello.darwin.amd64 index 0bd475dd81..4c62eb19b4 100644 --- a/src/cmd/link/testdata/link.hello.darwin.amd64 +++ b/src/cmd/link/testdata/link.hello.darwin.amd64 @@ -6,23 +6,23 @@ * 00000060 00 00 00 00 00 00 00 00 19 00 00 00 38 01 00 00 |............8...| 00000070 5f 5f 54 45 58 54 00 00 00 00 00 00 00 00 00 00 |__TEXT..........| -00000080 00 10 00 00 00 00 00 00 b0 10 00 00 00 00 00 00 |................| -00000090 00 00 00 00 00 00 00 00 b0 10 00 00 00 00 00 00 |................| +00000080 00 10 00 00 00 00 00 00 c0 10 00 00 00 00 00 00 |................| +00000090 00 00 00 00 00 00 00 00 c0 10 00 00 00 00 00 00 |................| 000000a0 07 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 |................| 000000b0 5f 5f 74 65 78 74 00 00 00 00 00 00 00 00 00 00 |__text..........| 000000c0 5f 5f 54 45 58 54 00 00 00 00 00 00 00 00 00 00 |__TEXT..........| -000000d0 00 20 00 00 00 00 00 00 20 00 00 00 00 00 00 00 |. ...... .......| +000000d0 00 20 00 00 00 00 00 00 30 00 00 00 00 00 00 00 |. ......0.......| 000000e0 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000000f0 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000100 5f 5f 72 6f 64 61 74 61 00 00 00 00 00 00 00 00 |__rodata........| 00000110 5f 5f 54 45 58 54 00 00 00 00 00 00 00 00 00 00 |__TEXT..........| -00000120 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ..............| -00000130 20 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ...............| +00000120 30 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |0 ..............| +00000130 30 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |0...............| * 00000150 5f 5f 66 75 6e 63 74 61 62 00 00 00 00 00 00 00 |__functab.......| 00000160 5f 5f 54 45 58 54 00 00 00 00 00 00 00 00 00 00 |__TEXT..........| -00000170 20 20 00 00 00 00 00 00 90 00 00 00 00 00 00 00 | ..............| -00000180 20 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ...............| +00000170 30 20 00 00 00 00 00 00 90 00 00 00 00 00 00 00 |0 ..............| +00000180 30 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |0...............| * 000001a0 19 00 00 00 98 00 00 00 5f 5f 44 41 54 41 00 00 |........__DATA..| 000001b0 00 00 00 00 00 00 00 00 00 30 00 00 00 00 00 00 |.........0......| @@ -38,17 +38,18 @@ * 000002c0 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00 00 |......... ......| * -00001000 bf 01 00 00 00 be 00 30 00 00 ba 0c 00 00 00 b8 |.......0........| -00001010 04 00 00 02 0f 05 31 ff b8 01 00 00 02 0f 05 c3 |......1.........| -00001020 fb ff ff ff 00 00 01 08 01 00 00 00 00 00 00 00 |................| -00001030 00 20 00 00 00 00 00 00 30 00 00 00 00 00 00 00 |. ......0.......| -00001040 20 20 00 00 00 00 00 00 80 00 00 00 00 00 00 00 | ..............| -00001050 00 20 00 00 00 00 00 00 58 00 00 00 00 00 00 80 |. ......X.......| -00001060 08 00 00 00 60 00 00 00 63 00 00 00 66 00 00 00 |....`...c...f...| -00001070 00 00 00 00 00 00 00 00 5f 72 74 30 5f 67 6f 00 |........_rt0_go.| -00001080 02 20 00 04 20 00 06 05 02 05 02 05 02 05 02 02 |. .. ...........| -00001090 02 02 02 05 02 02 02 01 00 00 00 00 00 00 00 00 |................| -000010a0 02 00 00 00 88 00 00 00 68 65 6c 6c 6f 2e 73 00 |........hello.s.| +00001000 bf 01 00 00 00 8d 35 f5 0f 00 00 ba 0c 00 00 00 |......5.........| +00001010 b8 04 00 00 02 0f 05 31 ff b8 01 00 00 02 0f 05 |.......1........| +00001020 c3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00001030 fb ff ff ff 00 00 01 08 01 00 00 00 00 00 00 00 |................| +00001040 00 20 00 00 00 00 00 00 30 00 00 00 00 00 00 00 |. ......0.......| +00001050 30 20 00 00 00 00 00 00 80 00 00 00 00 00 00 00 |0 ..............| +00001060 00 20 00 00 00 00 00 00 58 00 00 00 00 00 00 80 |. ......X.......| +00001070 08 00 00 00 60 00 00 00 63 00 00 00 66 00 00 00 |....`...c...f...| +00001080 00 00 00 00 00 00 00 00 5f 72 74 30 5f 67 6f 00 |........_rt0_go.| +00001090 02 30 00 04 30 00 06 05 02 06 02 05 02 05 02 02 |.0..0...........| +000010a0 02 02 02 05 02 02 02 10 00 00 00 00 00 00 00 00 |................| +000010b0 02 00 00 00 88 00 00 00 68 65 6c 6c 6f 2e 73 00 |........hello.s.| * 00002000 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a |hello world.| 0000200c diff --git a/src/cmd/link/testdata/pclntab.6 b/src/cmd/link/testdata/pclntab.6 index 9e7f9afdb044460e718d53c00afda317251c6351..8156698265f7f60821a1888b108470936b70b1e4 100644 GIT binary patch delta 159 zcmaDTdq;MHys}YZijjq}f^UAFf@49Ef{}rOp{13vg_VIBkZowHplxWh(fvKIHWvc} zS6XRavH=4F0}ls`X9(np!FfhNo(hN9XgKiM4%1@pajD|gb+|0x)4w= OSm^)%^n63(oD=}PBqluo delta 164 zcmca3`%rd*yoQ09rG=rng{h%svO;)jih^Tlx`L6pf}x3(sgaeDse+M#p^1X7fyqXv z_q^I{3=CXprFqE)3=9lB959|CkS7M`83B1J9DI{w_#7Oxgg~lO5=#<+Iuw8s4F3>9 UKyBzkK)qn0|NqnT4UKbB07W4t^Z)<=