[llvm-dev] Modifying objects with MC
Jim Grosbach via llvm-dev
llvm-dev at lists.llvm.org
Wed Aug 26 19:07:05 PDT 2015
A mutable interface to object files would be great to have but doesn't exist in any meaningful sense in LLVM today. David's hack and similar tricks are what's necessary right now.
I'd love to fix that as its a question that comes up not infrequently.
Sent from my iPhone
> On Aug 25, 2015, at 2:44 AM, David Chisnall via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>> On 25 Aug 2015, at 10:30, Simon Cook via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>> I've been trying to write a tool that reads in an ELF file and modifies
>> one section within that ELF file based on the data contained within
>> another section. Using llvm-objdump as a template of how to read an
>> object file, I've been able to read the latter section that tells me
>> what to edit, but I haven't found a way to edit the former, as
>> everything in the MCSection/ELFObjectFile/SectionRef classes seem to be
>> read-only as far as section contents are concerned.
>> The changes I would want to make don't change the size of any section,
>> all I need to do is for example zero the first n bytes of .text whilst
>> keeping the rest of the object the same. What would be the recommended
>> approach to achieving this goal?
> I have a similar use case and would also be interested in an answer. In the meantime, I have a horrible hack that may work for you.
> My current hack works because the returned StringRefs for the SymbolRef::getContents are within the range of the MemoryBuffer and so the offset relative to the memory buffer corresponds to the file offset and this offset can be used to write into the file directly.
> It’s a horrible hack though, and it would be nice to simply have a mutable memory buffer that can be written back to the file (or to a different file).
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
More information about the llvm-dev