Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Golang for NetBSD/arm



Hello port-arm,

I'm still tring golang on NetBSD/arm.

> 2nd probrem:
> 
> After above changes, when start make in NetBSD/evbearm-el on RPI,
> OS became hangup.

> 4th problem:
> 
> On NetBSD/earm 7.0RC2,  when executing the hello binary which made by golang
> on NetBSD/arm 6.1.5, Abort trap occurd.

Cause of the two of the problem is that the ARMv6 PAGE_SIZE has changed
from 4K to 8K.
The binaries made by Go linker, Elf_Phdr-> p_align was set to 4K.
ELF loader of NetBSD's kernel failed  mmap(2) and it seems that it will 
occur any incorrect action when p_align is smaller than PAGE_SIZE.
The standard of binary of NetBSD made with Gnu ld(1) is 64K.

For example,

Case of binary 'hello' created by go:

$ readelf -e ./hello
(snip)
Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align

  LOAD           0x000000 0x00010000 0x00010000 0x98fcc 0x98fcc R E 0x1000
  LOAD           0x099000 0x000a9000 0x000a9000 0x74bd4 0x74bd4 R   0x1000
  LOAD           0x10e000 0x0011e000 0x0011e000 0x04960 0x14090 RW  0x1000
(snip)

Align of LOAD type is 0x1000(=4K).


Case of /sbin/init:

$ readelf -e /sbin/init
(snip)
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x00010034 0x00010034 0x000e0 0x000e0 R E 0x4
  INTERP         0x000114 0x00010114 0x00010114 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /libexec/ld.elf_so]
  LOAD           0x000000 0x00010000 0x00010000 0x04354 0x04354 R E 0x10000
  LOAD           0x004354 0x00024354 0x00024354 0x0081c 0x00d94 RW  0x10000
(snip) 

Align is 0x10000(=64K).

GoLinker is able to change this value with '-R' commandline option, but
not be able to set when building toolchain.
So, I try to change go's source to set to 64K, then it works with no ABORT,
no HangUp!

In addition, in the memory management routine of Golang, PAGE_SIZE is
as 4K fixed (at cpu-arm). 

However, the PAGE_SIZE of many NetBSD/arm 7.0 kernel is 8K with ARMv6 or lator,
otherwise 4k with ARMv5, and in some kernel of ARMv6 is still 4K.
Also it can be changed in the kernel option even ARMv6.
So I try to get PAGE_SIZE from sysctl mib 'kern.pagesize', and store to global
variable when during Go's Runtime initialization.
(This change may not be well becase affects to other OS or architecture)

After the above, golang works in basic operation on NetBSD/arm(OABI) 7.0.

And add eabi padding in the structure of systemcall (fix missing of original
source of golang ), and add EABI flag in Elf Header.
Then, it works on NetBSD/earm (EABI) 7.0 in  basic operation.

Also Go 1.5 works on NetBSD/earm at some environment compiled by this Go1.4.

However, many problems are left this. Test suites of go could not finish now.
 - Cannot work cgo in some case.
 - OABI binary still does not work on NetBSD/earm  (process hangup or SEGV)
 - In armv7 and multi-core, Go1.5 works only ARMv7 binary.
    becase armv5 and armv6 don't support muliti-core by golang... 
 - In armv7 and multi-core, Go1.5 is strange (in multi-threading?)
 - and many more...

I still will continue to try solve these.
And I want to report upstream, but I can not be decide in something now,
 for example 
 - Correct value of Elf_Phdr->p_align, and why?
 - Support EABI only or OABI(include NetBSD6.x) or both if posible? 
 - How page size of NetBSD/arm? In my opinion, this is a valiable and 
   not unified in NetBSD/{arm,earm}, Ok?
 - What the default binary architecture type, armv5, armv6 or armv7? 
 - maybe more...

Patches (experimental) is
 for GO 1.4:
   https://gist.github.com/oshimaya/03091bf6d6bfdc57b9f2#file-go14src_for_earm-patch
 for GO 1.5:
   https://gist.github.com/oshimaya/03091bf6d6bfdc57b9f2#file-go15src_for_earm_arm5-patch
     This creates a ARMv5 binary, not work on mutli-core ARMv7 machine (ex. RPI2)

If you are interested or have any advices, please tell me.

Thanks.
--
Yasushi Oshima


Home | Main Index | Thread Index | Old Index