Changeset ef4a46e in rtems-tools


Ignore:
Timestamp:
Aug 25, 2016, 5:54:23 AM (3 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11
Children:
848344d
Parents:
e6a0675
git-author:
Chris Johns <chrisj@…> (08/25/16 05:54:23)
git-committer:
Chris Johns <chrisj@…> (08/25/16 05:57:21)
Message:

linkers/syms: Add weak symbols to the global symbol table.

Add any weak symbols that have been linked into the base image to the
global symbol table. A weak symbol is global when view viewed from
a dynamically loaded module.

Closes #2704.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • linkers/rtems-syms.cpp

    re6a0675 ref4a46e  
    147147 * a running RTEMS machine.
    148148 */
     149
     150struct output_sym
     151{
     152  rld::process::tempfile& c;
     153  const bool              embed;
     154  const bool              weak;
     155
     156  output_sym(rld::process::tempfile& c,
     157             bool                    embed,
     158             bool                    weak)
     159    : c (c),
     160      embed (embed),
     161      weak (weak) {
     162  }
     163
     164  void operator ()(const rld::symbols::symtab::value_type& value);
     165};
     166
     167void
     168output_sym::operator ()(const rld::symbols::symtab::value_type& value)
     169{
     170  const rld::symbols::symbol& sym = *(value.second);
     171
     172  /*
     173   * Weak symbols without a value are probably unresolved externs. Ignore them.
     174   */
     175  if (weak && sym.value () == 0)
     176    return;
     177
     178  c.write_line ("asm(\"  .asciz \\\"" + sym.name () + "\\\"\");");
     179
     180  if (embed)
     181  {
     182    c.write_line ("asm(\"  .long " + sym.name () + "\");");
     183  }
     184  else
     185  {
     186    std::stringstream oss;
     187    oss << std::hex << std::setfill ('0') << std::setw (8) << sym.value ();
     188    c.write_line ("asm(\"  .long 0x" + oss.str () + "\");");
     189  }
     190}
     191
     192
    149193static void
    150194generate_c (rld::process::tempfile& c,
    151               rld::symbols::table&  symbols,
    152               bool                  embed)
     195            rld::symbols::table&    symbols,
     196            bool                    embed)
    153197{
    154198  temporary_file_paint (c, c_header);
    155199
    156   for (rld::symbols::symtab::const_iterator si = symbols.globals ().begin ();
    157        si != symbols.globals ().end ();
    158        ++si)
    159   {
    160     const rld::symbols::symbol& sym = *((*si).second);
    161 
    162     c.write_line ("asm(\"  .asciz \\\"" + sym.name () + "\\\"\");");
    163 
    164     if (embed)
    165     {
    166       c.write_line ("asm(\"  .long " + sym.name () + "\");");
    167     }
    168     else
    169     {
    170       std::stringstream oss;
    171       oss << std::hex << std::setfill ('0') << std::setw (8) << sym.value ();
    172       c.write_line ("asm(\"  .long 0x" + oss.str () + "\");");
    173     }
    174   }
     200  /*
     201   * Add the global symbols.
     202   */
     203  std::for_each (symbols.globals ().begin (),
     204                 symbols.globals ().end (),
     205                 output_sym (c, embed, false));
     206
     207  /*
     208   * Add the weak symbols that have been linked into the base image. A weak
     209   * symbols present in the base image is no longer weak and should be consider
     210   * a global symbol. You cannot link a global symbol with the same in a
     211   * dynamically loaded module.
     212   */
     213  std::for_each (symbols.weaks ().begin (),
     214                 symbols.weaks ().end (),
     215                 output_sym (c, embed, true));
    175216
    176217  temporary_file_paint (c, c_trailer);
Note: See TracChangeset for help on using the changeset viewer.