Re: [PATCH, alpha, go]: Introduce applyRelocationsALPHA

2017-06-26 Thread Ian Lance Taylor
On Thu, Jun 22, 2017 at 12:13 AM, Uros Bizjak  wrote:
>
> However, there is one another issue with zdefaultcc.go generation. On
> my system, the default gccgo, gcc and g++ are installed in:
>
> $ which gccgo
> /usr/bin/gccgo
> $ which gcc
> /usr/bin/gcc
>
> but gotools Makefile uses $(bindir) to derive absolute path to the binaries:
>
> echo 'package main' > zdefaultcc.go.tmp
> echo 'const defaultGCCGO = "$(bindir)/$(GCCGO_INSTALL_NAME)"'
>>> zdefaultcc.go.tmp
> echo 'const defaultCC = "$(bindir)/$(GCC_INSTALL_NAME)"' >>
> zdefaultcc.go.tmp
> echo 'const defaultCXX = "$(bindir)/$(GXX_INSTALL_NAME)"' >>
> zdefaultcc.go.tmp
> echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp
>
> However, since $prefix (by default) points to /usr/local, $bindir
> points to /usr/local/bin. Consequently, zdefaultcc.go reads:
>
> package main
> const defaultGCCGO = "/usr/local/bin/gccgo"
> const defaultCC = "/usr/local/bin/gcc"
> const defaultCXX = "/usr/local/bin/g++"
> const defaultPkgConfig = "pkg-config"
>
> The absolute path is wrong, since - as mentioned above - the system
> compiler is installed in /usr/bin.
>
> Probably we just need to remove $bindir and assume that these binaries
> exist in $PATH.

I did that for defaultCC and defaultCXX, as appended.

Ian


2017-06-26  Ian Lance Taylor  

* Makefile.am (s-zdefaultcc): Don't record $(bindir) for defaultCC
or defaultCXX.
* Makefile.in: Rebuild.
Index: Makefile.am
===
--- Makefile.am (revision 249668)
+++ Makefile.am (working copy)
@@ -100,8 +100,8 @@ zdefaultcc.go: s-zdefaultcc; @true
 s-zdefaultcc: Makefile
echo 'package main' > zdefaultcc.go.tmp
echo 'const defaultGCCGO = "$(bindir)/$(GCCGO_INSTALL_NAME)"' >> 
zdefaultcc.go.tmp
-   echo 'const defaultCC = "$(bindir)/$(GCC_INSTALL_NAME)"' >> 
zdefaultcc.go.tmp
-   echo 'const defaultCXX = "$(bindir)/$(GXX_INSTALL_NAME)"' >> 
zdefaultcc.go.tmp
+   echo 'const defaultCC = "$(GCC_INSTALL_NAME)"' >> zdefaultcc.go.tmp
+   echo 'const defaultCXX = "$(GXX_INSTALL_NAME)"' >> zdefaultcc.go.tmp
echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp
$(SHELL) $(srcdir)/../move-if-change zdefaultcc.go.tmp zdefaultcc.go
$(STAMP) $@ 
Index: Makefile.in
===
--- Makefile.in (revision 249668)
+++ Makefile.in (working copy)
@@ -582,8 +582,8 @@ distclean-generic:
 maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
-@NATIVE_FALSE@uninstall-local:
 @NATIVE_FALSE@install-exec-local:
+@NATIVE_FALSE@uninstall-local:
 clean: clean-am
 
 clean-am: clean-binPROGRAMS clean-generic clean-noinstPROGRAMS \
@@ -682,8 +682,8 @@ zdefaultcc.go: s-zdefaultcc; @true
 s-zdefaultcc: Makefile
echo 'package main' > zdefaultcc.go.tmp
echo 'const defaultGCCGO = "$(bindir)/$(GCCGO_INSTALL_NAME)"' >> 
zdefaultcc.go.tmp
-   echo 'const defaultCC = "$(bindir)/$(GCC_INSTALL_NAME)"' >> 
zdefaultcc.go.tmp
-   echo 'const defaultCXX = "$(bindir)/$(GXX_INSTALL_NAME)"' >> 
zdefaultcc.go.tmp
+   echo 'const defaultCC = "$(GCC_INSTALL_NAME)"' >> zdefaultcc.go.tmp
+   echo 'const defaultCXX = "$(GXX_INSTALL_NAME)"' >> zdefaultcc.go.tmp
echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp
$(SHELL) $(srcdir)/../move-if-change zdefaultcc.go.tmp zdefaultcc.go
$(STAMP) $@ 


