[PATCH] D158124: [dsymutil] Add support for mergeable libraries

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 09:00:49 PDT 2023


avl added a comment.

In D158124#4608289 <https://reviews.llvm.org/D158124#4608289>, @Alpha wrote:

> In D158124#4601107 <https://reviews.llvm.org/D158124#4601107>, @avl wrote:
>
>> 3. Skipping and then inserting DW_AT_APPLE_origin attribute looks a bit screwed. Can we just update it if the attribute is presented(as it is done for other attributes) and add it if the attribute does not exist?
>
> That sounds reasonable.
>
> For the other 2 items, I'm fine with it, most of the issues boiled down to the fact that I'm not sure what is necessarily needed for relocations outside of dsymutil, and didn't want to pull out too specific stuff in the parent interfaces
> (things like `void saveRelinkedRelocs (SmallVector<ValidReloc>& Relocs)`). Looking into it.

if we want to keep  ValidReloc hidden from the DWARFLinker, then it is probably possible to use that solution:

  class AddressesMap {
    enum class SectionWithRelocationKind : uint8_t {
      DebugInfo,
      DebugAddr
    }
  
    void relinkRelocations ( SectionWithRelocationKind Kind, int64_t LinkedOffsetFixupVal, uint64_t StartOffset, uint64_t EndOffset );
  
  }
  
  struct AttributeLinkedOffsetFixup {
    SectionWithRelocationKind Kind;
    int64_t LinkedOffsetFixupVal;
    uint64_t InputAttrStartOffset;
    uint64_t InputAttrEndOffset;
  };
  
   DWARFLinker::cloneDIE() {
      ...
  *   SmallVector<AttributeLinkedOffsetFixup> AttributesFixups;
      for (const auto &AttrSpec : Abbrev->attributes()) {
        if (shouldSkipAttribute(Update, AttrSpec, Flags & TF_SkipPC)) {
          DWARFFormValue::skipValue(AttrSpec.Form, Data, &Offset,
                                    U.getFormParams());
          continue;
        }
  
        AttributeLinkedOffsetFixup CurAttrFixup;
  *    CurAttrFixup.Kind = DebugInfo or DebugAddr;
  *    CurAttrFixup.InputStartAttrOffset = InputDIE.getOffset() + Offset;
  *    CurAttrFixup.LinkedOffsetFixupVal = OutOffset - CurAttrFixup.InputStartAttrOffset);
        
        DWARFFormValue Val = AttrSpec.getFormValue();
        uint64_t AttrSize = Offset;
        Val.extractValue(Data, &Offset, U.getFormParams(), &U);
  *    CurAttrFixup.InputEndAttrOffset = InputDIE.getOffset() + Offset;
        AttrSize = Offset - AttrSize;
  
  
        uint64_t FinalAttrSize += cloneAttribute(*Die, InputDIE, File, Unit, Val, AttrSpec,
                                    AttrSize, AttrInfo, IsLittleEndian);
  
  *    if  (FinalAttrSize != 0) {
  *      AttributesFixups.push_back(CurAttrFixup);
  *    }
  
        OutOffset += FinalAttrSize;
      }
    
      ....
      Linker.assignAbbrev(NewAbbrev);
      Die->setAbbrevNumber(NewAbbrev.getNumber());
  
      // Add the size of the abbreviation number to the output offset.
      OutOffset += getULEB128Size(Die->getAbbrevNumber());
      ....
  *  updateFixupsWithAbbreviationNumberSize (getULEB128Size(Die->getAbbrevNumber(), AttributesFixups);
    
  *  for ( AttributeLinkedOffsetFixup& F :  AttributesFixups ) {
  *    ObjFile.Addresses->relinkRelocations(F.Kind, F.LinkedOffsetFixupVal, F.InputAttrStartOffset, F.InputAttrEndOffset )
  *  }
   }
  
  void updateFixupsWithAbbreviationNumberSize (uint64_t AbbrevNumberSize, SmallVector<ValidReloc>& Relocs) {
    for (AttributeLinkedOffsetFixup& F :  AttributesFixups) {
      F.LinkedOffsetFixupVal += AbbrevNumberSize;
    }
  }
  
    void DwarfLinkerForBinary::AddressManager<AddressesMapBase>::relinkRelocations ( SectionWithRelocationKind Kind, int64_t LinkedOffsetFixupVal, uint64_t StartOffset, uint64_t EndOffset ) {
      std::vector<ValidReloc> Relocs = getRelocations(AllRelocs, StartOffset, EndOffset);  
    
      for ( ValidReloc R : Relocs) {
        StoredValidDebugInfoRelocs.push_back ( { R.Offset + LinkedOffsetFixupVal, ... } );
      }
    }


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158124/new/

https://reviews.llvm.org/D158124



More information about the llvm-commits mailing list