From 8c64deff2a82fcca5b521362193a1fd8b1a0dca7 Mon Sep 17 00:00:00 2001 From: Luna Nova 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