[dsymutil] Update vector of section starts with size of current section
authorAugusto Noronha <augusto2112@me.com>
Tue, 22 Mar 2022 17:11:32 +0000 (14:11 -0300)
committerAugusto Noronha <augusto2112@me.com>
Wed, 23 Mar 2022 13:15:54 +0000 (10:15 -0300)
Take into account the contributions of the sections from different
object files when calculating the address where relocations should be
applied.

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

llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
llvm/tools/dsymutil/DwarfLinkerForBinary.h

index 8b40816368debb3b39f65859179b8e76d6258dba..fef9f25bf7c273111c312751d950ebc988244be7 100644 (file)
@@ -494,7 +494,7 @@ void DwarfLinkerForBinary::collectRelocationsToApplyToSwiftReflectionSections(
 
 void DwarfLinkerForBinary::copySwiftReflectionMetadata(
     const llvm::dsymutil::DebugMapObject *Obj, DwarfStreamer *Streamer,
-    const std::vector<uint64_t> &SectionToOffsetInDwarf,
+    std::vector<uint64_t> &SectionToOffsetInDwarf,
     std::vector<MachOUtils::DwarfRelocationApplicationInfo>
         &RelocationsToApply) {
   using binaryformat::Swift5ReflectionSectionKind;
@@ -539,6 +539,10 @@ void DwarfLinkerForBinary::copySwiftReflectionMetadata(
       collectRelocationsToApplyToSwiftReflectionSections(
           Section, *SectionContents, MO, SectionToOffsetInDwarf, Obj,
           RelocationsToApply);
+      // Update the section start with the current section's contribution, so
+      // the next section we copy from a different .o file points to the correct
+      // place.
+      SectionToOffsetInDwarf[SectionKind] += Section.getSize();
       Streamer->emitSwiftReflectionSection(SectionKind, *SectionContents,
                                            Section.getAlignment(),
                                            Section.getSize());
index 3a363d82ef16a2246d1d753e938af900a29bc37f..dd29b1ff98acbd33ff2221768b0797232b48af6e 100644 (file)
@@ -214,7 +214,7 @@ private:
 
   void copySwiftReflectionMetadata(
       const llvm::dsymutil::DebugMapObject *Obj, DwarfStreamer *Streamer,
-      const std::vector<uint64_t> &SectionToOffsetInDwarf,
+      std::vector<uint64_t> &SectionToOffsetInDwarf,
       std::vector<MachOUtils::DwarfRelocationApplicationInfo>
           &RelocationsToApply);