This optional cleanup patch fixes some sloppy programming in the
x86 libgo/go/debug/elf library that had given me a very hard time
to debug and fix when porting the code to s390[x].  See commit
comment for details.

ChangeLog
2014-09-05  Dominik Vogt  <v...@linux.vnet.ibm.com>

        * libgo/go/debug/elf/file.go (applyRelocationsAMD64):
        Fix the calculation of some relocations; do not assume that the symbol
        value is always zero.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany
>From 4fce3090be0efb0160cef859e1df6e06196b24e0 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <v...@linux.vnet.ibm.com>
Date: Fri, 5 Sep 2014 07:30:48 +0100
Subject: [PATCH 5/9] LIBGO: Fix some relocations in libgo/elf for amd64.

Adding sym.Value is not really necessary on amd64 as it's always 0 there.  But
on one hand this may change in the future, breaking this code, and on the other
soemone might copy this code for a different platform where sym.Value is not 0.
---
 libgo/go/debug/elf/file.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgo/go/debug/elf/file.go b/libgo/go/debug/elf/file.go
index 38269aa..c70c7b3 100644
--- a/libgo/go/debug/elf/file.go
+++ b/libgo/go/debug/elf/file.go
@@ -562,12 +562,12 @@ func (f *File) applyRelocationsAMD64(dst []byte, rels []byte) error {
 			if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 {
 				continue
 			}
-			f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], uint64(rela.Addend))
+			f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], uint64(rela.Addend) + uint64(sym.Value))
 		case R_X86_64_32:
 			if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 {
 				continue
 			}
-			f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], uint32(rela.Addend))
+			f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], uint32(rela.Addend) + uint32(sym.Value))
 		}
 	}
 
-- 
1.8.4.2

Reply via email to