[llvm] r227778 - [Orc] Make the ObjectLinkingLayer take ownership of object files until

Lang Hames lhames at gmail.com
Sun Feb 1 21:11:14 PST 2015


Perhaps, but I think it would be difficult. You still want to free the
objects after relocations are applied, but that's done lazily in the
ObjectLinkingLayer, which makes it the best candidate for managing the
memory.

The plan is for this to be a short term hack, so it didn't seem worth the
effort.

- Lang.

On Sun, Feb 1, 2015 at 8:51 PM, David Blaikie <dblaikie at gmail.com> wrote:

>
>
> On Sun, Feb 1, 2015 at 8:32 PM, Lang Hames <lhames at gmail.com> wrote:
>
>> Author: lhames
>> Date: Sun Feb  1 22:32:17 2015
>> New Revision: 227778
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=227778&view=rev
>> Log:
>> [Orc] Make the ObjectLinkingLayer take ownership of object files until
>> finalization time.
>>
>> As currently implemented, RuntimeDyldELF requires the original object
>> file to be avaible when relocations are being resolved. This patch
>> ensures that the ObjectLinkingLayer preserves it until then. In the
>> future RuntimeDyldELF should be rewritten to remove this requirement, at
>> which point this patch can be reverted.
>>
>> Regression test cases for Orc (which include coverage of this bug) will
>> be committed shortly.
>>
>>
>> Modified:
>>     llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
>>     llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
>>
>> Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=227778&r1=227777&r2=227778&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
>> (original)
>> +++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h Sun Feb
>> 1 22:32:17 2015
>> @@ -76,7 +76,12 @@ public:
>>        Buffers.push_back(std::move(Buffer));
>>      }
>>
>> -    return BaseLayer.addObjectSet(std::move(Objects), std::move(MM));
>> +    ModuleSetHandleT H =
>> +      BaseLayer.addObjectSet(Objects, std::move(MM));
>> +
>> +    BaseLayer.takeOwnershipOfBuffers(H, std::move(Buffers));
>
>
> Could you just keep ownership on this layer, rather than passing it down?
>
>
>> +
>> +    return H;
>>    }
>>
>>    /// @brief Remove the module set associated with the handle H.
>>
>> Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h?rev=227778&r1=227777&r2=227778&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
>> (original)
>> +++ llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h Sun
>> Feb  1 22:32:17 2015
>> @@ -61,6 +61,7 @@ protected:
>>        RTDyld->resolveRelocations();
>>        RTDyld->registerEHFrames();
>>        MM->finalizeMemory();
>> +      OwnedBuffers.clear();
>>        State = Finalized;
>>      }
>>
>> @@ -70,10 +71,19 @@ protected:
>>        RTDyld->mapSectionAddress(LocalAddress, TargetAddress);
>>      }
>>
>> +    void takeOwnershipOfBuffer(std::unique_ptr<MemoryBuffer> B) {
>> +      OwnedBuffers.push_back(std::move(B));
>> +    }
>> +
>>    private:
>>      std::unique_ptr<RTDyldMemoryManager> MM;
>>      std::unique_ptr<RuntimeDyld> RTDyld;
>>      enum { Raw, Finalizing, Finalized } State;
>> +
>> +    // FIXME: This ownership hack only exists because RuntimeDyldELF
>> still
>> +    //        wants to be able to inspect the original object when
>> resolving
>> +    //        relocations. As soon as that can be fixed this should be
>> removed.
>> +    std::vector<std::unique_ptr<MemoryBuffer>> OwnedBuffers;
>>    };
>>
>>    typedef std::list<LinkedObjectSet> LinkedObjectSetListT;
>> @@ -81,6 +91,16 @@ protected:
>>  public:
>>    /// @brief Handle to a set of loaded objects.
>>    typedef LinkedObjectSetListT::iterator ObjSetHandleT;
>> +
>> +  // Ownership hack.
>> +  // FIXME: Remove this as soon as RuntimeDyldELF can apply relocations
>> without
>> +  //        referencing the original object.
>> +  template <typename OwningMBSet>
>> +  void takeOwnershipOfBuffers(ObjSetHandleT H, OwningMBSet MBs) {
>> +    for (auto &MB : MBs)
>> +      H->takeOwnershipOfBuffer(std::move(MB));
>> +  }
>> +
>>  };
>>
>>  /// @brief Default (no-op) action to perform when loading objects.
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150201/ffda6a6b/attachment.html>


More information about the llvm-commits mailing list