From patchwork Tue Sep 12 13:01:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 812833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461915-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="paKeog88"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xs4gL6Qp7z9rxl for ; Tue, 12 Sep 2017 23:01:34 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=VSebu5T1seIv9Xft/u1/mbSjGznJ80IbsMvDSEd0QWSV/NKpLb ohtm7nashA037r+PhA31pM7I0VnduI/UsEuod2DCLVqZOQWBvdtsPkdK5GlP5cpk 8WZ6YpU975xw7xKofJUUsK/kTHh279wuj8onrSxSAD1kwrdFNWHNtk/hY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=5u7PnhWy+nFnefDsdn/P50pbe5E=; b=paKeog88l2/QPQX+YP8p 0qdyv9YBeKH0GyUI26PkGGKMsOuAKzANxQpIxfI8uCIy/hi0Yq3QM1kbmmdl/GgV fcU4gH2wr4KJYVyjpdEqhTWwhnFTqrSadRgYPDzyHR214+ueSbTlXKMnV155RfeC ipBKHYwPLShCbuas/ZaHhMQ= Received: (qmail 36960 invoked by alias); 12 Sep 2017 13:01:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 36380 invoked by uid 89); 12 Sep 2017 13:01:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=UD:Machine, UD:Read X-HELO: smtp.CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE (HELO smtp.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Sep 2017 13:01:19 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id A0AB0C95; Tue, 12 Sep 2017 15:01:16 +0200 (CEST) Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id hZ24iaPdHZc9; Tue, 12 Sep 2017 15:01:14 +0200 (CEST) Received: from lokon.CeBiTec.Uni-Bielefeld.DE (lokon.CeBiTec.Uni-Bielefeld.DE [129.70.161.152]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id 33F81C93; Tue, 12 Sep 2017 15:01:14 +0200 (CEST) Received: (from ro@localhost) by lokon.CeBiTec.Uni-Bielefeld.DE (8.15.2+Sun/8.15.2/Submit) id v8CD1Dn3004998; Tue, 12 Sep 2017 15:01:13 +0200 (MEST) From: Rainer Orth To: gcc-patches@gcc.gnu.org Cc: Ian Lance Taylor Subject: [libgo] Support 32-bit SPARC relocs Date: Tue, 12 Sep 2017 15:01:13 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes A couple of gotools tests were FAILing on 32-bit Solaris/SPARC like this: FAIL: TestCgoHandlesWlORIGIN go_test.go:267: running testgo [build origin] go_test.go:286: standard error: go_test.go:287: # origin cannot load DWARF output from $WORK/origin/_obj//_cgo_.o: applyRelocations: not implemented go_test.go:296: go [build origin] failed unexpectedly: exit status 2 The following patch fixes this by implementing applyRelocationsSPARC. It's a straightforward derivative of applyRelocationsSPARC64. The only point of not is support for the SPARC V8Plus ABI, which is the default on Solaris these days. The testcase above PASSes now, a couple of others still FAIL for different reasons. Rainer # HG changeset patch # Parent ec46539a4547c0a3db20b4c0a5309e8fbbe81bd8 Support 32-bit SPARC relocs diff --git a/libgo/go/debug/elf/file.go b/libgo/go/debug/elf/file.go --- a/libgo/go/debug/elf/file.go +++ b/libgo/go/debug/elf/file.go @@ -600,6 +600,8 @@ func (f *File) applyRelocations(dst []by return f.applyRelocationsMIPS64(dst, rels) case f.Class == ELFCLASS64 && f.Machine == EM_S390: return f.applyRelocationss390x(dst, rels) + case f.Class == ELFCLASS32 && (f.Machine == EM_SPARC || f.Machine == EM_SPARC32PLUS): + return f.applyRelocationsSPARC(dst, rels) case f.Class == ELFCLASS64 && f.Machine == EM_SPARCV9: return f.applyRelocationsSPARC64(dst, rels) case f.Class == ELFCLASS64 && f.Machine == EM_ALPHA: @@ -1006,6 +1008,46 @@ func (f *File) applyRelocationss390x(dst return nil } +func (f *File) applyRelocationsSPARC(dst []byte, rels []byte) error { + // 12 is the size of Rela32. + if len(rels)%12 != 0 { + return errors.New("length of relocation section is not a multiple of 12") + } + + symbols, _, err := f.getSymbols(SHT_SYMTAB) + if err != nil { + return err + } + + b := bytes.NewReader(rels) + var rela Rela32 + + for b.Len() > 0 { + binary.Read(b, f.ByteOrder, &rela) + symNo := rela.Info >> 32 + t := R_SPARC(rela.Info & 0xff) + + if symNo == 0 || symNo > uint32(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_32, R_SPARC_UA32: + if rela.Off+4 >= uint32(len(dst)) || rela.Addend < 0 { + continue + } + f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], uint32(rela.Addend)) + } + } + + return nil +} + func (f *File) applyRelocationsSPARC64(dst []byte, rels []byte) error { // 24 is the size of Rela64. if len(rels)%24 != 0 {