This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Fix duplicate output section statement lookup
- From: Guy Martin <gmsoft at tuxicoman dot be>
- To: Alan Modra <amodra at gmail dot com>, binutils at sourceware dot org
- Date: Fri, 17 Jan 2014 10:06:47 +0100
- Subject: Re: [PATCH] Fix duplicate output section statement lookup
- Authentication-results: sourceware.org; auth=none
- References: <40590ef10cd8c08dddafc067cf818ee7 at tuxicoman dot be> <20140115222459 dot GZ5390 at bubble dot grove dot modra dot org> <8dcd6ff7e0a0d143ad4e3d2db750d2eb at tuxicoman dot be> <20140117063318 dot GH5390 at bubble dot grove dot modra dot org>
On 2014-01-17 07:33, Alan Modra wrote:
This looks OK, except for the spuelf.em patch.
if (o != NULL)
- output_name = o->name;
- os = lang_output_section_find (output_name);
+ os = lang_output_section_get (o);
Please keep the lookup when o is NULL. OK with that fixed.
Thanks for reviewing Alan, here is the fixed patch.
---
Instead of trying to lookup the output section statement associated with
an output section, we assign the output section statement to the section
userdata and retreive it as needed. This also fix an issue occurring
when multiple section with the same name exists, the wrong one was
returned.
* ldlang.h (lang_output_section_get): Define.
* ldlang.c (lang_output_section_get): Likewise.
(init_os): Set the output_section userdata to the output
section statement.
* emultempl/hppaelf.em: Use lang_output_section_get instead of
lang_output_section_find where applicable.
* emultempl/aarch64elf.em: Likewise.
* emultempl/aix.em: Likewise.
* emultempl/armelf.em: Likewise.
* emultempl/metagelf.em: Likewise.
* emultempl/mipself.em: Likewise.
* emultempl/ppc64elf.em: Likewise.
* emultempl/m68hc1xelf.em: Likewise.
---
ld/emultempl/aarch64elf.em | 3 +--
ld/emultempl/aix.em | 2 +-
ld/emultempl/armelf.em | 3 +--
ld/emultempl/hppaelf.em | 3 +--
ld/emultempl/m68hc1xelf.em | 3 +--
ld/emultempl/metagelf.em | 3 +--
ld/emultempl/mipself.em | 4 +---
ld/emultempl/ppc64elf.em | 3 +--
ld/ldlang.c | 11 +++++++++++
ld/ldlang.h | 2 ++
10 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
index b3279bf..8c503eb 100644
--- a/ld/emultempl/aarch64elf.em
+++ b/ld/emultempl/aarch64elf.em
@@ -173,8 +173,7 @@ elf${ELFSIZE}_aarch64_add_stub_section (const char
*stub_sec_name,
bfd_set_section_alignment (stub_file->the_bfd, stub_sec, 3);
output_section = input_section->output_section;
- secname = bfd_get_section_name (output_section->owner,
output_section);
- os = lang_output_section_find (secname);
+ os = lang_output_section_get (output_section);
info.input_section = input_section;
lang_list_init (&info.add);
diff --git a/ld/emultempl/aix.em b/ld/emultempl/aix.em
index aa72ce6..000c060 100644
--- a/ld/emultempl/aix.em
+++ b/ld/emultempl/aix.em
@@ -854,7 +854,7 @@ gld${EMULATION_NAME}_before_allocation (void)
/* Remove this section from the list of the output section.
This assumes we know what the script looks like. */
is = NULL;
- os = lang_output_section_find (sec->output_section->name);
+ os = lang_output_section_get (sec->output_section);
if (os == NULL)
einfo ("%P%F: can't find output section %s\n",
sec->output_section->name);
diff --git a/ld/emultempl/armelf.em b/ld/emultempl/armelf.em
index eee6af1..ba5f555 100644
--- a/ld/emultempl/armelf.em
+++ b/ld/emultempl/armelf.em
@@ -203,8 +203,7 @@ elf32_arm_add_stub_section (const char *
stub_sec_name,
bfd_set_section_alignment (stub_file->the_bfd, stub_sec,
alignment_power);
output_section = input_section->output_section;
- secname = bfd_get_section_name (output_section->owner,
output_section);
- os = lang_output_section_find (secname);
+ os = lang_output_section_get (output_section);
info.input_section = input_section;
lang_list_init (&info.add);
diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em
index 65c1ea5..0e60d78 100644
--- a/ld/emultempl/hppaelf.em
+++ b/ld/emultempl/hppaelf.em
@@ -190,8 +190,7 @@ hppaelf_add_stub_section (const char *stub_sec_name,
asection *input_section)
goto err_ret;
output_section = input_section->output_section;
- secname = bfd_get_section_name (output_section->owner,
output_section);
- os = lang_output_section_find (secname);
+ os = lang_output_section_get (output_section);
info.input_section = input_section;
lang_list_init (&info.add);
diff --git a/ld/emultempl/m68hc1xelf.em b/ld/emultempl/m68hc1xelf.em
index 594b193..6f2ba9d 100644
--- a/ld/emultempl/m68hc1xelf.em
+++ b/ld/emultempl/m68hc1xelf.em
@@ -262,8 +262,7 @@ m68hc11elf_add_stub_section (const char
*stub_sec_name,
goto err_ret;
output_section = tramp_section->output_section;
- secname = bfd_get_section_name (output_section->owner,
output_section);
- os = lang_output_section_find (secname);
+ os = lang_output_section_get (sec->output_section);
/* Try to put the new section at the same place as an existing
.tramp section. Such .tramp section exists in most cases and
diff --git a/ld/emultempl/metagelf.em b/ld/emultempl/metagelf.em
index 21e3e94..71dbd17 100644
--- a/ld/emultempl/metagelf.em
+++ b/ld/emultempl/metagelf.em
@@ -166,8 +166,7 @@ metagelf_add_stub_section (const char
*stub_sec_name, asection *input_section)
goto err_ret;
output_section = input_section->output_section;
- secname = bfd_get_section_name (output_section->owner,
output_section);
- os = lang_output_section_find (secname);
+ os = lang_output_section_get (output_section);
info.input_section = input_section;
lang_list_init (&info.add);
diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em
index 3c6ec9f..4fc1a37 100644
--- a/ld/emultempl/mipself.em
+++ b/ld/emultempl/mipself.em
@@ -176,9 +176,7 @@ mips_add_stub_section (const char *stub_sec_name,
asection *input_section,
if (!bfd_set_section_flags (stub_bfd, stub_sec, flags))
goto err_ret;
- /* Create an output section statement. */
- secname = bfd_get_section_name (output_section->owner,
output_section);
- os = lang_output_section_find (secname);
+ os = lang_output_section_get (output_section);
/* Initialize a statement list that contains only the new statement.
*/
lang_list_init (&info.add);
diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
index f2085d7..13eef63 100644
--- a/ld/emultempl/ppc64elf.em
+++ b/ld/emultempl/ppc64elf.em
@@ -392,8 +392,7 @@ ppc_add_stub_section (const char *stub_sec_name,
asection *input_section)
goto err_ret;
output_section = input_section->output_section;
- secname = bfd_get_section_name (output_section->owner,
output_section);
- os = lang_output_section_find (secname);
+ os = lang_output_section_get (output_section);
info.input_section = input_section;
lang_list_init (&info.add);
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 2a6c4c5..1d80337 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1376,6 +1376,14 @@ lang_memory_default (asection * section)
return lang_memory_region_lookup (DEFAULT_MEMORY_REGION, FALSE);
}
+
+/* Get the output section statement directly from the userdata */
+lang_output_section_statement_type *
+lang_output_section_get (const asection *output_section)
+{
+ return get_userdata(output_section);
+}
+
/* Find or create an output_section_statement with the given NAME.
If CONSTRAINT is non-zero match one with that constraint, otherwise
match any non-negative constraint. If CREATE, always make a
@@ -2104,6 +2112,9 @@ init_os (lang_output_section_statement_type *s,
flagword flags)
s->bfd_section->output_section = s->bfd_section;
s->bfd_section->output_offset = 0;
+ /* Set the userdata of the output section to the output section
statement to avoid lookup */
+ get_userdata(s->bfd_section) = s;
+
/* If there is a base address, make sure that any sections it might
mention are initialized. */
if (s->addr_tree != NULL)
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 6eb75dc..e91153c 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -584,6 +584,8 @@ extern lang_input_statement_type
*lang_add_input_file
(const char *, lang_input_file_enum_type, const char *);
extern void lang_add_keepsyms_file
(const char *);
+extern lang_output_section_statement_type *lang_output_section_get
+ (const asection *);
extern lang_output_section_statement_type
*lang_output_section_statement_lookup
(const char *, int, bfd_boolean);
extern lang_output_section_statement_type
*next_matching_output_section_statement
--
1.8.3.2