[llvm-commits] [llvm] r151845 - in /llvm/trunk: include/llvm/Object/COFF.h include/llvm/Object/ELF.h include/llvm/Object/MachO.h include/llvm/Object/ObjectFile.h lib/Object/COFFObjectFile.cpp lib/Object/MachOObjectFile.cpp test/Object/readobj-shared-object.test tools/llvm-readobj/llvm-readobj.cpp
David Meyer
pdox at google.com
Thu Mar 1 14:19:54 PST 2012
Author: pdox
Date: Thu Mar 1 16:19:54 2012
New Revision: 151845
URL: http://llvm.org/viewvc/llvm-project?rev=151845&view=rev
Log:
[Object]
Add ObjectFile::getLoadName() for retrieving the soname/installname of a shared object.
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/include/llvm/Object/ELF.h
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/test/Object/readobj-shared-object.test
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Thu Mar 1 16:19:54 2012
@@ -164,6 +164,7 @@
virtual uint8_t getBytesInAddress() const;
virtual StringRef getFileFormatName() const;
virtual unsigned getArch() const;
+ virtual StringRef getLoadName() const;
error_code getHeader(const coff_file_header *&Res) const;
error_code getSection(int32_t index, const coff_section *&Res) const;
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Thu Mar 1 16:19:54 2012
@@ -369,6 +369,9 @@
DenseMap<const Elf_Sym*, ELF::Elf64_Word> ExtendedSymbolTable;
const Elf_Shdr *dot_dynamic_sec; // .dynamic
+ // Pointer to SONAME entry in dynamic string table
+ // This is set the first time getLoadName is called.
+ mutable const char *dt_soname;
/// @brief Map sections to an array of relocation sections that reference
/// them sorted by section index.
@@ -471,6 +474,7 @@
virtual uint8_t getBytesInAddress() const;
virtual StringRef getFileFormatName() const;
virtual unsigned getArch() const;
+ virtual StringRef getLoadName() const;
uint64_t getNumSections() const;
uint64_t getStringTableIndex() const;
@@ -1259,7 +1263,8 @@
, dot_shstrtab_sec(0)
, dot_strtab_sec(0)
, dot_dynstr_sec(0)
- , dot_dynamic_sec(0) {
+ , dot_dynamic_sec(0)
+ , dt_soname(0) {
const uint64_t FileSize = Data->getBufferSize();
@@ -1486,6 +1491,32 @@
}
template<support::endianness target_endianness, bool is64Bits>
+StringRef
+ELFObjectFile<target_endianness, is64Bits>::getLoadName() const {
+ if (!dt_soname) {
+ // Find the DT_SONAME entry
+ dyn_iterator it = begin_dynamic_table();
+ dyn_iterator ie = end_dynamic_table();
+ error_code ec;
+ while (it != ie) {
+ if (it->getTag() == ELF::DT_SONAME)
+ break;
+ it.increment(ec);
+ if (ec)
+ report_fatal_error("dynamic table iteration failed");
+ }
+ if (it != ie) {
+ if (dot_dynstr_sec == NULL)
+ report_fatal_error("Dynamic string table is missing");
+ dt_soname = getString(dot_dynstr_sec, it->getVal());
+ } else {
+ dt_soname = "";
+ }
+ }
+ return dt_soname;
+}
+
+template<support::endianness target_endianness, bool is64Bits>
library_iterator ELFObjectFile<target_endianness, is64Bits>
::begin_libraries_needed() const {
// Find the first DT_NEEDED entry
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Thu Mar 1 16:19:54 2012
@@ -42,6 +42,7 @@
virtual uint8_t getBytesInAddress() const;
virtual StringRef getFileFormatName() const;
virtual unsigned getArch() const;
+ virtual StringRef getLoadName() const;
MachOObject *getObject() { return MachOObj; }
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Thu Mar 1 16:19:54 2012
@@ -359,6 +359,11 @@
virtual StringRef getFileFormatName() const = 0;
virtual /* Triple::ArchType */ unsigned getArch() const = 0;
+ /// For shared objects, returns the name which this object should be
+ /// loaded from at runtime. This corresponds to DT_SONAME on ELF and
+ /// LC_ID_DYLIB (install name) on MachO.
+ virtual StringRef getLoadName() const = 0;
+
/// @returns Pointer to ObjectFile subclass to handle this type of object.
/// @param ObjectPath The path to the object file. ObjectPath.isObject must
/// return true.
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Thu Mar 1 16:19:54 2012
@@ -525,6 +525,12 @@
report_fatal_error("Libraries needed unimplemented in COFFObjectFile");
}
+StringRef COFFObjectFile::getLoadName() const {
+ // COFF does not have this field.
+ return "";
+}
+
+
section_iterator COFFObjectFile::begin_sections() const {
DataRefImpl ret;
std::memset(&ret, 0, sizeof(DataRefImpl));
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Thu Mar 1 16:19:54 2012
@@ -387,6 +387,11 @@
report_fatal_error("Needed libraries unimplemented in MachOObjectFile");
}
+StringRef MachOObjectFile::getLoadName() const {
+ // TODO: Implement
+ report_fatal_error("get_load_name() unimplemented in MachOObjectFile");
+}
+
/*===-- Sections ----------------------------------------------------------===*/
void MachOObjectFile::moveToNextSection(DataRefImpl &DRI) const {
Modified: llvm/trunk/test/Object/readobj-shared-object.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/readobj-shared-object.test?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/test/Object/readobj-shared-object.test (original)
+++ llvm/trunk/test/Object/readobj-shared-object.test Thu Mar 1 16:19:54 2012
@@ -1,7 +1,22 @@
RUN: llvm-readobj %p/Inputs/shared-object-test.elf-i386 \
RUN: | FileCheck %s -check-prefix ELF
+RUN: llvm-readobj %p/Inputs/shared-object-test.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF32
+
RUN: llvm-readobj %p/Inputs/shared-object-test.elf-x86-64 \
RUN: | FileCheck %s -check-prefix ELF
+RUN: llvm-readobj %p/Inputs/shared-object-test.elf-x86-64 \
+RUN: | FileCheck %s -check-prefix ELF64
+
+ELF64:File Format : ELF64-x86-64
+ELF64:Arch : x86_64
+ELF64:Address Size: 64 bits
+ELF64:Load Name : libfoo.so
+
+ELF32:File Format : ELF32-i386
+ELF32:Arch : i386
+ELF32:Address Size: 32 bits
+ELF32:Load Name : libfoo.so
ELF:Symbols:
ELF: .dynsym DBG {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} formatspecific
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=151845&r1=151844&r2=151845&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Thu Mar 1 16:19:54 2012
@@ -14,6 +14,7 @@
#include <string.h>
#include "llvm/Object/ObjectFile.h"
#include "llvm/Analysis/Verifier.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/PrettyStackTrace.h"
@@ -155,6 +156,16 @@
outs() << " Total: " << count << "\n\n";
}
+void DumpHeaders(const ObjectFile *obj) {
+ outs() << "File Format : " << obj->getFileFormatName() << "\n";
+ outs() << "Arch : "
+ << Triple::getArchTypeName((llvm::Triple::ArchType)obj->getArch())
+ << "\n";
+ outs() << "Address Size: " << (8*obj->getBytesInAddress()) << " bits\n";
+ outs() << "Load Name : " << obj->getLoadName() << "\n";
+ outs() << "\n";
+}
+
int main(int argc, char** argv) {
error_code ec;
sys::PrintStackTraceOnErrorSignal();
@@ -180,6 +191,7 @@
errs() << InputFilename << ": Object type not recognized\n";
}
+ DumpHeaders(obj);
DumpSymbols(obj);
DumpDynamicSymbols(obj);
DumpLibrariesNeeded(obj);
More information about the llvm-commits
mailing list