[llvm-commits] [llvm] r164365 - in /llvm/trunk: include/llvm/Object/ELF.h include/llvm/Object/ObjectFile.h test/Object/nm-shared-object.test test/Object/objdump-symbol-table.test
Alexey Samsonov
samsonov at google.com
Fri Sep 21 00:08:08 PDT 2012
Author: samsonov
Date: Fri Sep 21 02:08:08 2012
New Revision: 164365
URL: http://llvm.org/viewvc/llvm-project?rev=164365&view=rev
Log:
Fix SymbolRef::getAddress implementation for ELF. The 'value' field in symbol table entry should be treated differently for relocatable and relocated files. This patch fixes symbol addresses printed by llvm-nm for executables and shared objects.
Modified:
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/test/Object/nm-shared-object.test
llvm/trunk/test/Object/objdump-symbol-table.test
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=164365&r1=164364&r2=164365&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Fri Sep 21 02:08:08 2012
@@ -951,7 +951,18 @@
case ELF::STT_FUNC:
case ELF::STT_OBJECT:
case ELF::STT_NOTYPE:
- Result = symb->st_value + (Section ? Section->sh_addr : 0);
+ bool IsRelocatable;
+ switch(Header->e_type) {
+ case ELF::ET_EXEC:
+ case ELF::ET_DYN:
+ IsRelocatable = false;
+ break;
+ default:
+ IsRelocatable = true;
+ }
+ Result = symb->st_value;
+ if (IsRelocatable && Section != 0)
+ Result += Section->sh_addr;
return object_error::success;
default:
Result = UnknownAddressOrSize;
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=164365&r1=164364&r2=164365&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Fri Sep 21 02:08:08 2012
@@ -212,6 +212,8 @@
error_code getNext(SymbolRef &Result) const;
error_code getName(StringRef &Result) const;
+ /// Returns the symbol virtual address (i.e. address at which it will be
+ /// mapped).
error_code getAddress(uint64_t &Result) const;
error_code getFileOffset(uint64_t &Result) const;
error_code getSize(uint64_t &Result) const;
Modified: llvm/trunk/test/Object/nm-shared-object.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/nm-shared-object.test?rev=164365&r1=164364&r2=164365&view=diff
==============================================================================
--- llvm/trunk/test/Object/nm-shared-object.test (original)
+++ llvm/trunk/test/Object/nm-shared-object.test Fri Sep 21 02:08:08 2012
@@ -1,15 +1,23 @@
RUN: llvm-nm -D %p/Inputs/shared-object-test.elf-i386 \
-RUN: | FileCheck %s -check-prefix ELF
+RUN: | FileCheck %s -check-prefix ELF-32
RUN: llvm-nm -D %p/Inputs/shared-object-test.elf-x86-64 \
-RUN: | FileCheck %s -check-prefix ELF
+RUN: | FileCheck %s -check-prefix ELF-64
; Note: tls_sym should be 'D' (not '?'), but TLS is not
; yet recognized by ObjectFile.
-ELF: {{[0-9a-f]+}} A __bss_start
-ELF: {{[0-9a-f]+}} A _edata
-ELF: {{[0-9a-f]+}} A _end
-ELF: {{[0-9a-f]+}} B common_sym
-ELF: {{[0-9a-f]+}} D defined_sym
-ELF: {{[0-9a-f]+}} T global_func
-ELF: ? tls_sym
+ELF-32: 0012c8 A __bss_start
+ELF-32: 0012c8 A _edata
+ELF-32: 0012cc A _end
+ELF-32: 0012c8 B common_sym
+ELF-32: 0012c4 D defined_sym
+ELF-32: 0001f0 T global_func
+ELF-32: ? tls_sym
+
+ELF-64: 200454 A __bss_start
+ELF-64: 200454 A _edata
+ELF-64: 200458 A _end
+ELF-64: 200454 B common_sym
+ELF-64: 200450 D defined_sym
+ELF-64: 0002f0 T global_func
+ELF-64: ? tls_sym
Modified: llvm/trunk/test/Object/objdump-symbol-table.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/objdump-symbol-table.test?rev=164365&r1=164364&r2=164365&view=diff
==============================================================================
--- llvm/trunk/test/Object/objdump-symbol-table.test (original)
+++ llvm/trunk/test/Object/objdump-symbol-table.test Fri Sep 21 02:08:08 2012
@@ -4,6 +4,8 @@
RUN: | FileCheck %s -check-prefix ELF-i386
RUN: llvm-objdump -t %p/Inputs/trivial-object-test.macho-i386 \
RUN: | FileCheck %s -check-prefix macho-i386
+RUN: llvm-objdump -t %p/Inputs/shared-object-test.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF-shared
COFF-i386: file format
COFF-i386: SYMBOL TABLE:
@@ -31,3 +33,9 @@
macho-i386: 00000000 g F __TEXT,__text 00000024 _main
macho-i386: 00000000 *UND* 00000000 _SomeOtherFunction
macho-i386: 00000000 *UND* 00000000 _puts
+
+ELF-shared: shared-object-test.elf-i386: file format
+ELF-shared: SYMBOL TABLE:
+ELF-shared: 00000200 l F .text 00000003 local_func
+ELF-shared: 000012c4 g .data 00000004 defined_sym
+ELF-shared: 000001f0 g F .text 00000003 global_func
More information about the llvm-commits
mailing list