[llvm] r238698 - For COFF and MachO, compute the gap between to symbols.
Rafael Espindola
rafael.espindola at gmail.com
Sun May 31 16:15:35 PDT 2015
Author: rafael
Date: Sun May 31 18:15:35 2015
New Revision: 238698
URL: http://llvm.org/viewvc/llvm-project?rev=238698&view=rev
Log:
For COFF and MachO, compute the gap between to symbols.
Before r238028 we used to do this in O(N^2), now we do it in O(N log N).
Modified:
llvm/trunk/test/DebugInfo/debuglineinfo-macho.test
llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
Modified: llvm/trunk/test/DebugInfo/debuglineinfo-macho.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/debuglineinfo-macho.test?rev=238698&r1=238697&r2=238698&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/debuglineinfo-macho.test (original)
+++ llvm/trunk/test/DebugInfo/debuglineinfo-macho.test Sun May 31 18:15:35 2015
@@ -1,7 +1,12 @@
# Check that relocations get applied
RUN: llvm-dwarfdump %p/Inputs/test-simple-macho.o | FileCheck %s
RUN: llvm-dwarfdump %p/Inputs/test-multiple-macho.o | FileCheck %s
-RUN: llvm-rtdyld -printline %p/Inputs/test-multiple-macho.o | FileCheck %s
+RUN: llvm-rtdyld -printline %p/Inputs/test-multiple-macho.o | \
+RUN: FileCheck --check-prefix=SIZE %s
RUN: llvm-rtdyld -printobjline %p/Inputs/test-multiple-macho.o | FileCheck %s
+SIZE: Function: _bar, Size = 48
+SIZE: Function: _foo, Size = 16
+SIZE: Function: _fubar, Size = 46
+
CHECK-NOT: error: failed to compute relocation: X86_64_RELOC_UNSIGNED
Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp?rev=238698&r1=238697&r2=238698&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)
+++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Sun May 31 18:15:35 2015
@@ -247,6 +247,36 @@ static int printLineInfoForInput(bool Lo
std::unique_ptr<DIContext> Context(
new DWARFContextInMemory(*SymbolObj,LoadedObjInfo.get()));
+ // FIXME: This is generally useful. Figure out a place in lib/Object to
+ // put utility functions.
+ std::map<object::SectionRef, std::vector<uint64_t>> FuncAddresses;
+ if (!isa<ELFObjectFileBase>(SymbolObj)) {
+ for (object::SymbolRef Sym : SymbolObj->symbols()) {
+ object::SymbolRef::Type SymType;
+ if (Sym.getType(SymType))
+ continue;
+ if (SymType != object::SymbolRef::ST_Function)
+ continue;
+ uint64_t Addr;
+ if (Sym.getAddress(Addr))
+ continue;
+ object::section_iterator Sec = SymbolObj->section_end();
+ if (Sym.getSection(Sec))
+ continue;
+ std::vector<uint64_t> &Addrs = FuncAddresses[*Sec];
+ if (Addrs.empty()) {
+ uint64_t SecAddr = Sec->getAddress();
+ uint64_t SecSize = Sec->getSize();
+ Addrs.push_back(SecAddr + SecSize);
+ }
+ Addrs.push_back(Addr);
+ }
+ for (auto &Pair : FuncAddresses) {
+ std::vector<uint64_t> &Addrs = Pair.second;
+ array_pod_sort(Addrs.begin(), Addrs.end());
+ }
+ }
+
// Use symbol info to iterate functions in the object.
for (object::SymbolRef Sym : SymbolObj->symbols()) {
object::SymbolRef::Type SymType;
@@ -255,13 +285,25 @@ static int printLineInfoForInput(bool Lo
if (SymType == object::SymbolRef::ST_Function) {
StringRef Name;
uint64_t Addr;
- uint64_t Size;
if (Sym.getName(Name))
continue;
if (Sym.getAddress(Addr))
continue;
- if (Sym.getSize(Size))
- continue;
+
+ uint64_t Size;
+ if (isa<ELFObjectFileBase>(SymbolObj)) {
+ if (Sym.getSize(Size))
+ continue;
+ } else {
+ object::section_iterator Sec = SymbolObj->section_end();
+ if (Sym.getSection(Sec))
+ continue;
+ const std::vector<uint64_t> &Addrs = FuncAddresses[*Sec];
+ auto AddrI = std::find(Addrs.begin(), Addrs.end(), Addr);
+ assert(AddrI != Addrs.end() && (AddrI + 1) != Addrs.end());
+ assert(*AddrI == Addr);
+ Size = *(AddrI + 1) - Addr;
+ }
// If we're not using the debug object, compute the address of the
// symbol in memory (rather than that in the unrelocated object file)
More information about the llvm-commits
mailing list