Index: sys/conf/kern.post.mk =================================================================== --- sys/conf/kern.post.mk +++ sys/conf/kern.post.mk @@ -329,13 +329,19 @@ .depend: .PRECIOUS ${SRCS} _ILINKS= machine +CFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include .if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" _ILINKS+= ${MACHINE_CPUARCH} +CFLAGS+= -fdebug-prefix-map=./${MACHINE_CPUARCH}=${SYSDIR}/${MACHINE_CPUARCH}/include .endif .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" _ILINKS+= x86 +CFLAGS+= -fdebug-prefix-map=./x86=${SYSDIR}/x86/include .endif +# Ensure that DWARF info contains a full path for auto-generated headers. +CFLAGS+= -fdebug-prefix-map=.=${.OBJDIR} + # Ensure that the link exists without depending on it when it exists. .for _link in ${_ILINKS} .if !exists(${.OBJDIR}/${_link}) Index: sys/conf/kmod.mk =================================================================== --- sys/conf/kmod.mk +++ sys/conf/kmod.mk @@ -268,14 +268,20 @@ .endif _ILINKS=machine +CFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include .if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" _ILINKS+=${MACHINE_CPUARCH} +CFLAGS+= -fdebug-prefix-map=./${MACHINE_CPUARCH}=${SYSDIR}/${MACHINE_CPUARCH}/include .endif .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" _ILINKS+=x86 +CFLAGS+= -fdebug-prefix-map=./x86=${SYSDIR}/x86/include .endif CLEANFILES+=${_ILINKS} +# Ensure that DWARF info contains a full path for auto-generated headers. +CFLAGS+= -fdebug-prefix-map=.=${.OBJDIR} + all: ${PROG} beforedepend: ${_ILINKS}