public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [libgo] Support 32-bit SPARC relocs
@ 2017-09-12 13:01 Rainer Orth
  2017-09-29 14:36 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Rainer Orth @ 2017-09-12 13:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ian Lance Taylor

[-- Attachment #1: Type: text/plain, Size: 1015 bytes --]

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

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2017-09-11  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* go/debug/elf/file.go (applyRelocations): Handle 32-bit SPARC.
	(applyRelocationsSPARC): New function.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sol2sparc-libgo-32bit-relocs.patch --]
[-- Type: text/x-patch, Size: 1857 bytes --]

# 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 {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [libgo] Support 32-bit SPARC relocs
  2017-09-12 13:01 [libgo] Support 32-bit SPARC relocs Rainer Orth
@ 2017-09-29 14:36 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2017-09-29 14:36 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches, gofrontend-dev

On Tue, Sep 12, 2017 at 6:01 AM, Rainer Orth
<ro@cebitec.uni-bielefeld.de> wrote:
> 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
>
> --
> -----------------------------------------------------------------------------
> Rainer Orth, Center for Biotechnology, Bielefeld University
>
>
> 2017-09-11  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>
>         * go/debug/elf/file.go (applyRelocations): Handle 32-bit SPARC.
>         (applyRelocationsSPARC): New function.


Thanks.  Committed.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-29 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-12 13:01 [libgo] Support 32-bit SPARC relocs Rainer Orth
2017-09-29 14:36 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).