third_party/android_crazy_linker/src/tests/pylib/elf_utils.py
def CSourceForElfSymbolTable(variable_prefix, names, str_offsets):
  """Generate C source definition for an ELF symbol table.

  Args:
    variable_prefix: variable name prefix
    names: List of symbol names.
    str_offsets: List of symbol name offsets in string table.
  Returns:
    String containing C source fragment.
  """
  out = (
r'''// NOTE: ELF32_Sym and ELF64_Sym have very different layout.
#if UINTPTR_MAX == UINT32_MAX  // ELF32_Sym
#  define DEFINE_ELF_SYMBOL(name, name_offset, address, size) \
    { (name_offset), (address), (size), ELF_ST_INFO(STB_GLOBAL, STT_FUNC), \
      0 /* other */, 1 /* shndx */ },
#else  // ELF64_Sym
#  define DEFINE_ELF_SYMBOL(name, name_offset, address, size) \
    { (name_offset), ELF_ST_INFO(STB_GLOBAL, STT_FUNC), \
      0 /* other */, 1 /* shndx */, (address), (size) },
#endif  // !ELF64_Sym
''')

  out += 'static const ELF::Sym k%sSymbolTable[] = {\n' % variable_prefix
  out += '    { 0 },  // ST_UNDEF\n'
  out += '    LIST_ELF_SYMBOLS_%s(DEFINE_ELF_SYMBOL)\n' % variable_prefix
  out += '};\n'
  out += '#undef DEFINE_ELF_SYMBOL\n'
  return out
Generate C source definition for an ELF symbol table.

  Args:
    variable_prefix: variable name prefix
    names: List of symbol names.
    str_offsets: List of symbol name offsets in string table.
  Returns:
    String containing C source fragment.
  
Generate C source definition for an ELF symbol table.
Generate C source definition for an ELF symbol table .
def CSourceForElfSymbolTable(variable_prefix, names, str_offsets):
  out = (
r'''// NOTE: ELF32_Sym and ELF64_Sym have very different layout.
#if UINTPTR_MAX == UINT32_MAX  // ELF32_Sym
#  define DEFINE_ELF_SYMBOL(name, name_offset, address, size) \
    { (name_offset), (address), (size), ELF_ST_INFO(STB_GLOBAL, STT_FUNC), \
      0 /* other */, 1 /* shndx */ },
#else  // ELF64_Sym
#  define DEFINE_ELF_SYMBOL(name, name_offset, address, size) \
    { (name_offset), ELF_ST_INFO(STB_GLOBAL, STT_FUNC), \
      0 /* other */, 1 /* shndx */, (address), (size) },
#endif  // !ELF64_Sym
''')
  out += 'static const ELF::Sym k%sSymbolTable[] = {\n' % variable_prefix
  out += '    { 0 },  // ST_UNDEF\n'
  out += '    LIST_ELF_SYMBOLS_%s(DEFINE_ELF_SYMBOL)\n' % variable_prefix
  out += '};\n'
  out += '#undef DEFINE_ELF_SYMBOL\n'
  return out
def CSourceForElfSymbolTable ( variable_prefix , names , str_offsets ) : out = ( r'''// NOTE: ELF32_Sym and ELF64_Sym have very different layout.
#if UINTPTR_MAX == UINT32_MAX  // ELF32_Sym
#  define DEFINE_ELF_SYMBOL(name, name_offset, address, size) \
    { (name_offset), (address), (size), ELF_ST_INFO(STB_GLOBAL, STT_FUNC), \
      0 /* other */, 1 /* shndx */ },
#else  // ELF64_Sym
#  define DEFINE_ELF_SYMBOL(name, name_offset, address, size) \
    { (name_offset), ELF_ST_INFO(STB_GLOBAL, STT_FUNC), \
      0 /* other */, 1 /* shndx */, (address), (size) },
#endif  // !ELF64_Sym
''' ) out += 'static const ELF::Sym k%sSymbolTable[] = {\n' % variable_prefix out += '    { 0 },  // ST_UNDEF\n' out += '    LIST_ELF_SYMBOLS_%s(DEFINE_ELF_SYMBOL)\n' % variable_prefix out += '};\n' out += '#undef DEFINE_ELF_SYMBOL\n' return out
Generate C source definition for an ELF symbol table.
Generate C source definition for an ELF symbol table .
"""Generate C source definition for an ELF symbol table.

  Args:
    variable_prefix: variable name prefix
    names: List of symbol names.
    str_offsets: List of symbol name offsets in string table.
  Returns:
    String containing C source fragment.
  """
String containing C source fragment.
String containing C source fragment .
variable_prefix
variable name prefix
variable name prefix
names
List of symbol names.
List of symbol names .
str_offsets
List of symbol name offsets in string table.
List of symbol name offsets in string table .