Skip to content

Commit

Permalink
[lld][WebAssembly] Fix stub library parsing with windows line endings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbc100 committed Apr 4, 2023
1 parent 2f268b7 commit d9d840c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lld/test/wasm/Inputs/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ensures that we test parsing of stub libraries that contain
# windows line endings
libstub.so text eol=crlf
2 changes: 1 addition & 1 deletion lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,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;
}
Expand Down
18 changes: 11 additions & 7 deletions lld/wasm/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit d9d840c

Please sign in to comment.