Bug 93371

Summary: -ffile-prefix-map ignored with assembly files
Product: gcc Reporter: comexk
Component: driverAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: caleb.zulawski, raj.khem, rockdrilla, rv, tom.rini
Priority: P3    
Version: 10.0   
Target Milestone: 13.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description comexk 2020-01-22 01:10:41 UTC
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.
Comment 1 Caleb Zulawski 2022-06-22 12:42:00 UTC
I just found this report--seems to be still an issue in 12.1.
Comment 2 CVS Commits 2022-11-02 16:02:11 UTC
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.
Comment 3 Konstantin Demin 2022-12-12 18:21:55 UTC
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)
Comment 4 Andrew Pinski 2022-12-12 18:37:02 UTC
Fixed for GCC 13.