How do I pack a Go program so that it is sufficient?

I have a Go program and I want to run it on the switch. Since I cannot install Go on the switch itself, I just copy the executable and try to run. But I get the following error.

runtime: panic before malloc heap initialized fatal error: runtime: cannot reserve arena virtual address space runtime stack: runtime.throw(0x8149b8b) /usr/local/go/src/pkg/runtime/panic.c:520 +0x71 runtime.mallocinit() /usr/local/go/src/pkg/runtime/malloc.goc:552 +0xf2 runtime.schedinit() /usr/local/go/src/pkg/runtime/proc.c:150 +0x3a _rt0_go() /usr/local/go/src/pkg/runtime/asm_386.s:95 +0xf6` 

How to pack Go executable with all its dependencies?

EDIT 1: Here is a dump of ulimit -a .

 core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 40960 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) 395067 file locks (-x) unlimited 
+5
source share
1 answer

TL DR

Your Go app cannot allocate virtual memory to run. I have never developed a switch for a switch before, but if it uses the linux or unix version, check the group / user permissions and ulimit values ​​to see if this user has any restrictions. Perhaps this question may help.

Longer version

So your problem here is not that you cannot work without the go development environment, because you really don't need it. Go is known for creating static binaries that are, by definition, standalone and independent of other libraries to run.

If you look better at your error message, you will notice that it says:

"cannot reserve virtual arena address space"

Perhaps you are asking yourself: "What is this arena?"

A quick look at the malloc source code gives us a hint:

Set up the distribution arena, an adjacent memory area where the highlighted data will be found. The arena starts with a bitmap enough to store 4 bits per highlighted word.

If you go through this source code, you will find an error message here .

Runtime Environment Β· The SysReserve C function is one that actually tries to reserve a virtual address space for the arena. If he cannot isolate it, he will throw out this error.

You can find the code for its Linux implementation here .

As usual, you are trying to avoid large distributions, as it may crash right away if your user cannot allocate something smaller than 64K, which means that your user has hard limits. Since I have no idea which OS your switch is working for, and I have no experience for them, I cannot go beyond that.

If you can provide more information, I can try to update this answer accordingly.

+21
source

Source: https://habr.com/ru/post/1208623/


All Articles