Skip to content

Commit e7fcc63

Browse files
disable KASLR when using GDB
I was pulling my hair out trying to debug ClangBuiltLinux/linux#852 since breakpoints I set were never hit. Sami Tolvanen (@samitolvanen) reminded me I need to disable KASLR via nokaslr kernel command line parameter. Separate out the -append string from QEMU_ARCH_ARGS, since we need to change it both for interactive and debug mode.
1 parent d16f094 commit e7fcc63

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

boot-qemu.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,18 @@ function decomp_rootfs() {
100100

101101
# Boot QEMU
102102
function setup_qemu_args() {
103+
APPEND_STRING=""
103104
if ${INTERACTIVE:=false}; then
104-
RDINIT=" rdinit=/bin/sh"
105-
APPEND_RDINIT=(-append "${RDINIT}")
105+
APPEND_STRING+="rdinit=/bin/sh "
106+
fi
107+
if ${GDB:=false}; then
108+
APPEND_STRING+="nokaslr "
106109
fi
107110

108111
case ${ARCH} in
109112
arm32_v5)
110113
ARCH=arm
111-
QEMU_ARCH_ARGS=("${APPEND_RDINIT[@]}"
114+
QEMU_ARCH_ARGS=(
112115
-dtb "${KBUILD_DIR}"/arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb
113116
-machine palmetto-bmc
114117
-no-reboot)
@@ -117,7 +120,7 @@ function setup_qemu_args() {
117120

118121
arm32_v6)
119122
ARCH=arm
120-
QEMU_ARCH_ARGS=("${APPEND_RDINIT[@]}"
123+
QEMU_ARCH_ARGS=(
121124
-dtb "${KBUILD_DIR}"/arch/arm/boot/dts/aspeed-bmc-opp-romulus.dtb
122125
-machine romulus-bmc
123126
-no-reboot)
@@ -126,23 +129,25 @@ function setup_qemu_args() {
126129

127130
arm32_v7)
128131
ARCH=arm
129-
QEMU_ARCH_ARGS=(-append "console=ttyAMA0${RDINIT}"
132+
APPEND_STRING+="console=ttyAMA0 "
133+
QEMU_ARCH_ARGS=(
130134
-machine virt
131135
-no-reboot)
132136
QEMU=(qemu-system-arm)
133137
;;
134138

135139
arm64)
136140
KIMAGE=Image.gz
137-
QEMU_ARCH_ARGS=(-append "console=ttyAMA0${RDINIT}"
141+
APPEND_STRING+="console=ttyAMA0 "
142+
QEMU_ARCH_ARGS=(
138143
-cpu cortex-a57
139144
-machine virt)
140145
QEMU=(qemu-system-aarch64)
141146
;;
142147

143148
mips | mipsel)
144149
KIMAGE=vmlinux
145-
QEMU_ARCH_ARGS=("${APPEND_RDINIT[@]}"
150+
QEMU_ARCH_ARGS=(
146151
-cpu 24Kf
147152
-machine malta)
148153
QEMU=(qemu-system-"${ARCH}")
@@ -151,7 +156,8 @@ function setup_qemu_args() {
151156

152157
ppc32)
153158
ARCH=powerpc
154-
QEMU_ARCH_ARGS=(-append "console=ttyS0${RDINIT}"
159+
APPEND_STRING+="console=ttyS0 "
160+
QEMU_ARCH_ARGS=(
155161
-machine bamboo
156162
-no-reboot)
157163
QEMU_RAM=128m
@@ -161,7 +167,7 @@ function setup_qemu_args() {
161167
ppc64)
162168
ARCH=powerpc
163169
KIMAGE=vmlinux
164-
QEMU_ARCH_ARGS=("${APPEND_RDINIT[@]}"
170+
QEMU_ARCH_ARGS=(
165171
-machine pseries
166172
-vga none)
167173
QEMU_RAM=1G
@@ -171,7 +177,7 @@ function setup_qemu_args() {
171177
ppc64le)
172178
ARCH=powerpc
173179
KIMAGE=zImage.epapr
174-
QEMU_ARCH_ARGS=("${APPEND_RDINIT[@]}"
180+
QEMU_ARCH_ARGS=(
175181
-device "ipmi-bmc-sim,id=bmc0"
176182
-device "isa-ipmi-bt,bmc=bmc0,irq=10"
177183
-L "${IMAGES_DIR}/" -bios skiboot.lid
@@ -182,7 +188,7 @@ function setup_qemu_args() {
182188

183189
x86 | x86_64)
184190
KIMAGE=bzImage
185-
QEMU_ARCH_ARGS=(-append "console=ttyS0${RDINIT}")
191+
APPEND_STRING+="console=ttyS0 "
186192
# Use KVM if the processor supports it (first part) and the KVM module is loaded (second part)
187193
[[ $(grep -c -E 'vmx|svm' /proc/cpuinfo) -gt 0 && $(lsmod 2>/dev/null | grep -c kvm) -gt 0 ]] &&
188194
QEMU_ARCH_ARGS=("${QEMU_ARCH_ARGS[@]}" -cpu host -d "unimp,guest_errors" -enable-kvm)
@@ -213,6 +219,7 @@ function invoke_qemu() {
213219
# Note: no -serial mon:stdio
214220
"${QEMU[@]}" \
215221
"${QEMU_ARCH_ARGS[@]}" \
222+
-append "${APPEND_STRING}" \
216223
-display none \
217224
-initrd "${ROOTFS}" \
218225
-kernel "${KERNEL}" \
@@ -239,6 +246,7 @@ function invoke_qemu() {
239246
set -x
240247
"${QEMU[@]}" \
241248
"${QEMU_ARCH_ARGS[@]}" \
249+
-append "${APPEND_STRING}" \
242250
-display none \
243251
-initrd "${ROOTFS}" \
244252
-kernel "${KERNEL}" \

0 commit comments

Comments
 (0)