[llvm-dev] Modifying objects with MC

Sean Silva via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 26 20:27:32 PDT 2015

On Tue, Aug 25, 2015 at 2:30 AM, Simon Cook via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
> 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?

Just get a reference to the bytes you want to edit and then write through
the returned pointer. Just make that the file is mapped as writable,
otherwise you will obviously segfault.

-- Sean Silva

> Thanks,
> Simon
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150826/b649149f/attachment.html>

More information about the llvm-dev mailing list