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 769defcc2210..cadd8ec1b310 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 c173ea933169..c1cbfa622541 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 b189219a556a..f1e28a067159 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 zc-pO4eQX@X6`$R`bIv||KKlaL2@MyiB&6Z)e6H&{B*Z3Z0wxF|(T}JtEW3B>^D2A0 z$9_0Y0g(pUx)Q;pC@4Y!0aZ~7RRNWcs%ll#R8_@4(DF}Isa2&`RmFdy5+9{)I&bFP zdHr&GLTXp`y!U?dzUIx_xw(5_->v&qRbib+VcW&n^%;RdWwSzkg`I{{ipt@#=LXMBEB@|#=_a8%{ zz{f8hM`1npWQ)?6gKnm-bYc`#>W$c_8@1z z&E(vsHo7d(0)t|(AsKup;K=Wa@izc3oSxyWp}w3KJ@Y(-m+T9x?2kHZ-v-Eu$5UVD z|Nj_z6@l!VS0$OJPRP8wQdUok|`)!E}I2gh}S>Z zaWu`f2T)8)G20HqUtL9+D}cq|X6~oLkz9dK?i%BTo$MIRi~*3J>^POcFf`LhS(zD= z_|`F4$n5Cjd&aGkeN82ZYc!4vCrv-W568f*Dl#g?ROi>g(nv_Zu_!Y-CD~(#M z60{7zHZ@stY&TjeHQcB&Rk7Wg6V)vy6jA7+Xxd@0Mh8#2at)#fVZCn6mlq&pc(i2& zoaOoOxVFbxO=xu3qk(SuzGDZWRO7p#w%2jRfdi_>7ogAGuA9-kZn<@)drn>V=H~+| z6vi&MW}pxli`H^AQ9HK1N9@m9a?%TZ{t2In2q0a;H$WwqscwS&7Jv0;@i; zS_!C`tnnIWB3je1`9fT4i96R@M!hP@ge0GpWKxpP$r4_Ykqj>O8a8ZdQV-*+@S;$c zGl27`wk(~=3mmm%(qgf=u{?Iu<1O0BUoLAgG)%{ecZ6slX};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