@@ -85,16 +85,40 @@ bool Input::isPathValid(const std::string &Path) const {
8585 return true ;
8686}
8787
88+ std::string Input::expandSysrootMarkers (llvm::StringRef Name,
89+ const SearchDirs &PSearchDirs,
90+ DiagnosticEngine &DiagEngine) {
91+ llvm::StringRef Suffix;
92+ if (Name.starts_with (" =" ))
93+ Suffix = Name.substr (1 );
94+ else if (Name.starts_with (" $SYSROOT" ))
95+ Suffix = Name.substr (strlen (" $SYSROOT" ));
96+ else
97+ return Name.str ();
98+
99+ std::string ExpandedPath = Suffix.str ();
100+ if (PSearchDirs.hasSysRoot ())
101+ ExpandedPath = (PSearchDirs.sysroot ().native () + Suffix).str ();
102+
103+ DiagEngine.raise (Diag::verbose_sysroot_expansion) << Name << ExpandedPath;
104+ return ExpandedPath;
105+ }
106+
88107// / \return True if path able to be resolved, otherwise false
89108bool Input::resolvePath (const LinkerConfig &PConfig) {
90109 if (ResolvedPath)
91110 return true ;
92111 if (PConfig.options ().hasMappingFile () && !isInternal ())
93112 return resolvePathMappingFile (PConfig);
94113 auto &PSearchDirs = PConfig.directories ();
114+
115+ std::string ExpandedFileName = FileName;
116+ if (Type == Input::InputType::Script || Type == Input::InputType::Default)
117+ ExpandedFileName = expandSysrootMarkers (FileName, PSearchDirs, *DiagEngine);
118+
95119 switch (Type) {
96120 default :
97- ResolvedPath = eld::sys::fs::Path (FileName );
121+ ResolvedPath = eld::sys::fs::Path (ExpandedFileName );
98122 break ;
99123 case Input::Internal:
100124 ResolvedPath = eld::sys::fs::Path (FileName);
@@ -103,10 +127,11 @@ bool Input::resolvePath(const LinkerConfig &PConfig) {
103127 if (Type == Input::Script) {
104128 if (shouldPrependSysrootToScriptInput (PConfig)) {
105129 ResolvedPath = PSearchDirs.sysroot ();
106- ResolvedPath->append (FileName );
130+ ResolvedPath->append (ExpandedFileName );
107131 }
108132 if (!llvm::sys::fs::exists (ResolvedPath->native ())) {
109- const sys::fs::Path *P = PSearchDirs.find (FileName, Input::Script);
133+ const sys::fs::Path *P =
134+ PSearchDirs.find (ExpandedFileName, Input::InputType::Script);
110135 if (P != nullptr )
111136 ResolvedPath = *P;
112137 }
0 commit comments