Changeset 977c3de in rtems-tools for linkers/rld-files.h


Ignore:
Timestamp:
Nov 17, 2012, 6:34:33 AM (7 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, master
Children:
065ac15
Parents:
0b65a28
Message:

Refactor the ELF support to allow ELF write suppport.

The refactoring allows better reuse of the ELF support and cleans up
some hacks from the generic file and archive handling improving the
separation of the file handling from the file format, ie ELF. The
handling of ELF object files and ELF object files inside archives
is cleaner.

The refactor cleaned up the symbol handling where the symbols now
reside in the ELF file object and references are take in symbol
pointer containers and symbol table containers.

The main purpose of the refactor is to allow support for creating
and writing ELF files.

Also added an rtems-syms command where special symbol support
can be added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • linkers/rld-files.h

    r0b65a28 r977c3de  
    11/*
    2  * Copyright (c) 2011, Chris Johns <chrisj@rtems.org> 
     2 * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
    33 *
    44 * Permission to use, copy, modify, and/or distribute this software for any
    55 * purpose with or without fee is hereby granted, provided that the above
    66 * copyright notice and this permission notice appear in all copies.
    7  * 
     7 *
    88 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    99 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     
    2727 * created when the archive or object file was opened.
    2828 *
    29  * 
     29 *
    3030 */
    3131
     
    6868     */
    6969    typedef std::list < object* > object_list;
    70    
     70
    7171    /**
    7272     * Split a path from a string with a delimiter to the path container. Add
     
    7979     * Make a path by joining the parts with required separator.
    8080     */
    81     void path_join (const std::string& path_, 
    82                     const std::string& file_, 
     81    void path_join (const std::string& path_,
     82                    const std::string& file_,
    8383                    std::string& joined);
    8484
     
    9292     */
    9393    bool check_directory (const std::string& path);
    94    
     94
    9595    /**
    9696     * Find the file given a container of paths and file names.
     
    100100     * @param search_paths The container of paths to search.
    101101     */
    102     void find_file (std::string&       path, 
     102    void find_file (std::string&       path,
    103103                    const std::string& name,
    104104                    paths&             search_paths);
     
    324324
    325325      /**
    326        * The libelf reference. The ELF image could be in an archive container
    327        * so set container to true to get the archive's reference.
    328        */
    329       virtual rld::elf::elf* elf (bool archive = false);
    330 
    331       /**
    332        * Set the libelf reference.
    333        */
    334       void set_elf (rld::elf::elf* elf);
     326       * The ELF reference.
     327       */
     328      elf::file& elf ();
    335329
    336330      /**
     
    354348
    355349      /**
    356        * Is the archive open ?
    357        *
    358        * @retval true The archive is open.
    359        * @retval false The archive is not open.
     350       * Is the image open ?
     351       *
     352       * @retval true The image is open.
     353       * @retval false The image is not open.
    360354       */
    361355      bool is_open () const {
     
    363357      }
    364358
     359      /**
     360       * Is the image writable ?
     361       *
     362       * @retval true The image is writeable.
     363       * @retval false The image is not writeable.
     364       */
     365      bool is_writeable () const {
     366        return writeable;
     367      }
     368
    365369    private:
     370
    366371      file      name_;       //< The name of the file.
    367372      int       references_; //< The number of handles open.
    368373      int       fd_;         //< The file descriptor of the archive.
    369       elf::elf* elf_;        //< The libelf reference.
     374      elf::file elf_;        //< The libelf reference.
    370375      int       symbol_refs; //< The number of symbols references made.
     376      bool      writeable;   //< The image is writable.
    371377    };
    372378
     
    397403
    398404      /**
     405       * Begin the ELF session.
     406       */
     407      void begin ();
     408
     409      /**
     410       * End the ELF session.
     411       */
     412      void end ();
     413
     414      /**
    399415       * Match the archive name.
    400416       *
     
    414430       */
    415431      void load_objects (objects& objs);
    416      
     432
    417433      /**
    418434       * Get the name.
     
    432448
    433449    private:
     450
    434451      /**
    435452       * Read header.
     
    442459      void add_object (objects&    objs,
    443460                       const char* name,
    444                        off_t       offset, 
     461                       off_t       offset,
    445462                       size_t      size);
    446463
     
    529546       * Get the string from the string table.
    530547       */
    531       std::string get_string (int section, size_t offset);
     548//      std::string get_string (int section, size_t offset);
    532549
    533550      /**
     
    545562       */
    546563      virtual int fd () const;
    547 
    548       /**
    549        * The libelf reference. The ELF image could be in an archive container
    550        * so set container to true to get the archive's reference.
    551        */
    552       virtual elf::elf* elf (bool archive = false);
    553564
    554565      /**
     
    563574      archive* get_archive ();
    564575
     576#if 0
    565577      /**
    566578       * Number of sections in the object file.
     
    572584       */
    573585      int section_strings () const;
     586#endif
    574587
    575588      /**
     
    581594       * Return the list external symbols.
    582595       */
    583       rld::symbols::list& external_symbols ();
     596      rld::symbols::pointers& external_symbols ();
    584597
    585598    private:
    586       archive*            archive_;   //< Points to the archive if part of an
    587                                       //  archive.
    588       elf::elf_ehdr       ehdr;       //< The ELF header.
    589       rld::symbols::table unresolved; //< This object's unresolved symbols.
    590       rld::symbols::list  externals;  //< This object's external symbols.
     599      archive*               archive_;   //< Points to the archive if part of
     600                                         //  an archive.
     601      rld::symbols::table    unresolved; //< This object's unresolved symbols.
     602      rld::symbols::pointers externals;  //< This object's external symbols.
    591603
    592604      /**
     
    645657
    646658      /**
    647        * Being an ELF session on an archive.
     659       * Being a session on an archive.
    648660       */
    649661      void archive_begin (const std::string& path);
    650662
    651663      /**
    652        * End an ELF session on an archive.
     664       * End a session on an archive.
    653665       */
    654666      void archive_end (const std::string& path);
    655667
    656668      /**
    657        * Being ELF sessions on all archives.
     669       * Being sessions on all archives.
    658670       */
    659671      void archives_begin ();
    660672
    661673      /**
    662        * End the archive elf sessions.
     674       * End the archive sessions.
    663675       */
    664676      void archives_end ();
     
    668680       */
    669681      void collect_object_files ();
    670      
     682
    671683      /**
    672684       * Collect the object file names by verifing the paths to the files are
     
    674686       */
    675687      void collect_object_files (const std::string& path);
    676      
     688
    677689      /**
    678690       * Load the symbols into the symbol table.
     
    692704       */
    693705      archives& get_archives ();
    694  
     706
    695707      /**
    696708       * Get the objects inlcuding those in archives.
    697709       */
    698710      objects& get_objects ();
    699  
     711
    700712      /**
    701713       * Get the added objects. Does not include the ones in th archives.
Note: See TracChangeset for help on using the changeset viewer.