bintools/checklib/object/coff_object.cpp
changeset 2 39c28ec933dd
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     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 #include <cstring>
       
    25 
       
    26 Coff_object::Coff_object(const char* p1, const char* p2)
       
    27 {
       
    28     coff::File_header fh(p1, p2);
       
    29 
       
    30     unsigned nr_of_syms = fh.get_symcount();
       
    31     unsigned sym_size = coff::Symbol::get_entrysize();
       
    32 
       
    33     // Pointer to the first entry in the symbol table.
       
    34     p1 +=  fh.get_symtab_offset();
       
    35 
       
    36     // The string table is locates directly after the symbol table.
       
    37     coff::String_table strtab( p1 + nr_of_syms * sym_size);
       
    38 
       
    39     // Iterate over the whole symbol table.
       
    40     for (unsigned i = 0; i < nr_of_syms; i++, p1 += sym_size)
       
    41     {
       
    42         coff::Symbol s(p1, p2);
       
    43 
       
    44         // A symbol can have auxiliary entries that follows it.
       
    45         unsigned aux_count = s.get_auxcount();
       
    46 
       
    47         p1 += sym_size * aux_count;
       
    48         i += aux_count;
       
    49 
       
    50         if ( s.get_section() == 0 ) // If symbol is undefined ...
       
    51         {
       
    52             m_undef_symbols.push_back( strtab.get_string( s.get_name() ) );
       
    53         }
       
    54     }
       
    55 }
       
    56 
       
    57 Coff_object::~Coff_object() {}
       
    58 
       
    59 bool Coff_object::is_undef(const char a_sym[]) const
       
    60 {
       
    61     using std::find_if;
       
    62     using std::not1;
       
    63     using std::bind2nd;
       
    64     using std::ptr_fun;
       
    65     using std::strcmp;
       
    66 
       
    67     typedef std::vector<const char*> T;
       
    68 
       
    69     T::const_iterator beg_p = m_undef_symbols.begin();
       
    70     T::const_iterator end_p = m_undef_symbols.end();
       
    71 
       
    72     T::const_iterator pos = find_if( beg_p, end_p, not1(bind2nd( ptr_fun(strcmp), a_sym)) );
       
    73 
       
    74     return (pos != end_p);
       
    75 }
       
    76