Skip to content

Commit 0099797

Browse files
committed
[lld][WebAssembly] Fix reported names of LTO output file
This change was made in the ELF linker in #78835 but somehow never made it over the wasm port.
1 parent 097fef2 commit 0099797

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

lld/test/wasm/lto/signature-mismatch.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ define void @_start() {
1717

1818
; CHECK: error: function signature mismatch: f
1919
; CHECK: >>> defined as (i32) -> void in {{.*}}signature-mismatch.ll.tmp1.o
20-
; CHECK: >>> defined as () -> void in lto.tmp
20+
; CHECK: >>> defined as () -> void in {{.*}}signature-mismatch.ll.tmp.wasm.lto.o

lld/wasm/LTO.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ static void thinLTOCreateEmptyIndexFiles() {
183183

184184
// Merge all the bitcode files we have seen, codegen the result
185185
// and return the resulting objects.
186-
std::vector<StringRef> BitcodeCompiler::compile() {
186+
std::vector<MemoryBufferRef> BitcodeCompiler::compile() {
187187
unsigned maxTasks = ltoObj->getMaxTasks();
188188
buf.resize(maxTasks);
189189
files.resize(maxTasks);
190+
filenames.resize(maxTasks);
190191

191192
// The --thinlto-cache-dir option specifies the path to a directory in which
192193
// to cache native object files for ThinLTO incremental builds. If a path was
@@ -233,15 +234,21 @@ std::vector<StringRef> BitcodeCompiler::compile() {
233234
if (!ctx.arg.thinLTOCacheDir.empty())
234235
pruneCache(ctx.arg.thinLTOCacheDir, ctx.arg.thinLTOCachePolicy, files);
235236

236-
std::vector<StringRef> ret;
237+
std::vector<MemoryBufferRef> ret;
237238
for (unsigned i = 0; i != maxTasks; ++i) {
238239
StringRef objBuf = buf[i].second;
239240
StringRef bitcodeFilePath = buf[i].first;
241+
if (files[i]) {
242+
// When files[i] is not null, we get the native relocatable file from the
243+
// cache. filenames[i] contains the original BitcodeFile's identifier.
244+
objBuf = files[i]->getBuffer();
245+
bitcodeFilePath = filenames[i];
246+
} else {
247+
objBuf = buf[i].second;
248+
bitcodeFilePath = buf[i].first;
249+
}
240250
if (objBuf.empty())
241251
continue;
242-
ret.emplace_back(objBuf.data(), objBuf.size());
243-
if (!ctx.arg.saveTemps)
244-
continue;
245252

246253
// If the input bitcode file is path/to/x.o and -o specifies a.out, the
247254
// corresponding native relocatable file path will look like:
@@ -266,7 +273,10 @@ std::vector<StringRef> BitcodeCompiler::compile() {
266273
sys::path::remove_dots(path, true);
267274
ltoObjName = saver().save(path.str());
268275
}
269-
saveBuffer(objBuf, ltoObjName);
276+
if (ctx.arg.saveTemps)
277+
saveBuffer(objBuf, ltoObjName);
278+
llvm::dbgs() << "YYY: " << ltoObjName << "\n";
279+
ret.emplace_back(MemoryBufferRef(objBuf, ltoObjName));
270280
}
271281

272282
if (!ctx.arg.ltoObjPath.empty()) {
@@ -275,10 +285,6 @@ std::vector<StringRef> BitcodeCompiler::compile() {
275285
saveBuffer(buf[i].second, ctx.arg.ltoObjPath + Twine(i));
276286
}
277287

278-
for (std::unique_ptr<MemoryBuffer> &file : files)
279-
if (file)
280-
ret.push_back(file->getBuffer());
281-
282288
return ret;
283289
}
284290

lld/wasm/LTO.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ class BitcodeCompiler {
4545
~BitcodeCompiler();
4646

4747
void add(BitcodeFile &f);
48-
std::vector<StringRef> compile();
48+
std::vector<MemoryBufferRef> compile();
4949

5050
private:
5151
std::unique_ptr<llvm::lto::LTO> ltoObj;
5252
// An array of (module name, native relocatable file content) pairs.
5353
SmallVector<std::pair<std::string, SmallString<0>>, 0> buf;
5454
std::vector<std::unique_ptr<MemoryBuffer>> files;
55+
SmallVector<std::string, 0> filenames;
5556
std::unique_ptr<llvm::raw_fd_ostream> indexFile;
5657
llvm::DenseSet<StringRef> thinIndices;
5758
};

lld/wasm/SymbolTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ void SymbolTable::compileBitcodeFiles() {
8787
for (BitcodeFile *f : ctx.bitcodeFiles)
8888
lto->add(*f);
8989

90-
for (StringRef filename : lto->compile()) {
91-
auto *obj = make<ObjFile>(MemoryBufferRef(filename, "lto.tmp"), "");
90+
for (auto membuf : lto->compile()) {
91+
auto *obj = make<ObjFile>(membuf, "");
9292
obj->parse(true);
9393
ctx.objectFiles.push_back(obj);
9494
}

0 commit comments

Comments
 (0)