summaryrefslogtreecommitdiffstats
path: root/libs/elfio/examples/RelocationTable
diff options
context:
space:
mode:
authorEvan Lojewski <github@meklort.com>2019-03-30 10:54:09 -0600
committerEvan Lojewski <github@meklort.com>2019-03-30 10:54:09 -0600
commit87285d38380d1cff8f9e00bb38143c566c5947c3 (patch)
tree24e152250ff7c422bf607cd2b5dc87ed85a12b7a /libs/elfio/examples/RelocationTable
parentcca53919aa8df5e94579269ee1cc6238008f9f2b (diff)
downloadbcm5719-ortega-87285d38380d1cff8f9e00bb38143c566c5947c3.tar.gz
bcm5719-ortega-87285d38380d1cff8f9e00bb38143c566c5947c3.zip
Move elfio to a standalone library.
Diffstat (limited to 'libs/elfio/examples/RelocationTable')
-rw-r--r--libs/elfio/examples/RelocationTable/RelocationTable.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/libs/elfio/examples/RelocationTable/RelocationTable.cpp b/libs/elfio/examples/RelocationTable/RelocationTable.cpp
new file mode 100644
index 0000000..5257078
--- /dev/null
+++ b/libs/elfio/examples/RelocationTable/RelocationTable.cpp
@@ -0,0 +1,56 @@
+#include <cstdio>
+#include <ELFIO.h>
+
+int main( int, char* argv[] )
+{
+ // Create a ELFI reader
+ IELFI* pReader;
+ ELFIO::GetInstance()->CreateELFI( &pReader );
+
+ // Initialize it
+ char* filename = argv[1];
+ pReader->Load( filename );
+
+ // Get .text relocation entry
+ // List all sections of the file
+ int i;
+ int nSecNo = pReader->GetSectionsNum();
+ for ( i = 0; i < nSecNo; ++i ) { // For all sections
+ const IELFISection* pSec = pReader->GetSection( i );
+ if ( SHT_REL != pSec->GetType() && SHT_RELA != pSec->GetType() ) {
+ pSec->Release();
+ continue;
+ }
+ const IELFIRelocationTable* pRel = 0;
+ pReader->CreateSectionReader( IELFI::ELFI_RELOCATION, pSec, (void**)&pRel );
+
+ // Print all entries
+ Elf64_Addr offset;
+ Elf64_Addr symbolValue;
+ std::string symbolName;
+ unsigned char type;
+ Elf_Sxword addend;
+ Elf_Sxword calcValue;
+ Elf_Xword nNum = pRel->GetEntriesNum();
+ if ( 0 < nNum ) {
+ std::printf( "\nSection name: %s\n", pSec->GetName().c_str() );
+ std::printf( " Num Type Offset Addend Calc SymValue SymName\n" );
+ for ( Elf_Xword i = 0; i < nNum; ++i ) {
+ pRel->GetEntry( i, offset, symbolValue, symbolName,
+ type, addend, calcValue );
+ std::printf( "[%4llx] %02x %08llx %08llx %08llx %08llx %s\n",
+ i, type, offset,
+ addend, calcValue,
+ symbolValue, symbolName.c_str() );
+ }
+ }
+
+ pSec->Release();
+ pRel->Release();
+ }
+
+ // Free resources
+ pReader->Release();
+
+ return 0;
+}
OpenPOWER on IntegriCloud