[llvm-commits] MachOObjectFile fix functions

Danil Malyshev dmalyshev at accesssoftek.com
Mon Nov 7 14:40:51 PST 2011


Hello Owen,

Please find attached the changed patch which addresses the following 2 things:
1. Functions in ELFObjectFile, MachOObjectFile and COFFObjectFile should returns same result.
2. We don't need have several functions with similar functionality which can be obtained by other means.

getSymbolAddress - removed.
getRelocationAddress - removed.

getSymbolOffset - returns the offset from the beginning of the section.
If we need the virtual address we can use something like symbol.getOffset() + symbol.getSection().getAddress()
If we need the offset from the beginning of the object file, we can use something like symbol.getOffset() + symbol.getSection().getSectionContents().begin() - object->getData().begin()
If we need the pointer to the first byte of symbol we can use something like getOffset() + getSection().getSectionContents().begin()

getRelocationOffset - returns the offset from the beginning of the section.
If we need the virtual address we can use somethings like reloc.getOffset() + reloc.getSection().getAddress()
If we need the offset from the beginning of the object file, we can use something like reloc.getOffset() + reloc.getSection().getSectionContents().begin() - object->getData().begin()
If we need the pointer to the first byte of relocation address we can use something like reloc.getOffset() + reloc.getSection().getSectionContents().begin()


Regards,
Danil


________________________________
From: Owen Anderson [mailto:resistor at mac.com]
Sent: Friday, November 04, 2011 12:49 PM
To: Danil Malyshev
Cc: 'llvm-commits at cs.uiuc.edu'
Subject: Re: [llvm-commits] MachOObjectFile fix functions

Danil,

These changes are not correct.  I've spent a lot of time over the last few weeks getting these right by comparing them with existing MachO tools.  While it's quite possible there are still bugs, I'm fairly confident of them in general.  Specific incorrectness are noted below:

- getSymbolOffset

The Value field of a MachO symbol table entry is a virtual address, not a file offset.  AFAIK, the best way to find the file offset for the symbol is to get the subtract the section virtual address from the symbol virtual address, and add that to section offset.

- getSymbolAddress

Your implementation of this seems to be based on an incorrect understanding of what this method is supposed to return.  It is supposed to return the virtual address of the symbol, i.e. the address where the symbol will reside when the dynamic linker maps this object.  Instead, you're returning a pointer in the current process's address space, based on where the object file happens to be memory mapped at the moment.  If the ELF implementation does this, it is simply wrong.

- getRelocationAddress

This change is simply wrong.  The value field on MachO relocations holds an offset from the beginning of the section, not a virtual address.  You have to add that the the current section's virtual address to obtain the correct value, as the existing code currently does.

--Owen

On Nov 03, 2011, at 02:54 PM, Danil Malyshev <dmalyshev at accesssoftek.com> wrote:
Hello everyone,

Please find attached the patch for review.
The patch changed several MachOObjectFile functions:
- Fix getSymbolOffset(), getSymbolAddress() and getRelocationAddress(), now it's works same as in ELFObjectFile.
- Add implementation getSymbolSize()


Regards,
Danil

_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu<mailto: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/20111107/21bead27/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ObjectFile_fix_functions-01.patch
Type: application/octet-stream
Size: 17755 bytes
Desc: ObjectFile_fix_functions-01.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111107/21bead27/attachment.obj>


More information about the llvm-commits mailing list