Skip to content

Commit 449c813

Browse files
committed
package uncompressed vmlinux
This allows for easier gdb integration, which expects an uncompressed vmlinux. Enable CONFIG_PVH so that qemu can boot the uncompressed image. Only available on >= 5.0 kernels. Disable CONFIG_RANDOMIZE_BASE since KASLR breaks the ability to set breakpoints in gdb. Only package source code references by the resulting vmlinux to reduce the size of the image. Signed-off-by: Lorenz Bauer <[email protected]>
1 parent 252caff commit 449c813

File tree

7 files changed

+115
-6
lines changed

7 files changed

+115
-6
lines changed

.github/workflows/build-and-push.yml

+65-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ jobs:
3636
uses: docker/setup-buildx-action@v3
3737

3838
- name: Cache ccache output
39-
uses: actions/cache@v3
39+
uses: actions/cache@v4
4040
with:
4141
path: ccache
42-
key: ccache-${{ inputs.kernel_version }}-${{ hashFiles('config') }}
42+
key: ccache-${{ inputs.kernel_version }}-${{ hashFiles('config-*') }}
4343

4444
- name: Inject ccache into builder
4545
uses: reproducible-containers/[email protected]
@@ -63,6 +63,22 @@ jobs:
6363
annotations: |
6464
org.opencontainers.image.licenses=GPLv2
6565
66+
- name: Kernel metadata (debug)
67+
id: debug-meta
68+
uses: docker/metadata-action@v5
69+
with:
70+
images: ghcr.io/${{ github.repository_owner }}/ci-kernels
71+
flavor: latest=false
72+
tags: |
73+
type=raw,value=${{ inputs.kernel_version }},suffix=-debug
74+
type=match,pattern=^\d+\.\d+,group=0,value=${{ inputs.kernel_version }},suffix=-debug
75+
type=raw,value=${{ inputs.static_tag }},enable=${{ inputs.static_tag != '' }},suffix=-debug
76+
77+
labels: |
78+
org.opencontainers.image.licenses=GPLv2
79+
annotations: |
80+
org.opencontainers.image.licenses=GPLv2
81+
6682
- name: Selftests metadata
6783
id: selftests-meta
6884
uses: docker/metadata-action@v5
@@ -72,7 +88,22 @@ jobs:
7288
tags: |
7389
type=raw,value=${{ inputs.kernel_version }},suffix=-selftests
7490
type=match,pattern=^\d+\.\d+,group=0,value=${{ inputs.kernel_version }},suffix=-selftests
75-
type=raw,value=${{ inputs.static_tag }},suffix=-selftests,enable=${{ inputs.static_tag != '' }}
91+
type=raw,value=${{ inputs.static_tag }},enable=${{ inputs.static_tag != '' }},suffix=-selftests
92+
labels: |
93+
org.opencontainers.image.licenses=GPLv2
94+
annotations: |
95+
org.opencontainers.image.licenses=GPLv2
96+
97+
- name: Selftests metadata (debug)
98+
id: selftests-debug-meta
99+
uses: docker/metadata-action@v5
100+
with:
101+
images: ghcr.io/${{ github.repository_owner }}/ci-kernels
102+
flavor: latest=false
103+
tags: |
104+
type=raw,value=${{ inputs.kernel_version }},suffix=-selftests-debug
105+
type=match,pattern=^\d+\.\d+,group=0,value=${{ inputs.kernel_version }},suffix=-selftests-debug
106+
type=raw,value=${{ inputs.static_tag }},enable=${{ inputs.static_tag != '' }},suffix=-selftests-debug
76107
labels: |
77108
org.opencontainers.image.licenses=GPLv2
78109
annotations: |
@@ -101,6 +132,21 @@ jobs:
101132
annotations: ${{ steps.meta.outputs.annotations }}
102133
outputs: ${{ github.ref == 'refs/heads/main' && 'type=registry' || 'type=local,dest=/tmp/build/vmlinux' }}
103134

135+
- name: Build kernel (debug)
136+
uses: docker/build-push-action@v5
137+
with:
138+
target: vmlinux-debug
139+
provenance: false
140+
platforms: |
141+
linux/amd64
142+
${{ inputs.build_arm64 && 'linux/arm64' || '' }}
143+
build-args: |
144+
KERNEL_VERSION=${{ inputs.kernel_version }}
145+
tags: ${{ steps.debug-meta.outputs.tags }}
146+
labels: ${{ steps.debug-meta.outputs.labels }}
147+
annotations: ${{ steps.debug-meta.outputs.annotations }}
148+
outputs: ${{ github.ref == 'refs/heads/main' && 'type=registry' || 'type=local,dest=/tmp/build/vmlinux-debug' }}
149+
104150
- name: Build selftests
105151
if: inputs.build_selftests
106152
uses: docker/build-push-action@v5
@@ -116,9 +162,24 @@ jobs:
116162
annotations: ${{ steps.selftests-meta.outputs.annotations }}
117163
outputs: ${{ github.ref == 'refs/heads/main' && 'type=registry' || 'type=local,dest=/tmp/build/selftests-bpf' }}
118164