Re: [PATCH, alpha, go]: Introduce applyRelocationsALPHA

2017-06-22 Thread Uros Bizjak
On Thu, Jun 22, 2017 at 12:39 AM, Ian Lance Taylor  wrote:
> On Tue, Jun 20, 2017 at 12:46 PM, Uros Bizjak  wrote:
>> This patch inroduces applyRelocationsALPHA to solve:
>>
>> FAIL: TestCgoConsistentResults
>> FAIL: TestCgoPkgConfig
>> FAIL: TestCgoHandlesWlORIGIN
>>
>> gotools errors.
>>
>> Bootstrapped and regression tested on alphaev68-linux-gnu.
>
> Thanks!  Committed to mainline.

Thanks!

However, there is one another issue with zdefaultcc.go generation. On
my system, the default gccgo, gcc and g++ are installed in:

$ which gccgo
/usr/bin/gccgo
$ which gcc
/usr/bin/gcc

but gotools Makefile uses $(bindir) to derive absolute path to the binaries:

echo 'package main' > zdefaultcc.go.tmp
echo 'const defaultGCCGO = "$(bindir)/$(GCCGO_INSTALL_NAME)"'
>> zdefaultcc.go.tmp
echo 'const defaultCC = "$(bindir)/$(GCC_INSTALL_NAME)"' >>
zdefaultcc.go.tmp
echo 'const defaultCXX = "$(bindir)/$(GXX_INSTALL_NAME)"' >>
zdefaultcc.go.tmp
echo 'const defaultPkgConfig = "pkg-config"' >> zdefaultcc.go.tmp

However, since $prefix (by default) points to /usr/local, $bindir
points to /usr/local/bin. Consequently, zdefaultcc.go reads:

package main
const defaultGCCGO = "/usr/local/bin/gccgo"
const defaultCC = "/usr/local/bin/gcc"
const defaultCXX = "/usr/local/bin/g++"
const defaultPkgConfig = "pkg-config"

The absolute path is wrong, since - as mentioned above - the system
compiler is installed in /usr/bin.

Probably we just need to remove $bindir and assume that these binaries
exist in $PATH.

Uros.


Re: [PATCH, alpha, go]: Introduce applyRelocationsALPHA

2017-06-21 Thread Ian Lance Taylor
On Tue, Jun 20, 2017 at 12:46 PM, Uros Bizjak  wrote:
> This patch inroduces applyRelocationsALPHA to solve:
>
> FAIL: TestCgoConsistentResults
> FAIL: TestCgoPkgConfig
> FAIL: TestCgoHandlesWlORIGIN
>
> gotools errors.
>
> Bootstrapped and regression tested on alphaev68-linux-gnu.

Thanks!  Committed to mainline.

Ian


[PATCH, alpha, go]: Introduce applyRelocationsALPHA

2017-06-20 Thread Uros Bizjak
This patch inroduces applyRelocationsALPHA to solve:

FAIL: TestCgoConsistentResults
FAIL: TestCgoPkgConfig
FAIL: TestCgoHandlesWlORIGIN

gotools errors.

Bootstrapped and regression tested on alphaev68-linux-gnu.

Uros.
Index: go/debug/elf/file.go
===
--- go/debug/elf/file.go(revision 249418)
+++ go/debug/elf/file.go(working copy)
@@ -602,6 +602,8 @@
return f.applyRelocationss390x(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_SPARCV9:
return f.applyRelocationsSPARC64(dst, rels)
+   case f.Class == ELFCLASS64 && f.Machine == EM_ALPHA:
+   return f.applyRelocationsALPHA(dst, rels)
default:
return errors.New("applyRelocations: not implemented")
}
@@ -1049,6 +1051,55 @@
return nil
 }
 
+func (f *File) applyRelocationsALPHA(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, )
+   symNo := rela.Info >> 32
+   t := R_ALPHA(rela.Info & 0x)
+
+   if symNo == 0 || symNo > uint64(len(symbols)) {
+   continue
+   }
+   sym := [symNo-1]
+   if SymType(sym.Info&0xf) != STT_SECTION {
+   // We don't handle non-section relocations for now.
+   continue
+   }
+
+   // There are relocations, so this must be a normal
+   // object file, and we only look at section symbols,
+   // so we assume that the symbol value is 0.
+
+   switch t {
+   case R_ALPHA_REFQUAD:
+   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_ALPHA_REFLONG:
+   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.