[lld] 7d09e1d - [lld][WebAssembly] Minor refactor in preparation for SHF_STRINGS supports. NFC.

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 1 16:19:02 PST 2021


Author: Sam Clegg
Date: 2021-03-01T16:15:29-08:00
New Revision: 7d09e1d7cf27ce781e83f9d388a7a3e1e6487ead

URL: https://github.com/llvm/llvm-project/commit/7d09e1d7cf27ce781e83f9d388a7a3e1e6487ead
DIFF: https://github.com/llvm/llvm-project/commit/7d09e1d7cf27ce781e83f9d388a7a3e1e6487ead.diff

LOG: [lld][WebAssembly] Minor refactor in preparation for SHF_STRINGS supports. NFC.

A couple of small changes to match the ELF linker in preparation
for adding support string mergings.

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

Added: 
    

Modified: 
    lld/wasm/InputChunks.h
    lld/wasm/OutputSegment.h
    lld/wasm/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
index 77a057395a48..fe30fea62d1c 100644
--- a/lld/wasm/InputChunks.h
+++ b/lld/wasm/InputChunks.h
@@ -42,7 +42,7 @@ class InputChunk {
   virtual uint32_t getSize() const { return data().size(); }
   virtual uint32_t getInputSize() const { return getSize(); };
 
-  virtual void writeTo(uint8_t *sectionStart) const;
+  virtual void writeTo(uint8_t *buf) const;
 
   ArrayRef<WasmRelocation> getRelocations() const { return relocations; }
   void setRelocations(ArrayRef<WasmRelocation> rs) { relocations = rs; }
@@ -98,13 +98,14 @@ class InputChunk {
 class InputSegment : public InputChunk {
 public:
   InputSegment(const WasmSegment &seg, ObjFile *f)
-      : InputChunk(f, InputChunk::DataSegment), segment(seg) {}
+      : InputChunk(f, InputChunk::DataSegment), segment(seg) {
+    alignment = segment.Data.Alignment;
+  }
 
   static bool classof(const InputChunk *c) { return c->kind() == DataSegment; }
 
   void generateRelocationCode(raw_ostream &os) const;
 
-  uint32_t getAlignment() const { return segment.Data.Alignment; }
   StringRef getName() const override { return segment.Data.Name; }
   StringRef getDebugName() const override { return StringRef(); }
   uint32_t getComdat() const override { return segment.Data.Comdat; }
@@ -114,7 +115,8 @@ class InputSegment : public InputChunk {
   uint64_t getVA(uint64_t offset = 0) const;
 
   const OutputSegment *outputSeg = nullptr;
-  int32_t outputSegmentOffset = 0;
+  uint32_t outputSegmentOffset = 0;
+  uint32_t alignment = 0;
 
 protected:
   ArrayRef<uint8_t> data() const override { return segment.Data.Content; }
@@ -137,7 +139,7 @@ class InputFunction : public InputChunk {
            c->kind() == InputChunk::SyntheticFunction;
   }
 
-  void writeTo(uint8_t *sectionStart) const override;
+  void writeTo(uint8_t *buf) const override;
   StringRef getName() const override { return function->SymbolName; }
   StringRef getDebugName() const override { return function->DebugName; }
   llvm::Optional<StringRef> getExportName() const {

diff  --git a/lld/wasm/OutputSegment.h b/lld/wasm/OutputSegment.h
index f6985ce855e6..30553b9883e2 100644
--- a/lld/wasm/OutputSegment.h
+++ b/lld/wasm/OutputSegment.h
@@ -22,8 +22,8 @@ class OutputSegment {
 public:
   OutputSegment(StringRef n) : name(n) {}
 
-  void addInputSegment(InputSegment *inSeg, uint32_t forceAlignment = 0) {
-    uint32_t segAlign = std::max(forceAlignment, inSeg->getAlignment());
+  void addInputSegment(InputSegment *inSeg) {
+    uint32_t segAlign = inSeg->alignment;
     alignment = std::max(alignment, segAlign);
     inputSegments.push_back(inSeg);
     size = llvm::alignTo(size, 1ULL << segAlign);

diff  --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index af2cbdb7146f..a1bd142ce83a 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -890,12 +890,13 @@ void Writer::combineOutputSegments() {
       }
       bool first = true;
       for (InputSegment *inSeg : s->inputSegments) {
-        uint32_t alignment = first ? s->alignment : 0;
+        if (first)
+          inSeg->alignment = std::max(inSeg->alignment, s->alignment);
         first = false;
 #ifndef NDEBUG
         uint64_t oldVA = inSeg->getVA();
 #endif
-        combined->addInputSegment(inSeg, alignment);
+        combined->addInputSegment(inSeg);
 #ifndef NDEBUG
         uint64_t newVA = inSeg->getVA();
         assert(oldVA == newVA);


        


More information about the llvm-commits mailing list