Skip to content

Conversation

@parth-07
Copy link
Contributor

This commit fixes the parsing / interpretation of "archive:mem" file pattern. Previously, it was getting incorrectly stored because we were not properly handling quotes when a single quoted token in the linker script ("archive:member") is stored as two separate patterns in the linker implementation.

Resolves #680

@parth-07 parth-07 force-pushed the ArchiveMemPattern branch 2 times, most recently from 11b25c9 to 90f1426 Compare December 29, 2025 20:22
@parth-07 parth-07 force-pushed the ArchiveMemPattern branch 2 times, most recently from 3756a39 to f784281 Compare January 13, 2026 11:01
Copy link
Contributor

@quic-seaswara quic-seaswara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/lib/Script/ScriptFile.cpp b/lib/Script/ScriptFile.cpp
index 8c048bb9..00feb8f9 100644
--- a/lib/Script/ScriptFile.cpp
+++ b/lib/Script/ScriptFile.cpp
@@ -538,13 +538,28 @@ StrToken *ScriptFile::createParserStr(const char *PText, size_t PLength) {

 StrToken *ScriptFile::createParserStr(llvm::StringRef S) {
   bool IsQuoted = false;
+  bool IsLeftQuoted = false;
+  bool IsRightQuoted = false;
   if (S.starts_with("\"")) {
-    S = S.substr(1, S.size() - 2);
-    IsQuoted = true;
+    if (S.ends_with("\""))  {
+      S = S.substr(1, S.size() - 2);
+      IsQuoted = true;
+    }
+    else {
+      S = S.substr(1, S.size() - 1);
+      IsLeftQuoted = true;
+    }
+  } else if (S.ends_with("\"")) {
+    S = S.substr(0, S.size() - 1);
+    IsRightQuoted = true;
   }
   StrToken *Tok = make<eld::StrToken>(S.str());
   if (IsQuoted)
     Tok->setQuoted();
+  if (IsLeftQuoted)
+    Tok->setLeftQuote();
+  if (IsRightQuoted)
+    Tok->setRightQuote();
   return Tok;
 }

diff --git a/lib/ScriptParser/ScriptParser.cpp b/lib/ScriptParser/ScriptParser.cpp
index 4e0b2047..126a8405 100644
--- a/lib/ScriptParser/ScriptParser.cpp
+++ b/lib/ScriptParser/ScriptParser.cpp
@@ -661,18 +661,11 @@ InputSectDesc::Spec ScriptParser::readInputSectionDescSpec(StringRef Tok) {
   if (!Tok.contains(':'))
     FilePat = createAndRegisterWildcardPattern(Tok);
   else {
-    bool isQuoted = Tok.starts_with("\"");
-    Tok = unquote(Tok);
     std::pair<llvm::StringRef, llvm::StringRef> Split = Tok.split(':');
     FilePat = createAndRegisterWildcardPattern(Split.first);
     if (!Split.second.empty()) {
       ArchiveMem = createAndRegisterWildcardPattern(Split.second);
     }
-    if (isQuoted) {
-      FilePat->setLeftQuote();
-      if (ArchiveMem)
-        ArchiveMem->setRightQuote();
-    }
     llvm::StringRef peekTok = peek();
     if (!atEOF() && peekTok != "(" &&
         computeLineNumber(peekTok) == getCurrentLineNumber()) {

I was approaching the problem in the way above.

The core issue is in createParserStr.

Can you please look into it ?

This commit fixes the parsing / interpretation of `"archive:mem"` file
pattern. Previously, it was getting incorrectly stored because we were
not properly handling quotes when a single quoted token in the
linker script (`"archive:member"`) is stored as two separate patterns
in the linker implementation.

Resolves qualcomm#680

Signed-off-by: Parth Arora <partaror@qti.qualcomm.com>
@parth-07
Copy link
Contributor Author

I was approaching the problem in the way above.

The core issue is in createParserStr.

Can you please look into it ?

I have updated the code to the solution suggested by you.

@quic-seaswara quic-seaswara merged commit 96a7dff into qualcomm:main Jan 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"archive:mem" input section description is not interpreted correctly when it is within quotes

2 participants