@@ -22,10 +22,12 @@ ARG MODIFIERS
22
22
23
23
WORKDIR /go/src/github.com/cilium/cilium
24
24
25
+ # We must override NOSTRIP=1 to ensure binaries include debug symbols for extraction. They will be stripped subsequently
26
+ # in accordance with the supplied/default NOSTRIP setting. See "Extract debug symbols" below.
25
27
RUN --mount=type=bind,readwrite,target=/go/src/github.com/cilium/cilium \
26
28
--mount=type=cache,target=/root/.cache \
27
29
--mount=type=cache,target=/go/pkg \
28
- make GOARCH=${TARGETARCH} DESTDIR=/out/${TARGETOS}/${TARGETARCH} $(echo $MODIFIERS | tr -d '"' ) \
30
+ make GOARCH=${TARGETARCH} DESTDIR=/out/${TARGETOS}/${TARGETARCH} $(echo $MODIFIERS | tr -d '"' ) NOSTRIP=1 \
29
31
build-container-${OPERATOR_VARIANT} install-container-binary-${OPERATOR_VARIANT}
30
32
31
33
# licenses-all is a "script" that executes "go run" so its ARCH should be set
@@ -35,6 +37,24 @@ RUN --mount=type=bind,readwrite,target=/go/src/github.com/cilium/cilium \
35
37
--mount=type=cache,target=/go/pkg \
36
38
make GOARCH=${BUILDARCH} licenses-all && mv LICENSE.all /out/${TARGETOS}/${TARGETARCH}
37
39
40
+ # Extract debug symbols to /tmp/debug and strip the binaries if NOSTRIP is not set.
41
+ RUN set -xe && \
42
+ export D=/tmp/debug/${TARGETOS}/${TARGETARCH} && \
43
+ cd /out/${TARGETOS}/${TARGETARCH} && \
44
+ find . -type f \
45
+ -executable \
46
+ -exec sh -c \
47
+ 'filename=$(basename ${0}) && \
48
+ objcopy --only-keep-debug ${0} ${0}.debug && \
49
+ if ! echo "$MODIFIERS" | grep "NOSTRIP=1" ; then objcopy --strip-all ${0} && (cd $(dirname ${0}) && objcopy --add-gnu-debuglink=${filename}.debug ${filename}) ; fi && \
50
+ mkdir -p $(dirname ${D}/${0}) && \
51
+ mv -v ${0}.debug ${D}/${0}.debug' \
52
+ {} \;
53
+
54
+ # Check debug symbols are present
55
+ RUN for f in $(find /tmp/debug -type f -name '*.debug' ) ; do readelf -S ${f} | grep -q \\ .symtab || \
56
+ (echo Debug symbols are missing in ${f} - possibly due to incorrect build parameters && false); done
57
+
38
58
# BUILDPLATFORM is an automatic platform ARG enabled by Docker BuildKit.
39
59
# Represents the plataform where the build is happening, do not mix with
40
60
# TARGETARCH
@@ -95,3 +115,11 @@ ENV DEBUG_HOLD=${DEBUG_HOLD}
95
115
COPY --from=builder /out/${TARGETOS}/${TARGETARCH}/usr/bin/cilium-${OPERATOR_VARIANT} /usr/bin/cilium-${OPERATOR_VARIANT}-bin
96
116
COPY --from=debug-tools /go/bin/dlv /usr/bin/dlv
97
117
COPY --from=debug-tools /out/${TARGETOS}/${TARGETARCH}/bin/debug-wrapper /usr/bin/cilium-${OPERATOR_VARIANT}
118
+
119
+ # Copy in the debug symbols in case the binaries were stripped
120
+ COPY --from=builder /tmp/debug/${TARGETOS}/${TARGETARCH}/ /usr/lib/debug/
121
+
122
+ # Ensure dlv finds the debug symbols. Due to CGO_ENABLED=0, we have no GNU build-id, so Delve's default search path
123
+ # is insufficient.
124
+ RUN mkdir -p ${HOME}/.config/dlv && \
125
+ echo 'debug-info-directories: ["/usr/lib/debug/.build-id","/usr/lib/debug"]' > ${HOME}/.config/dlv/config.yml
0 commit comments