summaryrefslogtreecommitdiff
path: root/pkgs/development/rocm-modules/llvm/perf-shorten-gcclib-include-paths.patch
blob: b23a3886c3d00a09121d81f485439548776eb35e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From 8c64deff2a82fcca5b521362193a1fd8b1a0dca7 Mon Sep 17 00:00:00 2001
From: Luna Nova <git@lunnova.dev>
Date: Tue, 17 Dec 2024 04:29:11 -0800
Subject: [PATCH] HACK: Get canonical GCC include path so doesn't have
 ../../../../

This allows more of the strings used in compilation to fit inside
fixed size stack allocated buffers instead of spilling into the heap
---
 lib/Driver/ToolChains/Gnu.cpp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
index 07df9864636..b1201b999f0 100644
--- a/lib/Driver/ToolChains/Gnu.cpp
+++ b/lib/Driver/ToolChains/Gnu.cpp
@@ -3326,29 +3326,33 @@ static bool addLibStdCXXIncludePaths(llvm::vfs::FileSystem &vfs,
   if (!vfs.exists(IncludeDir))
     return false;
 
+  SmallString<260> CanonicalIncludeDir;
+  if (vfs.getRealPath(IncludeDir, CanonicalIncludeDir))
+    return false;
+
   // Debian native gcc uses g++-multiarch-incdir.diff which uses
   // include/x86_64-linux-gnu/c++/10$IncludeSuffix instead of
   // include/c++/10/x86_64-linux-gnu$IncludeSuffix.
-  std::string Dir = IncludeDir.str();
   StringRef Include =
-      llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
+      llvm::sys::path::parent_path(llvm::sys::path::parent_path(CanonicalIncludeDir));
   std::string Path =
-      (Include + "/" + Triple + Dir.substr(Include.size()) + IncludeSuffix)
+      (Include + "/" + Triple + CanonicalIncludeDir.substr(Include.size()) + IncludeSuffix)
           .str();
   if (DetectDebian && !vfs.exists(Path))
     return false;
 
   // GPLUSPLUS_INCLUDE_DIR
-  ToolChain::addSystemInclude(DriverArgs, CC1Args, IncludeDir);
+  ToolChain::addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir);
   // GPLUSPLUS_TOOL_INCLUDE_DIR. If Triple is not empty, add a target-dependent
   // include directory.
   if (DetectDebian)
     ToolChain::addSystemInclude(DriverArgs, CC1Args, Path);
   else if (!Triple.empty())
     ToolChain::addSystemInclude(DriverArgs, CC1Args,
-                                IncludeDir + "/" + Triple + IncludeSuffix);
+                                CanonicalIncludeDir + "/" + Triple + IncludeSuffix);
   // GPLUSPLUS_BACKWARD_INCLUDE_DIR
-  ToolChain::addSystemInclude(DriverArgs, CC1Args, IncludeDir + "/backward");
+  if (vfs.exists(CanonicalIncludeDir + "/backward"))
+    ToolChain::addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir + "/backward");
   return true;
 }
 
-- 
2.52.0