When using the GCC frontend to invoke GNU as, GCC passes through -fdebug-prefix-map (as --debug-prefix-map), but ignores -ffile-prefix-map. -ffile-prefix-map is supposed to be "equivalent to specifying all the individual -f*-prefix-map options." Most likely, GCC should be changed to pass --debug-prefix-map to as when the driver is passed -ffile-prefix-map (specifically in the definition of ASM_MAP in gcc/gcc.c). An alternative might be to add a --file-prefix-map option to GNU as and pass that instead; however, the only other type of prefix map is -fmacro-prefix-map, and that doesn't apply to raw as.
I just found this report--seems to be still an issue in 12.1.
The master branch has been updated by Jeff Law <law@gcc.gnu.org>: https://gcc.gnu.org/g:abaa32c7384edef065c79741764bc112dd18f32d commit r13-3611-gabaa32c7384edef065c79741764bc112dd18f32d Author: Rasmus Villemoes <rv@rasmusvillemoes.dk> Date: Wed Nov 2 10:01:22 2022 -0600 gcc: honour -ffile-prefix-map in ASM_MAP [PR93371] -ffile-prefix-map is supposed to be a superset of -fmacro-prefix-map and -fdebug-prefix-map. However, when building .S or .s files, gas is not called with the appropriate --debug-prefix-map option when -ffile-prefix-map is used. While the user can specify -fdebug-prefix-map when building assembly files via gcc, it's more ergonomic to also support -ffile-prefix-map; especially since for .S files that could contain the __FILE__ macro, one would then also have to specify -fmacro-prefix-map. gcc: PR driver/93371 * gcc.cc (ASM_MAP): Honour -ffile-prefix-map.
Test case: Let's consider having file "empty.S" with following contents: // -- cut -- .text ret // -- cut -- $ gcc -c -o empty.S.o empty.S -O2 -g && strings -f empty.S.o | grep -F ${PWD} && echo NOT OK || echo OK empty.S.o: /home/krd/gcc-prefix-case empty.S.o: /home/krd/gcc-prefix-case NOT OK $ gcc -c -o empty.S.o empty.S -O2 -g -fdebug-prefix-map=${PWD}=. && strings -f empty.S.o | grep -F ${PWD} && echo NOT OK || echo OK OK $ gcc -c -o empty.S.o empty.S -O2 -g -ffile-prefix-map=${PWD}=. && strings -f empty.S.o | grep -F ${PWD} && echo NOT OK || echo OK empty.S.o: /home/krd/gcc-prefix-case empty.S.o: /home/krd/gcc-prefix-case NOT OK $ gcc -c -o empty.S.o empty.S -O2 -g -ffile-prefix-map=${PWD}=. -Wa,--debug-prefix-map,${PWD}=. && strings -f empty.S.o | grep -F ${PWD} && echo NOT OK || echo OK OK $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux bookworm/sid Release: n/a Codename: bookworm $ dpkg-query -W -f='${Version}\n' gcc-12 12.2.0-10 $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-10' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-w47ffq/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-w47ffq/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (Debian 12.2.0-10)
Fixed for GCC 13.