[llvm-branch-commits] [lld] 7cbf1a2 - [lld][WebAssembly] Fix stub library parsing with windows line endings
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Jun 10 15:58:39 PDT 2023
Author: Sam Clegg
Date: 2023-06-10T15:58:16-07:00
New Revision: 7cbf1a2591520c2491aa35339f227775f4d3adf6
URL: https://github.com/llvm/llvm-project/commit/7cbf1a2591520c2491aa35339f227775f4d3adf6
DIFF: https://github.com/llvm/llvm-project/commit/7cbf1a2591520c2491aa35339f227775f4d3adf6.diff
LOG: [lld][WebAssembly] Fix stub library parsing with windows line endings
Also, fix checking of first line in ::parse. We can't use the
::getLines helper here since that already does comment stripping
internally.
Differential Revision: https://reviews.llvm.org/D147548
(cherry picked from commit d9d840cdaf51a9795930750d1b91d614a3849137)
Added:
lld/test/wasm/Inputs/.gitattributes
Modified:
lld/wasm/Driver.cpp
lld/wasm/InputFiles.cpp
Removed:
################################################################################
diff --git a/lld/test/wasm/Inputs/.gitattributes b/lld/test/wasm/Inputs/.gitattributes
new file mode 100644
index 0000000000000..6622904075b27
--- /dev/null
+++ b/lld/test/wasm/Inputs/.gitattributes
@@ -0,0 +1,3 @@
+# ensures that we test parsing of stub libraries that contain
+# windows line endings
+libstub.so text eol=crlf
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 8f7ed8b802d0c..762d4c97b0995 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -281,7 +281,7 @@ void LinkerDriver::addFile(StringRef path) {
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;
}
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 3d4fe939734df..a03166da973ac 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -691,12 +691,16 @@ StringRef strip(StringRef s) {
}
void StubFile::parse() {
- bool first = false;
+ bool first = true;
+
+ SmallVector<StringRef> 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 @@ void StubFile::parse() {
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);
}
}
}
More information about the llvm-branch-commits
mailing list