toolsandutils/e32tools/checklib/object/coff_object.cpp
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "object.h"
       
    17 
       
    18 #include "coff/coff_file_header.h"
       
    19 #include "coff/coff_symbol.h"
       
    20 #include "coff/coff_string_table.h"
       
    21 
       
    22 #include <algorithm>
       
    23 #include <functional>
       
    24 
       
    25 Coff_object::Coff_object(const char* p1, const char* p2)
       
    26 {
       
    27     coff::File_header fh(p1, p2);
       
    28 
       
    29     unsigned nr_of_syms = fh.get_symcount();
       
    30     unsigned sym_size = coff::Symbol::get_entrysize();
       
    31 
       
    32     // Pointer to the first entry in the symbol table.
       
    33     p1 +=  fh.get_symtab_offset();
       
    34 
       
    35     // The string table is locates directly after the symbol table.
       
    36     coff::String_table strtab( p1 + nr_of_syms * sym_size);
       
    37 
       
    38     // Iterate over the whole symbol table.
       
    39     for (unsigned i = 0; i < nr_of_syms; i++, p1 += sym_size)
       
    40     {
       
    41         coff::Symbol s(p1, p2);
       
    42 
       
    43         // A symbol can have auxiliary entries that follows it.
       
    44         unsigned aux_count = s.get_auxcount();
       
    45 
       
    46         p1 += sym_size * aux_count;
       
    47         i += aux_count;
       
    48 
       
    49         if ( s.get_section() == 0 ) // If symbol is undefined ...
       
    50         {
       
    51             m_undef_symbols.push_back( strtab.get_string( s.get_name() ) );
       
    52         }
       
    53     }
       
    54 }
       
    55 
       
    56 Coff_object::~Coff_object() {}
       
    57 
       
    58 bool Coff_object::is_undef(const char a_sym[]) const
       
    59 {
       
    60     using std::find_if;
       
    61     using std::not1;
       
    62     using std::bind2nd;
       
    63     using std::ptr_fun;
       
    64     using std::strcmp;
       
    65 
       
    66     typedef std::vector<const char*> T;
       
    67 
       
    68     T::const_iterator beg_p = m_undef_symbols.begin();
       
    69     T::const_iterator end_p = m_undef_symbols.end();
       
    70 
       
    71     T::const_iterator pos = find_if( beg_p, end_p, not1(bind2nd( ptr_fun(strcmp), a_sym)) );
       
    72 
       
    73     return (pos != end_p);
       
    74 }
       
    75