[PATCH] D147548: [lld][WebAssembly] Fix stub library parsing with windows line endings

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 10:31:22 PDT 2023


sbc100 created this revision.
Herald added subscribers: pmatos, asb, wingo, jdoerfert, ecnelises, sunfish, jgravelle-google, dschuff.
Herald added a project: All.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

Also, fix checking of first line in ::parse.  We can't use the
::getLines helper here since that already does comment stripping
internally.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147548

Files:
  lld/test/wasm/Inputs/.gitattributes
  lld/test/wasm/Inputs/libstub.so
  lld/wasm/Driver.cpp
  lld/wasm/InputFiles.cpp


Index: lld/wasm/InputFiles.cpp
===================================================================
--- lld/wasm/InputFiles.cpp
+++ lld/wasm/InputFiles.cpp
@@ -691,12 +691,16 @@
 }
 
 void StubFile::parse() {
-  bool first = false;
+  bool first = true;
+
+  SmallVector<StringRef, 0> lines;
+  mb.getBuffer().split(lines, '\n');
+  for (StringRef line : lines) {
+    line = line.trim();
 
-  for (StringRef line : args::getLines(mb)) {
     // File must begin with #STUB
     if (first) {
-      assert(line == "#STUB\n");
+      assert(line == "#STUB");
       first = false;
     }
 
@@ -713,10 +717,10 @@
     symbolDependencies[sym] = {};
 
     while (rest.size()) {
-      StringRef first;
-      std::tie(first, rest) = rest.split(',');
-      first = strip(first);
-      symbolDependencies[sym].push_back(first);
+      StringRef dep;
+      std::tie(dep, rest) = rest.split(',');
+      dep = strip(dep);
+      symbolDependencies[sym].push_back(dep);
     }
   }
 }
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -280,7 +280,7 @@
     files.push_back(createObjectFile(mbref));
     break;
   case file_magic::unknown:
-    if (mbref.getBuffer().starts_with("#STUB\n")) {
+    if (mbref.getBuffer().starts_with("#STUB")) {
       files.push_back(make<StubFile>(mbref));
       break;
     }
Index: lld/test/wasm/Inputs/libstub.so
===================================================================
--- lld/test/wasm/Inputs/libstub.so
+++ lld/test/wasm/Inputs/libstub.so
@@ -1,5 +1,5 @@
-#STUB
-# This is a comment
-foo: foodep1,foodep2
-# This symbols as no dependencies
-bar
+#STUB
+# This is a comment
+foo: foodep1,foodep2
+# This symbols as no dependencies
+bar
Index: lld/test/wasm/Inputs/.gitattributes
===================================================================
--- /dev/null
+++ lld/test/wasm/Inputs/.gitattributes
@@ -0,0 +1,3 @@
+# ensures that we test parsing of stub libraries that contain
+# windows line endings
+libstubs.so text eol=crlf


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147548.510852.patch
Type: text/x-patch
Size: 2076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230404/6c625909/attachment.bin>


More information about the llvm-commits mailing list