[lld] r353250 - [PDB] Remove dots and normalize slashes with /PDBSOURCEPATH.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 6 06:47:13 PST 2019


Merged to 8.0 in r353300.

On Wed, Feb 6, 2019 at 1:50 AM Zachary Turner via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: zturner
> Date: Tue Feb  5 16:50:35 2019
> New Revision: 353250
>
> URL: http://llvm.org/viewvc/llvm-project?rev=353250&view=rev
> Log:
> [PDB] Remove dots and normalize slashes with /PDBSOURCEPATH.
>
> In a previous patch, I made changes so that PDBs which were
> generated on non-Windows platforms contained sensical paths
> for the host.  While this is an esoteric use case, we need
> it to be supported for certain cross compilation scenarios
> especially with LLDB, which can debug things on non-Windows
> platforms.
>
> However, this regressed a case where you specify /PDBSOURCEPATH
> and use a windows-style path.  Previously, we would still remove
> dots and canonicalize slashes to backslashes, but since my
> change intentionally tried to support non-backslash paths, this
> was broken.
>
> This patch fixes the situation by trying to guess which path
> style the user is specifying when /PDBSOURCEPATH is passed.
> It is intentionally conservative, erring on the side of a
> Windows path style unless absolutely certain.  All dots are
> removed and slashes canonicalized to whatever the deduced
> path style is after appending the file path to the /PDBSOURCEPATH
> argument.
>
> Differential Revision: https://reviews.llvm.org/D57769
>
> Modified:
>     lld/trunk/COFF/PDB.cpp
>     lld/trunk/test/COFF/pdb-relative-source-lines.test
>
> Modified: lld/trunk/COFF/PDB.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=353250&r1=353249&r2=353250&view=diff
> ==============================================================================
> --- lld/trunk/COFF/PDB.cpp (original)
> +++ lld/trunk/COFF/PDB.cpp Tue Feb  5 16:50:35 2019
> @@ -287,18 +287,24 @@ static void pdbMakeAbsolute(SmallVectorI
>    // It's not absolute in any path syntax.  Relative paths necessarily refer to
>    // the local file system, so we can make it native without ending up with a
>    // nonsensical path.
> -  sys::path::native(FileName);
>    if (Config->PDBSourcePath.empty()) {
> +    sys::path::native(FileName);
>      sys::fs::make_absolute(FileName);
>      return;
>    }
> -  // Only apply native and dot removal to the relative file path.  We want to
> -  // leave the path the user specified untouched since we assume they specified
> -  // it for a reason.
> -  sys::path::remove_dots(FileName, /*remove_dot_dots=*/true);
>
> +  // Try to guess whether /PDBSOURCEPATH is a unix path or a windows path.
> +  // Since PDB's are more of a Windows thing, we make this conservative and only
> +  // decide that it's a unix path if we're fairly certain.  Specifically, if
> +  // it starts with a forward slash.
>    SmallString<128> AbsoluteFileName = Config->PDBSourcePath;
> -  sys::path::append(AbsoluteFileName, FileName);
> +  sys::path::Style GuessedStyle = AbsoluteFileName.startswith("/")
> +                                      ? sys::path::Style::posix
> +                                      : sys::path::Style::windows;
> +  sys::path::append(AbsoluteFileName, GuessedStyle, FileName);
> +  sys::path::native(AbsoluteFileName, GuessedStyle);
> +  sys::path::remove_dots(AbsoluteFileName, true, GuessedStyle);
> +
>    FileName = std::move(AbsoluteFileName);
>  }
>
>
> Modified: lld/trunk/test/COFF/pdb-relative-source-lines.test
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-relative-source-lines.test?rev=353250&r1=353249&r2=353250&view=diff
> ==============================================================================
> --- lld/trunk/test/COFF/pdb-relative-source-lines.test (original)
> +++ lld/trunk/test/COFF/pdb-relative-source-lines.test Tue Feb  5 16:50:35 2019
> @@ -37,26 +37,26 @@ RUN: llvm-pdbutil pdb2yaml -modules -mod
>  RUN: ./lld-link -debug "-pdbsourcepath:/usr/src" -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
>  RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=POSIX %s
>
> -CHECK-LABEL:  - Module:          'c:\src{{[\\/]}}pdb_lines_1_relative.obj'
> -CHECK-NEXT:     ObjFile:         'c:\src{{[\\/]}}pdb_lines_1_relative.obj'
> +CHECK-LABEL:  - Module:          'c:\src\pdb_lines_1_relative.obj'
> +CHECK-NEXT:     ObjFile:         'c:\src\pdb_lines_1_relative.obj'
>  CHECK:          SourceFiles:
> -CHECK-NEXT:       - 'c:\src{{[\\/]}}pdb_lines_1.c'
> -CHECK-NEXT:       - 'c:\src{{[\\/]}}foo.h'
> +CHECK-NEXT:       - 'c:\src\pdb_lines_1.c'
> +CHECK-NEXT:       - 'c:\src\foo.h'
>  CHECK:          Subsections:
> -CHECK:                - FileName:        'c:\src{{[\\/]}}pdb_lines_1.c'
> -CHECK:                - FileName:        'c:\src{{[\\/]}}foo.h'
> +CHECK:                - FileName:        'c:\src\pdb_lines_1.c'
> +CHECK:                - FileName:        'c:\src\foo.h'
>  CHECK:            - !FileChecksums
> -CHECK:                - FileName:        'c:\src{{[\\/]}}pdb_lines_1.c'
> -CHECK:                - FileName:        'c:\src{{[\\/]}}foo.h'
> +CHECK:                - FileName:        'c:\src\pdb_lines_1.c'
> +CHECK:                - FileName:        'c:\src\foo.h'
>
> -CHECK-LABEL:  - Module:          'c:\src{{[\\/]}}pdb_lines_2_relative.obj'
> -CHECK-NEXT:     ObjFile:         'c:\src{{[\\/]}}pdb_lines_2_relative.obj'
> +CHECK-LABEL:  - Module:          'c:\src\pdb_lines_2_relative.obj'
> +CHECK-NEXT:     ObjFile:         'c:\src\pdb_lines_2_relative.obj'
>  CHECK:          SourceFiles:
> -CHECK-NEXT:       - 'c:\src{{[\\/]}}pdb_lines_2.c'
> +CHECK-NEXT:       - 'c:\src\pdb_lines_2.c'
>  CHECK:          Subsections:
> -CHECK:                - FileName:        'c:\src{{[\\/]}}pdb_lines_2.c'
> +CHECK:                - FileName:        'c:\src\pdb_lines_2.c'
>  CHECK:            - !FileChecksums
> -CHECK:                - FileName:        'c:\src{{[\\/]}}pdb_lines_2.c'
> +CHECK:                - FileName:        'c:\src\pdb_lines_2.c'
>
>  CHECK-LABEL:  - Kind:            S_ENVBLOCK
>  CHECK-NEXT:     EnvBlockSym:
> @@ -64,33 +64,33 @@ CHECK-NEXT:       Entries:
>  CHECK-NEXT:         - cwd
>  CHECK-NEXT:         - 'c:\src'
>  CHECK-NEXT:         - exe
> -CHECK-NEXT:         - 'c:\src{{[\\/]}}lld-link'
> +CHECK-NEXT:         - 'c:\src\lld-link'
>  CHECK-NEXT:         - pdb
> -CHECK-NEXT:         - 'c:\src{{[\\/]}}out.pdb'
> +CHECK-NEXT:         - 'c:\src\out.pdb'
>  CHECK-NEXT:         - cmd
>  CHECK-NEXT:         - '-debug -pdbsourcepath:c:\src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'
>
>
> -POSIX-LABEL:  - Module:          '/usr/src{{[\\/]}}pdb_lines_1_relative.obj'
> -POSIX-NEXT:     ObjFile:         '/usr/src{{[\\/]}}pdb_lines_1_relative.obj'
> +POSIX-LABEL:  - Module:          '/usr/src/pdb_lines_1_relative.obj'
> +POSIX-NEXT:     ObjFile:         '/usr/src/pdb_lines_1_relative.obj'
>  POSIX:          SourceFiles:
> -POSIX-NEXT:       - '/usr/src{{[\\/]}}pdb_lines_1.c'
> -POSIX-NEXT:       - '/usr/src{{[\\/]}}foo.h'
> +POSIX-NEXT:       - '/usr/src/pdb_lines_1.c'
> +POSIX-NEXT:       - '/usr/src/foo.h'
>  POSIX:          Subsections:
> -POSIX:                - FileName:        '/usr/src{{[\\/]}}pdb_lines_1.c'
> -POSIX:                - FileName:        '/usr/src{{[\\/]}}foo.h'
> +POSIX:                - FileName:        '/usr/src/pdb_lines_1.c'
> +POSIX:                - FileName:        '/usr/src/foo.h'
>  POSIX:            - !FileChecksums
> -POSIX:                - FileName:        '/usr/src{{[\\/]}}pdb_lines_1.c'
> -POSIX:                - FileName:        '/usr/src{{[\\/]}}foo.h'
> +POSIX:                - FileName:        '/usr/src/pdb_lines_1.c'
> +POSIX:                - FileName:        '/usr/src/foo.h'
>
> -POSIX-LABEL:  - Module:          '/usr/src{{[\\/]}}pdb_lines_2_relative.obj'
> -POSIX-NEXT:     ObjFile:         '/usr/src{{[\\/]}}pdb_lines_2_relative.obj'
> +POSIX-LABEL:  - Module:          '/usr/src/pdb_lines_2_relative.obj'
> +POSIX-NEXT:     ObjFile:         '/usr/src/pdb_lines_2_relative.obj'
>  POSIX:          SourceFiles:
> -POSIX-NEXT:       - '/usr/src{{[\\/]}}pdb_lines_2.c'
> +POSIX-NEXT:       - '/usr/src/pdb_lines_2.c'
>  POSIX:          Subsections:
> -POSIX:                - FileName:        '/usr/src{{[\\/]}}pdb_lines_2.c'
> +POSIX:                - FileName:        '/usr/src/pdb_lines_2.c'
>  POSIX:            - !FileChecksums
> -POSIX:                - FileName:        '/usr/src{{[\\/]}}pdb_lines_2.c'
> +POSIX:                - FileName:        '/usr/src/pdb_lines_2.c'
>
>  POSIX-LABEL:  - Kind:            S_ENVBLOCK
>  POSIX-NEXT:     EnvBlockSym:
> @@ -98,8 +98,8 @@ POSIX-NEXT:       Entries:
>  POSIX-NEXT:         - cwd
>  POSIX-NEXT:         - '/usr/src'
>  POSIX-NEXT:         - exe
> -POSIX-NEXT:         - '/usr/src{{[\\/]}}lld-link'
> +POSIX-NEXT:         - '/usr/src/lld-link'
>  POSIX-NEXT:         - pdb
> -POSIX-NEXT:         - '/usr/src{{[\\/]}}out.pdb'
> +POSIX-NEXT:         - '/usr/src/out.pdb'
>  POSIX-NEXT:         - cmd
>  POSIX-NEXT:         - '-debug -pdbsourcepath:/usr/src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list