This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
fix up Xtensa property section names
- From: Bob Wilson <bwilson at tensilica dot com>
- To: binutils at sources dot redhat dot com
- Date: Tue, 14 Oct 2003 15:47:28 -0700
- Subject: fix up Xtensa property section names
- Organization: Tensilica, Inc.
Xtensa ELF object files contain 2 special "property table" sections. These
currently identify the locations of code and literals in the file. The
property tables for linkonce section should also be linkonce sections, but
the naming of these linkonce property sections was inconsistent. The correct
names are .gnu.linkonce.v.* or .gnu.linkonce.p.* (someone just picked these
'v' and 'p' letters arbitrarily but I don't think they conflict with anything
else right now). In some cases, the linkonce property section names were
being formed by appending .xt.insn or .xt.lit to the original .gnu.linkonce.*
name, which was wrong because it would result in those property sections
being intermixed with loadable sections after linking.
This patch fixes the bfd xtensa_get_property_section_name function to return
the correct names for linkonce property sections. It also fixes up the
comments in the elf/xtensa.h header regarding these linkonce property section
names, and fixes the assembler's use of this function to match.
The only other item worth mentioning here is that I'm removing the Xtensa
port's get_is_linkonce_section -- the only purpose for having this function
might have been to handle COMDAT linkonce sections but the rest of the code
will currently only work with .gnu.linkonce sections and at least now it is
consistent.
Tested by running the testsuites with an xtensa-linux cross target. Committed
on the mainline.
bfd ChangeLog:
2003-10-14 Bob Wilson <bob.wilson@acm.org>
* elf32-xtensa.c (get_is_linkonce_section): Delete.
(xtensa_is_property_section, xtensa_is_littable_section): Use
XTENSA_INSN_SEC_NAME and XTENSA_LIT_SEC_NAME macros. Do not recognize
linkonce sections containing ".xt.insn" and ".xt.lit" substrings.
(xtensa_get_property_section_name): Check section name instead of
calling get_is_linkonce_section. Remove unused bfd parameter. Use
XTENSA_INSN_SEC_NAME and XTENSA_LIT_SEC_NAME macros. Never generate
linkonce section names by appending ".xt.insn" or ".xt.lit".
(xtensa_read_table_entries): Remove bfd argument in call to
xtensa_get_property_section_name. Free section name when done.
(elf_xtensa_combine_prop_entries): Free leaking table.
gas ChangeLog:
2003-10-14 Bob Wilson <bob.wilson@acm.org>
* config/tc-xtensa.c (xtensa_create_property_segments): Remove bfd
argument in call to xtensa_get_property_section_name. Formatting.
include ChangeLog:
2003-10-14 Bob Wilson <bob.wilson@acm.org>
* elf/xtensa.h: Formatting. Fix comments about property section
names for linkonce sections.
Index: bfd/elf32-xtensa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xtensa.c,v
retrieving revision 1.13
diff -u -r1.13 elf32-xtensa.c
--- bfd/elf32-xtensa.c 23 Sep 2003 20:23:55 -0000 1.13
+++ bfd/elf32-xtensa.c 14 Oct 2003 22:00:07 -0000
@@ -212,10 +212,8 @@
PARAMS ((asection *));
static int internal_reloc_compare
PARAMS ((const PTR, const PTR));
-static bfd_boolean get_is_linkonce_section
- PARAMS ((bfd *, asection *));
extern char *xtensa_get_property_section_name
- PARAMS ((bfd *, asection *, const char *));
+ PARAMS ((asection *, const char *));
/* Other functions called directly by the linker. */
@@ -504,8 +502,9 @@
Elf_Internal_Rela *internal_relocs;
table_section_name =
- xtensa_get_property_section_name (abfd, section, sec_name);
+ xtensa_get_property_section_name (section, sec_name);
table_section = bfd_get_section_by_name (abfd, table_section_name);
+ free (table_section_name);
if (table_section != NULL)
table_size = bfd_get_section_size_before_reloc (table_section);
@@ -2314,6 +2313,7 @@
memcpy (sgotloc->contents, contents, section_size);
free (contents);
+ free (table);
return num;
}
@@ -5605,25 +5605,25 @@
}
+static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
+static int insn_sec_len = sizeof (XTENSA_INSN_SEC_NAME) - 1;
+static int lit_sec_len = sizeof (XTENSA_LIT_SEC_NAME) - 1;
+
+
static bfd_boolean
xtensa_is_property_section (sec)
asection *sec;
{
- static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
+ if (strncmp (XTENSA_INSN_SEC_NAME, sec->name, insn_sec_len) == 0
+ || strncmp (XTENSA_LIT_SEC_NAME, sec->name, lit_sec_len) == 0)
+ return TRUE;
- if (strncmp (".xt.insn", sec->name, 8) == 0
- || strncmp (".xt.lit", sec->name, 7) == 0)
+ if (strncmp (".gnu.linkonce.", sec->name, linkonce_len) == 0
+ && (sec->name[linkonce_len] == 'x'
+ || sec->name[linkonce_len] == 'p')
+ && sec->name[linkonce_len + 1] == '.')
return TRUE;
- if (strncmp (".gnu.linkonce.", sec->name, linkonce_len) == 0)
- {
- if (strncmp ("x.", sec->name + linkonce_len, 2) == 0
- || strncmp ("p.", sec->name + linkonce_len, 2) == 0)
- return TRUE;
- if (strstr (sec->name + linkonce_len, ".xt.insn") != NULL
- || strstr (sec->name + linkonce_len, ".xt.lit") != NULL)
- return TRUE;
- }
return FALSE;
}
@@ -5632,18 +5632,14 @@
xtensa_is_littable_section (sec)
asection *sec;
{
- static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
+ if (strncmp (XTENSA_LIT_SEC_NAME, sec->name, lit_sec_len) == 0)
+ return TRUE;
- if (strncmp (".xt.lit", sec->name, 7) == 0)
+ if (strncmp (".gnu.linkonce.", sec->name, linkonce_len) == 0
+ && sec->name[linkonce_len] == 'p'
+ && sec->name[linkonce_len + 1] == '.')
return TRUE;
- if (strncmp (".gnu.linkonce.", sec->name, linkonce_len) == 0)
- {
- if (strncmp ("p.", sec->name + linkonce_len, 2) == 0)
- return TRUE;
- if (strstr (sec->name + linkonce_len, ".xt.lit") != NULL)
- return TRUE;
- }
return FALSE;
}
@@ -5671,78 +5667,42 @@
}
-static bfd_boolean
-get_is_linkonce_section (abfd, sec)
- bfd *abfd ATTRIBUTE_UNUSED;
- asection *sec;
-{
- flagword flags, link_once_flags;
- bfd_boolean is_linkonce = FALSE;;
-
- flags = bfd_get_section_flags (abfd, sec);
- link_once_flags = (flags & SEC_LINK_ONCE);
- if (link_once_flags != 0)
- is_linkonce = TRUE;
-
- /* In order for this to be useful to the assembler
- before the linkonce flag is set we need to
- check for the GNU extension name. */
- if (!is_linkonce &&
- strncmp (sec->name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
- is_linkonce = TRUE;
-
- return is_linkonce;
-}
-
-
char *
-xtensa_get_property_section_name (abfd, sec, base_name)
- bfd *abfd;
+xtensa_get_property_section_name (sec, base_name)
asection *sec;
- const char * base_name;
+ const char *base_name;
{
- char *table_sec_name = NULL;
- bfd_boolean is_linkonce;
-
- is_linkonce = get_is_linkonce_section (abfd, sec);
-
- if (!is_linkonce)
+ if (strncmp (sec->name, ".gnu.linkonce.", linkonce_len) == 0)
{
- table_sec_name = strdup (base_name);
- }
- else
- {
- static size_t prefix_len = sizeof (".gnu.linkonce.t.") - 1;
- size_t len = strlen (sec->name) + 1;
- char repl_char = '\0';
- const char *segname = sec->name;
-
- if (strncmp (segname, ".gnu.linkonce.t.", prefix_len) == 0)
- {
- if (strcmp (base_name, ".xt.insn") == 0)
- repl_char = 'x';
- else if (strcmp (base_name, ".xt.lit") == 0)
- repl_char = 'p';
- }
-
- if (repl_char != '\0')
- {
- char *name = (char *) bfd_malloc (len);
- memcpy (name, sec->name, len);
- name[prefix_len - 2] = repl_char;
- table_sec_name = name;
- }
+ char *prop_sec_name;
+ const char *suffix;
+ char linkonce_kind = 0;
+
+ if (strcmp (base_name, XTENSA_INSN_SEC_NAME) == 0)
+ linkonce_kind = 'x';
+ else if (strcmp (base_name, XTENSA_LIT_SEC_NAME) == 0)
+ linkonce_kind = 'p';
else
+ abort ();
+
+ prop_sec_name = (char *) bfd_malloc (strlen (sec->name) + 1);
+ memcpy (prop_sec_name, ".gnu.linkonce.", linkonce_len);
+ prop_sec_name[linkonce_len] = linkonce_kind;
+ prop_sec_name[linkonce_len + 1] = '.';
+
+ suffix = sec->name + linkonce_len;
+ while (*suffix)
{
- size_t base_len = strlen (base_name) + 1;
- char *name = (char *) bfd_malloc (len + base_len);
- memcpy (name, sec->name, len - 1);
- memcpy (name + len - 1, base_name, base_len);
- table_sec_name = name;
+ suffix += 1;
+ if (suffix[-1] == '.')
+ break;
}
+ strcpy (prop_sec_name + linkonce_len + 2, suffix);
+
+ return prop_sec_name;
}
- return table_sec_name;
+ return strdup (base_name);
}
Index: gas/config/tc-xtensa.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-xtensa.c,v
retrieving revision 1.5
diff -u -r1.5 tc-xtensa.c
--- gas/config/tc-xtensa.c 12 Sep 2003 00:00:03 -0000 1.5
+++ gas/config/tc-xtensa.c 14 Oct 2003 22:00:07 -0000
@@ -677,7 +677,7 @@
/* Import from elf32-xtensa.c in BFD library. */
extern char *xtensa_get_property_section_name
- PARAMS ((bfd *, asection *, const char *));
+ PARAMS ((asection *, const char *));
/* TInsn and IStack functions. */
static bfd_boolean tinsn_has_symbolic_operands
@@ -7916,12 +7916,11 @@
segT sec = *seclist;
if (section_has_property (sec, property_function))
{
- char * property_section_name =
- xtensa_get_property_section_name (stdoutput, sec,
- section_name_base);
+ char *property_section_name =
+ xtensa_get_property_section_name (sec, section_name_base);
segT insn_sec = retrieve_xtensa_section (property_section_name);
segment_info_type *xt_seg_info = retrieve_segment_info (insn_sec);
- xtensa_block_info ** xt_blocks =
+ xtensa_block_info **xt_blocks =
&xt_seg_info->tc_segment_info_data.blocks[sec_type];
/* Walk over all of the frchains here and add new sections. */
add_xt_block_frags (sec, insn_sec, xt_blocks, property_function);
Index: include/elf/xtensa.h
===================================================================
RCS file: /cvs/src/src/include/elf/xtensa.h,v
retrieving revision 1.1
diff -u -r1.1 xtensa.h
--- include/elf/xtensa.h 1 Apr 2003 15:50:31 -0000 1.1
+++ include/elf/xtensa.h 14 Oct 2003 22:00:07 -0000
@@ -16,7 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
/* This file holds definitions specific to the Xtensa ELF ABI. */
@@ -68,8 +69,8 @@
/* Definitions for instruction and literal property tables. The
- instruction tables for ".gnu.linkonce.t.*" sections are placed in
- the following sections:
+ tables for ".gnu.linkonce.*" sections are placed in the following
+ sections:
instruction tables: .gnu.linkonce.x.*
literal tables: .gnu.linkonce.p.*