From d2c4425e86310d44aa8e9f9d91b49e2e61237ef2 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 14 Oct 2016 17:16:55 +0000 Subject: [PATCH] debug/elf: add sparc64 relocations This is a backport of https://go-review.googlesource.com/30870. Reviewed-on: https://go-review.googlesource.com/30916 From-SVN: r241171 --- gcc/go/gofrontend/MERGE | 2 +- libgo/go/debug/elf/file.go | 47 ++++++++++++++++++ libgo/go/debug/elf/file_test.go | 19 +++++++ .../go-relocation-test-gcc620-sparc64.obj | Bin 0 -> 5952 bytes 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 libgo/go/debug/elf/testdata/go-relocation-test-gcc620-sparc64.obj diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 769defcc221..cadd8ec1b31 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -5f043fc2bf0f92a84a1f7da57acd79a61c9d2592 +911fceabd4c955b2f29f6b532f241a002ca7ad4f The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/debug/elf/file.go b/libgo/go/debug/elf/file.go index c173ea93316..c1cbfa62254 100644 --- a/libgo/go/debug/elf/file.go +++ b/libgo/go/debug/elf/file.go @@ -598,6 +598,8 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error { return f.applyRelocationsMIPS64(dst, rels) case f.Class == ELFCLASS64 && f.Machine == EM_S390: return f.applyRelocationss390x(dst, rels) + case f.Class == ELFCLASS64 && f.Machine == EM_SPARCV9: + return f.applyRelocationsSPARC64(dst, rels) default: return errors.New("applyRelocations: not implemented") } @@ -962,6 +964,51 @@ func (f *File) applyRelocationss390x(dst []byte, rels []byte) error { return nil } +func (f *File) applyRelocationsSPARC64(dst []byte, rels []byte) error { + // 24 is the size of Rela64. + if len(rels)%24 != 0 { + return errors.New("length of relocation section is not a multiple of 24") + } + + symbols, _, err := f.getSymbols(SHT_SYMTAB) + if err != nil { + return err + } + + b := bytes.NewReader(rels) + var rela Rela64 + + for b.Len() > 0 { + binary.Read(b, f.ByteOrder, &rela) + symNo := rela.Info >> 32 + t := R_SPARC(rela.Info & 0xffff) + + if symNo == 0 || symNo > uint64(len(symbols)) { + continue + } + sym := &symbols[symNo-1] + if SymType(sym.Info&0xf) != STT_SECTION { + // We don't handle non-section relocations for now. + continue + } + + switch t { + case R_SPARC_64, R_SPARC_UA64: + if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { + continue + } + f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], uint64(rela.Addend)) + case R_SPARC_32, R_SPARC_UA32: + if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { + continue + } + f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], uint32(rela.Addend)) + } + } + + return nil +} + func (f *File) DWARF() (*dwarf.Data, error) { // sectionData gets the data for s, checks its size, and // applies any applicable relations. diff --git a/libgo/go/debug/elf/file_test.go b/libgo/go/debug/elf/file_test.go index b189219a556..f1e28a06715 100644 --- a/libgo/go/debug/elf/file_test.go +++ b/libgo/go/debug/elf/file_test.go @@ -491,6 +491,25 @@ var relocationTests = []relocationTest{ }}, }, }, + { + "testdata/go-relocation-test-gcc620-sparc64.obj", + []relocationTestEntry{ + {0, &dwarf.Entry{ + Offset: 0xb, + Tag: dwarf.TagCompileUnit, + Children: true, + Field: []dwarf.Field{ + {Attr: dwarf.AttrProducer, Val: "GNU C11 6.2.0 20160914 -mcpu=v9 -g -fstack-protector-strong", Class: dwarf.ClassString}, + {Attr: dwarf.AttrLanguage, Val: int64(12), Class: dwarf.ClassConstant}, + {Attr: dwarf.AttrName, Val: "hello.c", Class: dwarf.ClassString}, + {Attr: dwarf.AttrCompDir, Val: "/tmp", Class: dwarf.ClassString}, + {Attr: dwarf.AttrLowpc, Val: uint64(0x0), Class: dwarf.ClassAddress}, + {Attr: dwarf.AttrHighpc, Val: int64(0x2c), Class: dwarf.ClassConstant}, + {Attr: dwarf.AttrStmtList, Val: int64(0), Class: dwarf.ClassLinePtr}, + }, + }}, + }, + }, { "testdata/go-relocation-test-gcc493-mips64le.obj", []relocationTestEntry{ diff --git a/libgo/go/debug/elf/testdata/go-relocation-test-gcc620-sparc64.obj b/libgo/go/debug/elf/testdata/go-relocation-test-gcc620-sparc64.obj new file mode 100644 index 0000000000000000000000000000000000000000..d65c23e1cbeaad5acc30d7d256931443ac8aea2a GIT binary patch literal 5952 zcmbtXYiwLc6`r|w?X2zCvE#Nlw4@t}CM~hob}%Ms)5c9m8aGvm1e6K_+kITytL&@y z?j{ZeHKaU@L~sL2RiPHOAgWLh4*@MgASyrz@uvm;L`Wbc5JLUeBGE#D@O?AquIFAm zf8c2E%sJnj$IO}MK79C|Bc7*Km$cdq-T}HTV75~5)Eq06*Q%{g{^=*j&kd`wS5II1 z^iOwPde}$9qr(pv6*}Sf@fZJ?jU6rpwOVsLce)wYDroW#sthV++c%TlfX0b=rnro9 zubF%PhjRQKnX#8K! zyn^W4`v9oSt0+p!@~?qk&079-^23(@2l+9}|C4;q@^6s8+4BD)KV|uUlizFk|B#>S zN2xLVZ~|mZZebkG{<}qVmJuq zQ_8k&kI@x_jw&WYZDEnow?TVF`27xlJ9*>u2`mloJHu4(c^2#m%YJ>0{YIDVeKWL5 zi03_z?{6cDwtqDSz1I^lJ4%~9K!-x(8pHJua4M8(EcqAC>aOS?@Gq=rGZ?k1^oYJ` zXmr3Ix_)RxZ{0NfCiuNh`9rr3+%_-|8~?3pVBik4V|cu4{u`$g=TAEh`Dhf!*?*7KvZ7~BCrlV}_oh3WonNbHRD0iy%k2n-8= zxE2`UV%nP52e#Q>@7l(J%#A&Ea2s8Y_H;YpVGWYT?Qvk%hDFxO@in%~y=e5G%jh?T z29*Y(1)rYmMB!wuTAExemnWlEF)Yu{Ow_84&ho@!qcb@>S#6YSol2mLq6ix(ma6S2 zp`(;J>GEZEA!=7D!9sqCA=_tKK?D{%7;&pjusAcJ(Phs>g&+)T)u?UNFbn3iqNnS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