[lld] 3a7bcba - [lld][WebAssembly] Cleanup output of --verbose

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 08:39:58 PDT 2021


Author: Sam Clegg
Date: 2021-09-10T11:35:50-04:00
New Revision: 3a7bcba34b3aac01d2a7fc921c9e58e7b55e5d52

URL: https://github.com/llvm/llvm-project/commit/3a7bcba34b3aac01d2a7fc921c9e58e7b55e5d52
DIFF: https://github.com/llvm/llvm-project/commit/3a7bcba34b3aac01d2a7fc921c9e58e7b55e5d52.diff

LOG: [lld][WebAssembly] Cleanup output of --verbose

Remove some unnecessary logging from wasm-ld when running under
`--verbose`.  Unlike `-debug` this logging is available in release
builds.  This change makes it little more minimal/readable.

Also, avoid compiling the `debugWrite` function in releaase builds
where it does nothing.  This should remove a lot debug strings from
the binary, and avoid having to construct unused debug strings at
runtime.

Differential Revision: https://reviews.llvm.org/D109583

Added: 
    

Modified: 
    lld/wasm/InputFiles.cpp
    lld/wasm/InputFiles.h
    lld/wasm/OutputSections.cpp
    lld/wasm/OutputSections.h
    lld/wasm/Writer.cpp
    lld/wasm/WriterUtils.cpp
    lld/wasm/WriterUtils.h

Removed: 
    


################################################################################
diff  --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 3f87df07a9519..664e657e9bfd2 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -88,15 +88,6 @@ InputFile *createObjectFile(MemoryBufferRef mb, StringRef archiveName) {
   fatal("unknown file type: " + mb.getBufferIdentifier());
 }
 
-void ObjFile::dumpInfo() const {
-  log("info for: " + toString(this) +
-      "\n              Symbols : " + Twine(symbols.size()) +
-      "\n     Function Imports : " + Twine(wasmObj->getNumImportedFunctions()) +
-      "\n       Global Imports : " + Twine(wasmObj->getNumImportedGlobals()) +
-      "\n          Tag Imports : " + Twine(wasmObj->getNumImportedTags()) +
-      "\n        Table Imports : " + Twine(wasmObj->getNumImportedTables()));
-}
-
 // Relocations contain either symbol or type indices.  This function takes a
 // relocation and returns relocated index (i.e. translates from the input
 // symbol/type space to the output symbol/type space).

diff  --git a/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h
index f4ff8bbb1d159..f67b7ced85d34 100644
--- a/lld/wasm/InputFiles.h
+++ b/lld/wasm/InputFiles.h
@@ -116,8 +116,6 @@ class ObjFile : public InputFile {
   // Returns the underlying wasm file.
   const WasmObjectFile *getWasmObj() const { return wasmObj.get(); }
 
-  void dumpInfo() const;
-
   uint32_t calcNewIndex(const WasmRelocation &reloc) const;
   uint64_t calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
                         const InputChunk *chunk) const;

diff  --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp
index 85994ea5f839e..d234c63071ebe 100644
--- a/lld/wasm/OutputSections.cpp
+++ b/lld/wasm/OutputSections.cpp
@@ -101,8 +101,8 @@ void CodeSection::finalizeContents() {
 }
 
 void CodeSection::writeTo(uint8_t *buf) {
-  log("writing " + toString(*this));
-  log(" size=" + Twine(getSize()));
+  log("writing " + toString(*this) + " offset=" + Twine(offset) +
+      " size=" + Twine(getSize()));
   log(" headersize=" + Twine(header.size()));
   log(" codeheadersize=" + Twine(codeSectionHeader.size()));
   buf += offset;
@@ -187,8 +187,8 @@ void DataSection::finalizeContents() {
 }
 
 void DataSection::writeTo(uint8_t *buf) {
-  log("writing " + toString(*this) + " size=" + Twine(getSize()) +
-      " body=" + Twine(bodySize));
+  log("writing " + toString(*this) + " offset=" + Twine(offset) +
+      " size=" + Twine(getSize()) + " body=" + Twine(bodySize));
   buf += offset;
 
   // Write section header
@@ -279,8 +279,8 @@ void CustomSection::finalizeContents() {
 }
 
 void CustomSection::writeTo(uint8_t *buf) {
-  log("writing " + toString(*this) + " size=" + Twine(getSize()) +
-      " chunks=" + Twine(inputSections.size()));
+  log("writing " + toString(*this) + " offset=" + Twine(offset) +
+      " size=" + Twine(getSize()) + " chunks=" + Twine(inputSections.size()));
 
   assert(offset);
   buf += offset;

diff  --git a/lld/wasm/OutputSections.h b/lld/wasm/OutputSections.h
index c3becf6ec2403..fcc8cf45dc73b 100644
--- a/lld/wasm/OutputSections.h
+++ b/lld/wasm/OutputSections.h
@@ -33,10 +33,7 @@ class OutputSection {
   virtual ~OutputSection() = default;
 
   StringRef getSectionName() const;
-  void setOffset(size_t newOffset) {
-    log("setOffset: " + toString(*this) + ": " + Twine(newOffset));
-    offset = newOffset;
-  }
+  void setOffset(size_t newOffset) { offset = newOffset; }
   void createHeader(size_t bodySize);
   virtual bool isNeeded() const { return true; }
   virtual size_t getSize() const = 0;

diff  --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 0adc971b499cf..ac81f14e547ea 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -1513,8 +1513,6 @@ void Writer::run() {
     log("Global Imports   : " + Twine(out.importSec->getNumImportedGlobals()));
     log("Tag Imports      : " + Twine(out.importSec->getNumImportedTags()));
     log("Table Imports    : " + Twine(out.importSec->getNumImportedTables()));
-    for (ObjFile *file : symtab->objectFiles)
-      file->dumpInfo();
   }
 
   createHeader();

diff  --git a/lld/wasm/WriterUtils.cpp b/lld/wasm/WriterUtils.cpp
index 17e7c17cf1f59..da7b2ebc58408 100644
--- a/lld/wasm/WriterUtils.cpp
+++ b/lld/wasm/WriterUtils.cpp
@@ -80,9 +80,11 @@ std::string toString(const WasmTableType &type) {
 }
 
 namespace wasm {
+#ifdef LLVM_DEBUG
 void debugWrite(uint64_t offset, const Twine &msg) {
   LLVM_DEBUG(dbgs() << format("  | %08lld: ", offset) << msg << "\n");
 }
+#endif
 
 void writeUleb128(raw_ostream &os, uint64_t number, const Twine &msg) {
   debugWrite(os.tell(), msg + "[" + utohexstr(number) + "]");

diff  --git a/lld/wasm/WriterUtils.h b/lld/wasm/WriterUtils.h
index 40daf45559483..f270cad809c24 100644
--- a/lld/wasm/WriterUtils.h
+++ b/lld/wasm/WriterUtils.h
@@ -16,7 +16,11 @@
 namespace lld {
 namespace wasm {
 
+#ifdef LLVM_DEBUG
 void debugWrite(uint64_t offset, const Twine &msg);
+#else
+#define debugWrite(...) (void *)0
+#endif
 
 void writeUleb128(raw_ostream &os, uint64_t number, const Twine &msg);
 


        


More information about the llvm-commits mailing list