Changeset cad8b53 in rtems-tools for linkers/rtems-ld.cpp


Ignore:
Timestamp:
Nov 26, 2012, 12:09:06 AM (7 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, master
Children:
eb825b1
Parents:
a458e27
Message:

Updated to reflect the framework changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • linkers/rtems-ld.cpp

    ra458e27 rcad8b53  
    5858  { "map",         no_argument,            NULL,           'M' },
    5959  { "output",      required_argument,      NULL,           'o' },
    60   { "script",      no_argument,            NULL,           'S' },
     60  { "out-format",  required_argument,      NULL,           'O' },
    6161  { "lib-path",    required_argument,      NULL,           'L' },
    6262  { "lib",         required_argument,      NULL,           'l' },
     
    9393            << " -M        : generate map output (also --map)" << std::endl
    9494            << " -o file   : linker output is written to file (also --output)" << std::endl
    95             << " -S        : linker output is a script file (also --script)" << std::endl
     95            << " -O format : linker output format, default is 'rap' (also --out-format)" << std::endl
    9696            << " -L path   : path to a library, add multiple for more than" << std::endl
    9797            << "             one path (also --lib-path)" << std::endl
     
    109109            << " -E prefix : the RTEMS tool prefix (also --exec-prefix)" << std::endl
    110110            << " -a march  : machine architecture (also --march)" << std::endl
    111             << " -c cpu    : machine architecture's CPU (also --mcpu)" << std::endl;
     111            << " -c cpu    : machine architecture's CPU (also --mcpu)" << std::endl
     112            << "Output Formats:" << std::endl
     113            << " rap     - RTEMS application (LZ77, single image)" << std::endl
     114            << " elf     - ELF application (script, ELF files)" << std::endl
     115            << " script  - Script format (list of object files)" << std::endl
     116            << " archive - Archive format (collection of ELF files)" << std::endl;
    112117  ::exit (exit_code);
    113118}
     
    168173    rld::symbols::table  undefined;
    169174    std::string          entry = "rtems";
     175    std::string          exit;
    170176    std::string          output = "a.out";
    171177    std::string          base_name;
    172178    std::string          cc_name;
    173     rld::outputter::type output_type = rld::outputter::ot_application;
     179    std::string          output_type = "rap";
    174180    bool                 standard_libs = true;
    175181    bool                 exec_prefix_set = false;
     
    181187    while (true)
    182188    {
    183       int opt = ::getopt_long (argc, argv, "hvwVMnSb:E:o:L:l:a:c:e:d:u:C:", rld_opts, NULL);
     189      int opt = ::getopt_long (argc, argv, "hvwVMnb:E:o:O:L:l:a:c:e:d:u:C:", rld_opts, NULL);
    184190      if (opt < 0)
    185191        break;
     
    211217          break;
    212218
    213         case 'S':
    214           output_type = rld::outputter::ot_script;
     219        case 'O':
     220          output_type = optarg;
    215221          break;
    216222
     
    291297
    292298    /*
     299     * Check the output format is valid.
     300     */
     301    if ((output_type != "rap") &&
     302        (output_type != "elf") &&
     303        (output_type != "script") &&
     304        (output_type != "archive"))
     305      throw rld::error ("invalid output format", "options");
     306
     307    /*
    293308     * Load the remaining command line arguments into the cache as object
    294309     * files.
     
    338353    if (base_name.length ())
    339354    {
     355      if (rld::verbose ())
     356        std::cout << "base-image: " << base_name << std::endl;
    340357      base.open ();
    341358      base.add (base_name);
     
    366383
    367384    /*
    368      * Load the symbol table.
    369      */
    370     cache.load_symbols (symbols);
    371 
    372     /*
    373      * Map ?
    374      */
    375     if (map)
     385     * Begin the archive session. This opens the archives and leaves them open
     386     * while we the symbol table is being used. The symbols reference object
     387     * files and the object files may reference archives and it is assumed they
     388     * are open and available. It is also assumed the number of library
     389     * archives being managed is less than the maximum file handles this
     390     * process can have open at any one time. If this is not the case this
     391     * approach would need to be reconsidered and the overhead of opening and
     392     * closing archives added.
     393     */
     394    try
    376395    {
    377       if (base_name.length ())
    378         rld::map (base, base_symbols);
    379       rld::map (cache, symbols);
    380     }
    381 
    382     if (cache.path_count ())
    383     {
     396      cache.archives_begin ();
     397
    384398      /*
    385        * This structure allows us to add different operations with the same
    386        * structure.
     399       * Load the symbol table.
    387400       */
    388       rld::files::object_list dependents;
    389       rld::resolver::resolve (dependents, cache, base_symbols, symbols, undefined);
    390 
    391       /**
    392        * Output the file.
     401      cache.load_symbols (symbols);
     402
     403      /*
     404       * Map ?
    393405       */
    394       switch (output_type)
     406      if (map)
    395407      {
    396         case rld::outputter::ot_script:
    397           rld::outputter::script (output, entry, dependents, cache);
    398           break;
    399         case rld::outputter::ot_archive:
    400           rld::outputter::archive (output, entry, dependents, cache);
    401           break;
    402         case rld::outputter::ot_application:
    403           rld::outputter::application (output, entry, dependents, cache);
    404           break;
    405         default:
     408        if (base_name.length ())
     409          rld::map (base, base_symbols);
     410        rld::map (cache, symbols);
     411      }
     412
     413      if (cache.path_count ())
     414      {
     415        /*
     416         * This structure allows us to add different operations with the same
     417         * structure.
     418         */
     419        rld::files::object_list dependents;
     420        rld::resolver::resolve (dependents, cache,
     421                                base_symbols, symbols, undefined);
     422
     423        /**
     424         * Output the file.
     425         */
     426        if (output_type == "script")
     427          rld::outputter::script (output, entry, exit, dependents, cache);
     428        else if (output_type == "archive")
     429          rld::outputter::archive (output, entry, exit, dependents, cache);
     430        else if (output_type == "elf")
     431          rld::outputter::elf_application (output, entry, exit,
     432                                           dependents, cache);
     433        else if (output_type == "rap")
     434          rld::outputter::application (output, entry, exit,
     435                                       dependents, cache, symbols);
     436        else
    406437          throw rld::error ("invalid output type", "output");
    407       }
    408 
    409       /**
    410        * Check for warnings.
    411        */
    412       if (warnings)
    413       {
    414         rld::warn_unused_externals (dependents);
     438
     439        /**
     440         * Check for warnings.
     441         */
     442        if (warnings)
     443        {
     444          rld::warn_unused_externals (dependents);
     445        }
    415446      }
    416447    }
     448    catch (...)
     449    {
     450      cache.archives_end ();
     451      throw;
     452    }
     453
     454    cache.archives_end ();
    417455  }
    418456  catch (rld::error re)
Note: See TracChangeset for help on using the changeset viewer.