동적으로 빌드시 OS 버전별 glibc 버전이 상이하여 빌드 환경에 따라 다른 OS에서 바이너리 실행시 실행되지 않는 문제
Ubuntu 22.04에서 빌드한 바이너리를 Ubuntu 18.04에서 실행한 예시
/root/cm-honeybee: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /root/cm-honeybee)
/root/cm-honeybee: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /root/cm-honeybee)
해당 문제를 해결하기 위해 정적 빌드 방법을 다음과 같이 시도 하였지만 nvml 라이브러리가 CGO에 의존되어 있어 빌드가 불가하거나 static linking을 통해 빌드시 정상적인 실행 불가
LDFLAGS에 static 옵션을 추가 하여 static linking 후에 실행시 정상적인 실행이 불가한 모습
Error Tracing
$ GOTOOLCHAIN=go1.20.11 go build -o cm-honeybee -ldflags '-w -extldflags "-static"' main.go
# command-line-arguments
/usr/bin/ld: /tmp/go-link-445234796/000025.o: in function `_cgo_0dc027beab6b_Cfunc_dlopen':
/tmp/go-build/dl.cgo2.c:107:(.text+0xaa): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-445234796/000028.o: in function `mygetgrouplist':
/_/os/user/getgrouplist_unix.go:15:(.text+0x22): warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-445234796/000027.o: in function `mygetgrgid_r':
/_/os/user/cgo_lookup_cgo.go:45:(.text+0x44): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-445234796/000027.o: in function `mygetgrnam_r':
/_/os/user/cgo_lookup_cgo.go:54:(.text+0xe5): warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-445234796/000027.o: in function `mygetpwnam_r':
/_/os/user/cgo_lookup_cgo.go:36:(.text+0x18a): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-445234796/000027.o: in function `mygetpwuid_r':
/_/os/user/cgo_lookup_cgo.go:27:(.text+0x249): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-445234796/000009.o: in function `_cgo_cbcce81e6342_C2func_getaddrinfo':
/tmp/go-build/cgo_unix_cgo.cgo2.c:58:(.text+0x37): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
이슈
문제가 되는 라이브러리
github.com/NVIDIA/go-nvml/pkg/nvml
이슈 사항
golang 1.21.x로 빌드 후 실행시 동작 안하는 문제 (해당 문제는
GOTOOLCHAIN=go1.20.11
환경 변수를 통해 강제 툴체인 변경 가능)Error Tracing
``` 2023/11/22 12:19:53 [ INFO ] Agent UUID: 432f3387-fec2-4567-bd85-b80d369a8bfd SIGSEGV: segmentation violation PC=0x0 m=0 sigcode=1 signal arrived during cgo execution goroutine 1 [syscall, locked to thread]: runtime.cgocall(0x6af170, 0xc0001698b0) /opt/go/src/runtime/cgocall.go:157 +0x4b fp=0xc000169888 sp=0xc000169850 pc=0x40684b github.com/NVIDIA/go-nvml/pkg/nvml._Cfunc_nvmlInit_v2() _cgo_gotypes.go:4597 +0x47 fp=0xc0001698b0 sp=0xc000169888 pc=0x6a4607 github.com/NVIDIA/go-nvml/pkg/nvml.nvmlInit_v2() /home/ish/go/pkg/mod/github.com/!n!v!i!d!i!a/go-nvml@v0.12.0-1/pkg/nvml/nvml.go:32 +0x13 fp=0xc0001698c8 sp=0xc0001698b0 pc=0x6a4f73 github.com/NVIDIA/go-nvml/pkg/nvml.Init() /home/ish/go/pkg/mod/github.com/!n!v!i!d!i!a/go-nvml@v0.12.0-1/pkg/nvml/init.go:43 +0x92 fp=0xc0001698f0 sp=0xc0001698c8 pc=0x6a4972 github.com/cloud-barista/cm-honeybee/gpu/nvidia.(*NVReader).Init(0x8?) /home/ish/go/src/cloud-migrator/cm-honeybee/gpu/nvidia/nvml_linux.go:18 +0x17 fp=0xc000169950 sp=0xc0001698f0 pc=0x6a7e77 github.com/cloud-barista/cm-honeybee/gpu/nvidia.NewNVReader() /home/ish/go/src/cloud-migrator/cm-honeybee/gpu/nvidia/NVReader.go:10 +0x1a fp=0xc0001699a0 sp=0xc000169950 pc=0x6a7c3a github.com/cloud-barista/cm-honeybee/driver/infra.GetNVIDIAGpuInfo() /home/ish/go/src/cloud-migrator/cm-honeybee/driver/infra/gpu.go:10 +0x13 fp=0xc0001699b8 sp=0xc0001699a0 pc=0x6a9e73 github.com/cloud-barista/cm-honeybee/driver/infra.GetInfraInfo() /home/ish/go/src/cloud-migrator/cm-honeybee/driver/infra/infra.go:21 +0x125 fp=0xc000169da0 sp=0xc0001699b8 pc=0x6a9fe5 main.init.0() /home/ish/go/src/cloud-migrator/cm-honeybee/main.go:44 +0x1a5 fp=0xc000169e10 sp=0xc000169da0 pc=0x6ab145 runtime.doInit1(0x979e10) /opt/go/src/runtime/proc.go:6740 +0xd8 fp=0xc000169f40 sp=0xc000169e10 pc=0x447658 runtime.doInit(...) /opt/go/src/runtime/proc.go:6707 runtime.main() /opt/go/src/runtime/proc.go:249 +0x374 fp=0xc000169fe0 sp=0xc000169f40 pc=0x43a574 runtime.goexit() /opt/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000169fe8 sp=0xc000169fe0 pc=0x469cc1 goroutine 2 [force gc (idle)]: runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?) /opt/go/src/runtime/proc.go:398 +0xce fp=0xc000048fa8 sp=0xc000048f88 pc=0x43a90e runtime.goparkunlock(...) /opt/go/src/runtime/proc.go:404 runtime.forcegchelper() /opt/go/src/runtime/proc.go:322 +0xb3 fp=0xc000048fe0 sp=0xc000048fa8 pc=0x43a793 runtime.goexit() /opt/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000048fe8 sp=0xc000048fe0 pc=0x469cc1 created by runtime.init.6 in goroutine 1 /opt/go/src/runtime/proc.go:310 +0x1a goroutine 3 [GC sweep wait]: runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?) /opt/go/src/runtime/proc.go:398 +0xce fp=0xc000049778 sp=0xc000049758 pc=0x43a90e runtime.goparkunlock(...) /opt/go/src/runtime/proc.go:404 runtime.bgsweep(0x0?) /opt/go/src/runtime/mgcsweep.go:280 +0x94 fp=0xc0000497c8 sp=0xc000049778 pc=0x426954 runtime.gcenable.func1() /opt/go/src/runtime/mgc.go:200 +0x25 fp=0xc0000497e0 sp=0xc0000497c8 pc=0x41bd25 runtime.goexit() /opt/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000497e8 sp=0xc0000497e0 pc=0x469cc1 created by runtime.gcenable in goroutine 1 /opt/go/src/runtime/mgc.go:200 +0x66 goroutine 4 [GC scavenge wait]: runtime.gopark(0xc000072000?, 0x7bbde0?, 0x1?, 0x0?, 0xc0000071e0?) /opt/go/src/runtime/proc.go:398 +0xce fp=0xc000049f70 sp=0xc000049f50 pc=0x43a90e runtime.goparkunlock(...) /opt/go/src/runtime/proc.go:404 runtime.(*scavengerState).park(0x9b4840) /opt/go/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc000049fa0 sp=0xc000049f70 pc=0x424229 runtime.bgscavenge(0x0?) /opt/go/src/runtime/mgcscavenge.go:653 +0x3c fp=0xc000049fc8 sp=0xc000049fa0 pc=0x4247bc runtime.gcenable.func2() /opt/go/src/runtime/mgc.go:201 +0x25 fp=0xc000049fe0 sp=0xc000049fc8 pc=0x41bcc5 runtime.goexit() /opt/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000049fe8 sp=0xc000049fe0 pc=0x469cc1 created by runtime.gcenable in goroutine 1 /opt/go/src/runtime/mgc.go:201 +0xa5 goroutine 5 [finalizer wait]: runtime.gopark(0x7386a0?, 0x10043ba01?, 0x0?, 0x0?, 0x442ac5?) /opt/go/src/runtime/proc.go:398 +0xce fp=0xc000048628 sp=0xc000048608 pc=0x43a90e runtime.runfinq() /opt/go/src/runtime/mfinal.go:193 +0x107 fp=0xc0000487e0 sp=0xc000048628 pc=0x41ada7 runtime.goexit() /opt/go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000487e8 sp=0xc0000487e0 pc=0x469cc1 created by runtime.createfing in goroutine 1 /opt/go/src/runtime/mfinal.go:163 +0x3d rax 0xc00016a000 rbx 0xc0001698b0 rcx 0xc0001698b0 rdx 0xc000169840 rdi 0xc0001698b0 rsi 0x9b4c20 rbp 0xc000169840 rsp 0x7ffce7d50338 r8 0x9b5240 r9 0x0 r10 0x1370ae0 r11 0x320a0c4b31bede07 r12 0xc00016a000 r13 0x55555555555 r14 0xc0000061a0 r15 0xeb rip 0x0 rflags 0x10206 cs 0x33 fs 0x0 gs 0x0 ```동적으로 빌드시 OS 버전별 glibc 버전이 상이하여 빌드 환경에 따라 다른 OS에서 바이너리 실행시 실행되지 않는 문제
해당 문제를 해결하기 위해 정적 빌드 방법을 다음과 같이 시도 하였지만 nvml 라이브러리가 CGO에 의존되어 있어 빌드가 불가하거나 static linking을 통해 빌드시 정상적인 실행 불가
Error Tracing
Error Tracing
이슈를 해결하기 위한 대안
nvidia-smi 실행 명령 사용
nvidia-smi
명령이 사용 가능함. (별도로 PATH 지정하지 않고 바로 이용 가능.)출력 결과 예시
Example
```