Skip to content

Commit e9aa072

Browse files
committed
ploop.go: use pkg-config
Instead of specifying CFLAGS and LDFLAGS, let's rely on pkg-config. Unfortunately go doesn't have a way to selectively pass --static flag to pkg-config, so if we try to build Docker statically the resulting binary will have many undefined symbols: # readelf -s bundles/1.7.1/binary/docker-1.7.1 | grep -w UND | grep -E 'xml|timer' 21029: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND xmlTextWriterWriteFormatE 21044: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND timer_create ......... This clearly shows that neither libxml2 nor librt were linked in, and the resulting binary will segfault on the first access to one of these symbols. To fix this, we have to pass --static to pkg-config. For case of dynamic linking, this is also OK but leads to so-called "overlinking" (see [1] for discussion about it). We could have used LDFLAGS=-Wl,--as-needed to fix this, but as there is no way to distinguish between LDFLAGS and LDLIBS (LDFLAGS should go before .o files, and LDLIBS should go after) we can't use --as-needed. Anyways, overlinking is probably a minor issue compared to a sudden binary segfault. Still, TODO: find a way to selectively pass --static to pkg-config Note: this requires a very recent ploop (with ploop.pc added). [1] https://wiki.mageia.org/en/Overlinking_issues_in_packaging Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 9425017 commit e9aa072

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

ploop.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import "strings"
44
import "os/exec"
55
import "sync"
66

7-
// #cgo CFLAGS: -D_GNU_SOURCE
8-
// #cgo LDFLAGS: -lploop -lxml2 -lrt
7+
// #cgo pkg-config: --static ploop
98
// #include <ploop/libploop.h>
109
import "C"
1110

0 commit comments

Comments
 (0)