165+
- name: Build selftests (debug)
166+
if: inputs.build_selftests
167+
uses: docker/build-push-action@v5
168+
with:
169+
target: selftests-bpf-debug
170+
provenance: false
171+
platforms: |
172+
linux/amd64
173+
build-args: |
174+
KERNEL_VERSION=${{ inputs.kernel_version }}
175+
tags: ${{ steps.selftests-debug-meta.outputs.tags }}
176+
labels: ${{ steps.selftests-debug-meta.outputs.labels }}
177+
annotations: ${{ steps.selftests-debug-meta.outputs.annotations }}
178+
outputs: ${{ github.ref == 'refs/heads/main' && 'type=registry' || 'type=local,dest=/tmp/build/selftests-bpf-debug' }}
179+
119180
- name: Store artifacts
120181
if: github.ref != 'refs/heads/main'
121-
uses: actions/upload-artifact@v3
182+
uses: actions/upload-artifact@v4
122183
with:
123184
name: Artifacts (${{ inputs.kernel_version }})
124185
if-no-files-found: error

Dockerfile

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ COPY download.sh .
77

88
RUN --mount=type=cache,target=/tmp/kernel ./download.sh
99

10-
WORKDIR /usr/src/linux-${KERNEL_VERSION}
10+
WORKDIR /usr/src/linux
1111

1212
COPY ccache.conf /etc/ccache.conf
1313

@@ -39,6 +39,14 @@ RUN if [ -d tools/testing/selftests/bpf/bpf_testmod ]; then \
3939
ln -s usr/lib /tmp/output/lib; \
4040
fi
4141

42+
FROM build-vmlinux as build-vmlinux-debug
43+
44+
# Package debug info
45+
RUN mkdir -p /tmp/debug/boot
46+
47+
COPY copy-debug.sh filter-debug.awk .
48+
RUN ./copy-debug.sh /tmp/debug
49+
4250
# Build selftests
4351
FROM build-vmlinux as build-selftests
4452

@@ -64,9 +72,23 @@ LABEL org.opencontainers.image.licenses=GPL-2.0-only
6472

6573
COPY --from=build-vmlinux /tmp/output /
6674

75+
# Debug
76+
FROM vmlinux as vmlinux-debug
77+
78+
LABEL org.opencontainers.image.licenses=GPL-2.0-only
79+
80+
COPY --from=build-vmlinux-debug /tmp/debug /
81+
6782
# Prepare the selftests image
6883
FROM vmlinux as selftests-bpf
6984

7085
LABEL org.opencontainers.image.licenses=GPL-2.0-only
7186

7287
COPY --from=build-selftests /tmp/selftests /usr/src/linux
88+
89+
# Debug
90+
FROM vmlinux-debug as selftests-bpf-debug
91+
92+
LABEL org.opencontainers.image.licenses=GPL-2.0-only
93+
94+
COPY --from=build-selftests /tmp/selftests /usr/src/linux

config

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ CONFIG_VIRTIO_PCI=y
2222
CONFIG_VIRTIO=y
2323
CONFIG_VT=y
2424

25+
# Make debugging in gdb work.
26+
CONFIG_RANDOMIZE_BASE=n
27+
2528
# Enable BPF related things
2629
# Please sort lines by alphabet ascending.
2730
CONFIG_BPF_JIT_ALWAYS_ON=y

config-x86_64

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CONFIG_HYPERVISOR_GUEST=y
88
CONFIG_KVM_GUEST=y
99
CONFIG_MAXSMP=y
1010
CONFIG_PARAVIRT=y
11+
CONFIG_PVH=y
1112

1213
# Get rid of some drivers and obsolete features
1314
CONFIG_AGP=n

copy-debug.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# copy-debug.sh DEST
3+
4+
set -eux
5+
set -o pipefail
6+
7+
readonly output="${1}"
8+
9+
# Retain vmlinux which includes debug symbols
10+
cp vmlinux "$output/boot/"
11+
12+
# Retain only the sources referenced by dwarf debug info
13+
"${LLVM_DWARFDUMP}" "$output/boot/vmlinux" | \
14+
awk -f filter-debug.awk | \
15+
xargs cp -v --no-clobber --parents --target-directory="$output"

download.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ fi
1212

1313
cd /tmp/kernel
1414
curl --fail -L --time-cond "linux-${KERNEL_VERSION}.tar.${KERNEL_URL##*.}" -o "linux-${KERNEL_VERSION}.tar.${KERNEL_URL##*.}" "$KERNEL_URL"
15-
tar -xf "linux-${KERNEL_VERSION}.tar.${KERNEL_URL##*.}" -C /usr/src
15+
mkdir /usr/src/linux
16+
tar -xf "linux-${KERNEL_VERSION}.tar.${KERNEL_URL##*.}" --strip-components=1 -C /usr/src/linux

filter-debug.awk

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Parse the output of llvm-dwarfdump to extract unique file names.
2+
3+
/DW_AT_(call|decl)_file/ {
4+
if ($2 ~ /<built-in>/) next;
5+
if (!seen[$2]++) print substr($2, 3, length($2)-4)
6+
}

0 commit comments

Comments
 (0)