[LLVMdev] ELFObjectFile::getSymbolFileOffset

Kaylor, Andrew andrew.kaylor at intel.com
Fri Jan 18 15:13:07 PST 2013


While working on some other changes I came across a problem where ELFObjectFile::getSymbolFileOffset was returning a different value than I expected in the case where the symbol in question was a section.  Looking at the code, it seems obviously wrong, but  I didn't want to just commit my change without at least asking if anyone knew of a good reason for the current behavior.  I know there have been some discussions in the past about the address/offset ambiguity in this interface but I couldn't find anything directly addressing this question.

Looking at the revision history, it seems that the current implementation has been in place since getSymbolOffset was created (in lib/Object/ELFObjectFile.cpp, r139683) based on an earlier getSymbolAddress implementation and wasn't updated when other aspects of the function were corrected and the function was renamed getSymbolFileOffset(in lib/Object/ELFObjectFile.cpp, r145408) .

Here's the change I'm proposing (also attached as a patch file):

Index: include/llvm/Object/ELF.h
===================================================================
--- include/llvm/Object/ELF.h     (revision 172846)
+++ include/llvm/Object/ELF.h  (working copy)
@@ -1000,7 +1000,7 @@
   switch (symb->getType()) {
   case ELF::STT_SECTION:
-    Result = Section ? Section->sh_addr : UnknownAddressOrSize;
+    Result = Section ? Section->sh_offset : UnknownAddressOrSize;
     return object_error::success;
   case ELF::STT_FUNC:
   case ELF::STT_OBJECT:

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130118/506f6f0a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: section-offset.patch
Type: application/octet-stream
Size: 494 bytes
Desc: section-offset.patch
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130118/506f6f0a/attachment.obj>


More information about the llvm-dev mailing list