Skip to content

Commit dbbdc7e

Browse files
committed
[operator] Always generate debug symbols
Always generate debug symbols for the operator as part of the debug image.
1 parent d044ae8 commit dbbdc7e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

images/operator/Dockerfile

+29-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ ARG MODIFIERS
2222

2323
WORKDIR /go/src/github.com/cilium/cilium
2424

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.
2527
RUN --mount=type=bind,readwrite,target=/go/src/github.com/cilium/cilium \
2628
--mount=type=cache,target=/root/.cache \
2729
--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 \
2931
build-container-${OPERATOR_VARIANT} install-container-binary-${OPERATOR_VARIANT}
3032

3133
# 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 \
3537
--mount=type=cache,target=/go/pkg \
3638
make GOARCH=${BUILDARCH} licenses-all && mv LICENSE.all /out/${TARGETOS}/${TARGETARCH}
3739

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+
3858
# BUILDPLATFORM is an automatic platform ARG enabled by Docker BuildKit.
3959
# Represents the plataform where the build is happening, do not mix with
4060
# TARGETARCH
@@ -95,3 +115,11 @@ ENV DEBUG_HOLD=${DEBUG_HOLD}
95115
COPY --from=builder /out/${TARGETOS}/${TARGETARCH}/usr/bin/cilium-${OPERATOR_VARIANT} /usr/bin/cilium-${OPERATOR_VARIANT}-bin
96116
COPY --from=debug-tools /go/bin/dlv /usr/bin/dlv
97117
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

Comments
 (0)