Skip to contentSkip to conversation

Makefile: Use correct nm binary when cross-compiling for x86_64

PATCH New Mika Tammi 1 participant 1 message Oct 30

Subsystems (2)
lore
Share & tools
lore

Mika Tammi

author
#0 lore raw

PATCH 1/1 Makefile: Use correct nm binary when cross-compiling for x86_64

x86/bios/gen-offsets.sh generates x86/bios/bios-rom.h from the symbols of the BIOS image with plain nm, the build machine's rather than the cross toolchain's. Where there is no plain nm, as in nixpkgs' cross builds, bios-rom.h gets no offsets and the build fails:

gen-offsets.sh: line 11: nm: command not found
x86/bios.c:18:50: error: 'BIOS_OFFSET__bios_int10' undeclared here (not in a function)

Pass the toolchain's nm to the script, as
commit 53ce8c598e58 ("Makefile: Use correct objcopy binary when cross-compiling for x86_64") did for objcopy. Run by hand, the script still uses plain nm.

Assisted-by Claude:claude-opus-5-5

---
I used Claude Opus 5.5 to track down the cause, write this patch and its description, and run the tests below; I have reviewed the result.

Tested with nixpkgs' kvmtool package on an x86_64 host: cross builds for x86_64 with musl, dynamic and static, failed as above and now build. Their bios-rom.h and bios.bin are identical to a native build's, and their lkvm boots an x86_64 guest under KVM once built without _FORTIFY_SOURCE: with it, musl's fortify-headers trap on the memcpy() from bios_rom, which bios-export.h declares as char[0], a separate issue. Native x86_64 and arm64 builds, and cross builds for arm64, riscv32 and riscv64, give a byte-identical lkvm with and without this patch.

 Makefile                | 3 ++-
 x86/bios/gen-offsets.sh | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
Makefile +2 -1
index 1c0e7f5..62142ff 100644
@@ -24,6 +24,7 @@ CFLAGS	:=
 LD	:= $(CROSS_COMPILE)ld
 LDFLAGS	:=
 OBJCOPY	:= $(CROSS_COMPILE)objcopy
+NM	:= $(CROSS_COMPILE)nm
 
 FIND	:= find
 CSCOPE	:= cscope
@@ -537,7 +538,7 @@ x86/bios/bios-rom.o: x86/bios/bios-rom.S x86/bios/bios.bin x86/bios/bios-rom.h
 
 x86/bios/bios-rom.h: x86/bios/bios.bin.elf
 	$(E) "  NM      " $@
-	$(Q) cd x86/bios && sh gen-offsets.sh > bios-rom.h && cd ..
+	$(Q) cd x86/bios && NM="$(NM)" sh gen-offsets.sh > bios-rom.h && cd ..
 
 check: all
 	$(MAKE) -C tests
x86/bios/gen-offsets.sh +1 -1
index 8771bbe..7f7b8e2 100644
@@ -8,7 +8,7 @@ echo ""
 echo "#define BIOS_ENTRY_SIZE(name) (name##_end - name)"
 echo ""
 
-nm bios.bin.elf | grep ' [Tt] ' | awk '{ print "#define BIOS_OFFSET__" $3 " 0x" $1; }'
+${NM:-nm} bios.bin.elf | grep ' [Tt] ' | awk '{ print "#define BIOS_OFFSET__" $3 " 0x" $1; }'
 
 echo ""
 echo "#endif"
Signature · 1 line
2.54.0 (Apple Git-157)