Skip to content

Commit 7cbf1a2

Browse files
sbc100tstellar
authored andcommitted
[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 d9d840c)
1 parent 10c3bdc commit 7cbf1a2

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

lld/test/wasm/Inputs/.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ensures that we test parsing of stub libraries that contain
2+
# windows line endings
3+
libstub.so text eol=crlf

lld/wasm/Driver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void LinkerDriver::addFile(StringRef path) {
281281
files.push_back(createObjectFile(mbref));
282282
break;
283283
case file_magic::unknown:
284-
if (mbref.getBuffer().starts_with("#STUB\n")) {
284+
if (mbref.getBuffer().starts_with("#STUB")) {
285285
files.push_back(make<StubFile>(mbref));
286286
break;
287287
}

lld/wasm/InputFiles.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,16 @@ StringRef strip(StringRef s) {
691691
}
692692

693693
void StubFile::parse() {
694-
bool first = false;
694+
bool first = true;
695+
696+
SmallVector<StringRef> lines;
697+
mb.getBuffer().split(lines, '\n');
698+
for (StringRef line : lines) {
699+
line = line.trim();
695700

696-
for (StringRef line : args::getLines(mb)) {
697701
// File must begin with #STUB
698702
if (first) {
699-
assert(line == "#STUB\n");
703+
assert(line == "#STUB");
700704
first = false;
701705
}
702706

@@ -713,10 +717,10 @@ void StubFile::parse() {
713717
symbolDependencies[sym] = {};
714718

715719
while (rest.size()) {
716-
StringRef first;
717-
std::tie(first, rest) = rest.split(',');
718-
first = strip(first);
719-
symbolDependencies[sym].push_back(first);
720+
StringRef dep;
721+
std::tie(dep, rest) = rest.split(',');
722+
dep = strip(dep);
723+
symbolDependencies[sym].push_back(dep);
720724
}
721725
}
722726
}

0 commit comments

Comments
 (0)