nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1From ef6c5b353861be727c98f1319c81d0c6b609d644 Mon Sep 17 00:00:00 2001
2From: Luna Nova <git@lunnova.dev>
3Date: Tue, 17 Dec 2024 04:29:11 -0800
4Subject: [PATCH] HACK: Get canonical GCC include path so doesn't have
5 ../../../../
6
7This allows more of the strings used in compilation to fit inside
8fixed size stack allocated buffers instead of spilling into the heap
9
10---
11 clang/lib/Driver/ToolChains/Gnu.cpp | 16 ++++++++++------
12 1 file changed, 10 insertions(+), 6 deletions(-)
13
14diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
15index af9fd46f0ce7b..a63a7a93f6a78 100644
16--- a/lib/Driver/ToolChains/Gnu.cpp
17+++ b/lib/Driver/ToolChains/Gnu.cpp
18@@ -3394,29 +3394,33 @@ bool Generic_GCC::addLibStdCXXIncludePaths(Twine IncludeDir, StringRef Triple,
19 if (!getVFS().exists(IncludeDir))
20 return false;
21
22+ SmallString<260> CanonicalIncludeDir;
23+ if (getVFS().getRealPath(IncludeDir, CanonicalIncludeDir))
24+ return false;
25+
26 // Debian native gcc uses g++-multiarch-incdir.diff which uses
27 // include/x86_64-linux-gnu/c++/10$IncludeSuffix instead of
28 // include/c++/10/x86_64-linux-gnu$IncludeSuffix.
29- std::string Dir = IncludeDir.str();
30 StringRef Include =
31- llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
32+ llvm::sys::path::parent_path(llvm::sys::path::parent_path(CanonicalIncludeDir));
33 std::string Path =
34- (Include + "/" + Triple + Dir.substr(Include.size()) + IncludeSuffix)
35+ (Include + "/" + Triple + CanonicalIncludeDir.substr(Include.size()) + IncludeSuffix)
36 .str();
37 if (DetectDebian && !getVFS().exists(Path))
38 return false;
39
40 // GPLUSPLUS_INCLUDE_DIR
41- addSystemInclude(DriverArgs, CC1Args, IncludeDir);
42+ addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir);
43 // GPLUSPLUS_TOOL_INCLUDE_DIR. If Triple is not empty, add a target-dependent
44 // include directory.
45 if (DetectDebian)
46 addSystemInclude(DriverArgs, CC1Args, Path);
47 else if (!Triple.empty())
48 addSystemInclude(DriverArgs, CC1Args,
49- IncludeDir + "/" + Triple + IncludeSuffix);
50+ CanonicalIncludeDir + "/" + Triple + IncludeSuffix);
51 // GPLUSPLUS_BACKWARD_INCLUDE_DIR
52- addSystemInclude(DriverArgs, CC1Args, IncludeDir + "/backward");
53+ if (getVFS().exists(CanonicalIncludeDir + "/backward"))
54+ addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir + "/backward");
55 return true;
56 }
57