https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109591

            Bug ID: 109591
           Summary: Multiple -fdebug-prefix-map= prefixes match, which one
                    wins?
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i at maskray dot me
  Target Milestone: ---

mkdir -p a/b/c
echo 'int main(){}' > a/b/c/d.c
~/Dev/gcc/out/release/gcc/xgcc -B ~/Dev/gcc/out/release/gcc -g -c
-fdebug-prefix-map=a/b/c=z -fdebug-prefix-map=a/b=y -fdebug-prefix-map=a=x
a/b/c/d.c
objdump -Wi d.o | grep 'd\.c'  # <12>   DW_AT_name        : (indirect line
string, offset: 0): x/b/c/d.c
~/Dev/gcc/out/release/gcc/xgcc -B ~/Dev/gcc/out/release/gcc -g -c
-fdebug-prefix-map=a=x -fdebug-prefix-map=a/b=y -fdebug-prefix-map=a/b/c=z
a/b/c/d.c
objdump -Wi d.o | grep 'd\.c'  # <12>   DW_AT_name        : (indirect line
string, offset: 0): z/d.c
return

When multiple -fdebug-prefix-map= options are applicable, it seems that the
last wins.
In Clang, after https://reviews.llvm.org/D49466 (landed in Nov 2019), the
longest prefix wins.

clang -g -c -fdebug-prefix-map=a=x -fdebug-prefix-map=a/b=y
-fdebug-prefix-map=a/b/c=z a/b/c/d.c # z/d.c
clang -g -c -fdebug-prefix-map=a=x -fdebug-prefix-map=a/b=y
-fdebug-prefix-map=a/b/c=z a/b/c/d.c # z/d.c

This issue is motivated by https://reviews.llvm.org/D148757

---

Related, there is a strange use case where the old prefix is empty. The new
prefix may or may not end with a slash: '-fdebug-prefix-map==w' and
'-fdebug-prefix-map==w/'.

'-fdebug-prefix-map==w' changes the file name to wa/b/c/d.c . I am unsure
whether it should be w/a/b/c/d.c instead. Clang has the same problem.

Reply via email to