Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: buildmode=pie makes application consumes much higher memory #44190

Open
osab270844 opened this issue Feb 9, 2021 · 2 comments
Open

cmd/link: buildmode=pie makes application consumes much higher memory #44190

osab270844 opened this issue Feb 9, 2021 · 2 comments

Comments

@osab270844
Copy link

@osab270844 osab270844 commented Feb 9, 2021

What version of Go are you using (go version)?

aarch64-poky-linux-go version 1.14.7 arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

aarch64-poky-linux-go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/.cache/go-build"
GOENV="
/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="
/usr/lib/aarch64-poky-linux/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/aarch64-poky-linux/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="aarch64-poky-linux-gcc -march=armv8-a -mtune=cortex-a57.cortex-a53 --sysroot=
/build/tmp/work/x86_64-linux/go-cross-aarch64/1.14.7-r0/recipe-sysroot"
CXX="aarch64-poky-linux-g++ -march=armv8-a -mtune=cortex-a57.cortex-a53 --sysroot=/build/tmp/work/x86_64-linux/go-cross-aarch64/1.14.7-r0/recipe-sysroot"
CGO_ENABLED="0"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=
/go-build347086452=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Build runc (https://github.com/opencontainers/runc) with --buildmode=pie option to have ASLR support.

Run containers on ARM64v8 arch.

What did you expect to see?

runc with PIE flag consumes memory similar or slightly higher compared to runc built in default mode.

What did you see instead?

runc consumes much higher memory when it's built in PIE mode.

P.S. checking size of a simple example on Ubuntu 16.04 LTS/amd64

root@osama:/data/gotest# go build --buildmode=pie -o ex ex.go
root@osama:/data/gotest# size ex
text data bss dec hex filename
1068470 611516 207464 1887450 1cccda ex
root@osama:/data/gotest# go build --buildmode=default -o ex ex.go
root@osama:/data/gotest# size ex
text data bss dec hex filename
1268529 88724 207456 1564709 17e025 ex

root@osama:/data/gotest# go version
go version devel +8869086 Thu Feb 4 04:46:49 2021 +0000 linux/amd64

data section increases more than x6 with buildmode=pie

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Feb 9, 2021

runc consumes much higher memory when it's built in PIE mode.

Could you show how this is measured?

data section increases more than x6 with buildmode=pie

This is related how the size command does accounting. When built as PIE, some part of the program used to be in rodata (counted as text) becomes data, because dynamic relocations need to be applied. As you posted, the text size decreases. You can use size -A or objdump -h for a more detailed breakdown.

The numbers above looks reasonable and expected to me. And I don't think it has (direct) relation with memory consumption increase.

@dmitshur dmitshur changed the title buildmode=pie makes application consumes much higher memory cmd/link: buildmode=pie makes application consumes much higher memory Feb 9, 2021
@osab270844
Copy link
Author

@osab270844 osab270844 commented Feb 12, 2021

@cherrymui Thanks for you reply.

I use linux "free" command to check the free memory on qemu arm64 based image which has 9 runc-opencontainers containers. I see runc consumes about ~4MB more if it's built in PIE mode.

Checking runc image size built with yocto aarch64-poky-linux-go, there is ~2.56 MB binary size increase (~26.4% increase):

###########

default

###########

file runc
runc: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.14.0, BuildID[sha1]=33d30f1ad2ca10b8d12aae7a1f9656a03253dc6e, not stripped
size runc
text data bss dec hex filename
9809960 173052 194760 10177772 9b4cec runc
size -A runc
runc :
section size addr
.interp 27 4194872
.note.ABI-tag 32 4194900
.note.go.buildid 100 4194932
.note.gnu.build-id 36 4195032
.gnu.hash 1716 4195072
.dynsym 6096 4196792
.dynstr 3684 4202888
.gnu.version 508 4206572
.gnu.version_r 96 4207080
.rela.dyn 120 4207176
.rela.plt 2736 4207296
.init 20 4210032
.plt 1856 4210064
.text 4311696 4211920
.fini 16 8523616
.rodata 2085192 8523648
.typelink 16228 10608864
.itablink 4128 10625096
.gopclntab 3375669 10629248
.eh_frame 4 14004920
.tbss 16 14072304
.init_array 16 14072304
.fini_array 8 14072320
.dynamic 544 14072328
.got 984 14072872
.data 75336 14073856
.go.buildinfo 32 14149200
.noptrdata 96132 14149248
.bss 183952 14245408
.noptrbss 10792 14429376
.comment 17 0
.zdebug_aranges 394 0
.zdebug_pubnames 22927 0
.zdebug_info 1027940 0
.zdebug_abbrev 2247 0
.zdebug_line 524254 0
.zdebug_frame 126784 0
.zdebug_str 4101 0
.zdebug_loc 586953 0
.zdebug_pubtypes 66621 0
.zdebug_ranges 185242 0
.debug_gdb_scripts 40 0
Total 12725292

ls -l runc

13706048

###########

pie

###########

file runc
runc: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.14.0, BuildID[sha1]=003f128d9f8de535f3237168846f460a7b9b5354, not stripped
size runc
text data bss dec hex filename
7800919 4870913 194760 12866592 c45420 runc
size -A runc
runc :
section size addr
.interp 27 568
.note.ABI-tag 32 596
.note.go.buildid 100 628
.note.gnu.build-id 36 728
.gnu.hash 1716 768
.dynsym 6120 2488
.dynstr 3642 8608
.gnu.version 510 12250
.gnu.version_r 64 12760
.rela.dyn 2686704 12824
.rela.plt 2736 2699528
.init 20 2702264
.plt 1856 2702288
.text 4282656 2704144
.fini 16 6986800
.rodata 814680 6986816
.eh_frame 4 7801496
.tbss 16 7868008
.init_array 16 7868008
.fini_array 8 7868024
.data.rel.ro 4697845 7868032
.dynamic 512 12565880
.got 96 12566392
.got.plt 936 12566504
.data 75336 12567456
.go.buildinfo 32 12642800
.noptrdata 96132 12642848
.bss 183952 12739008
.noptrbss 10792 12922976
.comment 17 0
.zdebug_aranges 396 0
.zdebug_pubnames 22918 0
.zdebug_info 1027973 0
.zdebug_abbrev 2231 0
.zdebug_line 529303 0
.zdebug_frame 126661 0
.zdebug_str 4008 0
.zdebug_loc 586561 0
.zdebug_pubtypes 66639 0
.zdebug_ranges 190395 0
.debug_gdb_scripts 40 0
Total 15423734

ls -l runc

16403528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants