Example #1
0
void
i386_pe_unique_section (tree decl, int reloc)
{
    int len;
    const char *name, *prefix;
    char *string;

    name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
    name = i386_pe_strip_name_encoding_full (name);

    /* The object is put in, for example, section .text$foo.
       The linker will then ultimately place them in .text
       (everything from the $ on is stripped). Don't put
       read-only data in .rdata section to avoid a PE linker
       bug when .rdata$* grouped sections are used in code
       without a .rdata section.  */
    if (TREE_CODE (decl) == FUNCTION_DECL)
        prefix = ".text$";
    else if (decl_readonly_section (decl, reloc))
        prefix = ".rdata$";
    else
        prefix = ".data$";
    len = strlen (name) + strlen (prefix);
    string = alloca (len + 1);
    sprintf (string, "%s%s", prefix, name);

    DECL_SECTION_NAME (decl) = build_string (len, string);
}
Example #2
0
unsigned int
i386_pe_section_type_flags (tree decl, const char *name, int reloc)
{
  static htab_t htab;
  unsigned int flags;
  unsigned int **slot;

  /* The names we put in the hashtable will always be the unique
     versions given to us by the stringtable, so we can just use
     their addresses as the keys.  */
  if (!htab)
    htab = htab_create (31, htab_hash_pointer, htab_eq_pointer, NULL);

  if (decl && TREE_CODE (decl) == FUNCTION_DECL)
    flags = SECTION_CODE;
  else if (decl && decl_readonly_section (decl, reloc))
    flags = 0;
  else
    {
      flags = SECTION_WRITE;

      if (decl && TREE_CODE (decl) == VAR_DECL
 /* APPLE LOCAL begin mainline 2005-04-01 */
          && lookup_attribute ("shared", DECL_ATTRIBUTES (decl)))
        flags |= SECTION_PE_SHARED;
 /* APPLE LOCAL end mainline 2005-04-01 */
    }

  if (decl && DECL_ONE_ONLY (decl))
    flags |= SECTION_LINKONCE;

  /* See if we already have an entry for this section.  */
  slot = (unsigned int **) htab_find_slot (htab, name, INSERT);
  if (!*slot)
    {
      *slot = (unsigned int *) xmalloc (sizeof (unsigned int));
      **slot = flags;
    }
  else
    {
      if (decl && **slot != flags)
        error ("%J'%D' causes a section type conflict", decl, decl);
    }

  return flags;
}