This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: Fix ELF arrays
On Thu, Jul 14, 2005 at 10:06:07AM -0700, H. J. Lu wrote:
> On Thu, Jul 14, 2005 at 07:44:02AM -0700, H. J. Lu wrote:
>
> > _bfd_elf_provide_section_bound_symbols should be called at least
> > once after lang_size_sections. Otherwise, the section size will be
> > zero.
> >
> >
>
> On Linux, only ia64 uses ELF arrays. People may not see the problems
> with ELF arrays. I checked in this patch to test them on all ELF
> targets. They may fail if the system C library doesn't support ELF
> arrays.
>
>
This patch fixes ELF arrays and restore the patch for
http://sourceware.org/ml/binutils/2005-04/msg00660.html:
H.J.
----
bfd/
2005-07-14 H.J. Lu <hongjiu.lu@intel.com>
* elflink.c (_bfd_elf_provide_section_bound_symbols): Redefine
the symbol if it is relative to the same section and its value
is 0.
ld/
2005-07-14 H.J. Lu <hongjiu.lu@intel.com>
* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Set to the
provide_section_symbols field to NULL.
* emultempl/armcoff.em: Likewise.
* emultempl/beos.em: Likewise.
* emultempl/generic.em: Likewise.
* emultempl/gld960.em: Likewise.
* emultempl/gld960c.em: Likewise.
* emultempl/linux.em: Likewise.
* emultempl/lnk960.em: Likewise.
* emultempl/m68kcoff.em: Likewise.
* emultempl/pe.em: Likewise.
* emultempl/sunos.em: Likewise.
* emultempl/ticoff.em: Likewise.
* emultempl/vanilla.em: Likewise.
* emultempl/elf32.em (gld${EMULATION_NAME}_provide_init_fini_syms):
Renamd to ...
(gld${EMULATION_NAME}_provide_section_symbols): This.
* ldemul.c (ldemul_provide_section_symbols): New.
* ldemul.h (ldemul_provide_section_symbols): New.
(ld_emulation_xfer_struct): Add the provide_section_symbols
field.
* ldlang.c (lang_process): Call ldemul_provide_section_symbols
after lang_size_sections.
--- binutils/bfd/elflink.c.provide 2005-07-14 08:32:50.694434473 -0700
+++ binutils/bfd/elflink.c 2005-07-14 09:57:04.705431887 -0700
@@ -9885,11 +9885,58 @@ _bfd_elf_provide_section_bound_symbols (
const char *start,
const char *end)
{
- bfd_vma val = 0;
- _bfd_elf_provide_symbol (info, start, val, sec);
+ struct elf_link_hash_entry *hs, *he;
+ bfd_vma start_val, end_val;
+ bfd_boolean do_start, do_end;
+ asection *defined = sec ? sec : bfd_abs_section_ptr;
+
+ /* Check if we need them or not first. This function may be called
+ more than once. The section size is 0 when it is called before
+ lang_size_sections. We assume that the symbols are provided by
+ linker if it is relative to the same section and its value is 0.
+ */
+ hs = elf_link_hash_lookup (elf_hash_table (info), start, FALSE,
+ FALSE, FALSE);
+ do_start = (hs != NULL
+ && (!hs->def_regular
+ || (hs->root.u.def.section == defined
+ && hs->root.u.def.value == 0)));
+
+ he = elf_link_hash_lookup (elf_hash_table (info), end, FALSE,
+ FALSE, FALSE);
+ do_end = (he != NULL
+ && (!he->def_regular
+ || (he->root.u.def.section == defined
+ && he->root.u.def.value == 0)));
+
+ if (!do_start && !do_end)
+ return;
+
if (sec != NULL)
- val = sec->size;
- _bfd_elf_provide_symbol (info, end, val, sec);
+ {
+ start_val = 0;
+ end_val = sec->size;
+ }
+ else
+ {
+ /* We have to choose those values very carefully. Some targets,
+ like alpha, may have relocation overflow with 0. "__bss_start"
+ should be defined in all cases. */
+ struct elf_link_hash_entry *h
+ = elf_link_hash_lookup (elf_hash_table (info), "__bss_start",
+ FALSE, FALSE, FALSE);
+ if (h != NULL && h->root.type == bfd_link_hash_defined)
+ start_val = h->root.u.def.value;
+ else
+ start_val = 0;
+ end_val = start_val;
+ }
+
+ if (do_start)
+ bfd_elf_set_symbol (hs, start_val, sec);
+
+ if (do_end)
+ bfd_elf_set_symbol (he, end_val, sec);
}
/* Convert symbols in excluded output sections to absolute. */
--- binutils/ld/emultempl/aix.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/aix.em 2005-07-14 09:57:04.706431723 -0700
@@ -1348,6 +1348,7 @@ struct ld_emulation_xfer_struct ld_${EMU
0, /* open_dynamic_archive */
0, /* place_orphan */
0, /* set_symbols */
+ 0, /* provide_section_symbols */
gld${EMULATION_NAME}_parse_args,
gld${EMULATION_NAME}_add_options,
gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/armcoff.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/armcoff.em 2005-07-14 09:57:04.707431558 -0700
@@ -268,6 +268,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* open dynamic archive */
NULL, /* place orphan */
NULL, /* set symbols */
+ NULL, /* provide section symbols */
NULL, /* parse_args */
gld${EMULATION_NAME}_add_options,
gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/beos.em.provide 2005-06-02 16:02:26.000000000 -0700
+++ binutils/ld/emultempl/beos.em 2005-07-14 09:57:04.707431558 -0700
@@ -775,6 +775,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* open dynamic archive */
gld${EMULATION_NAME}_place_orphan,
gld_${EMULATION_NAME}_set_symbols,
+ NULL, /* provide_section_symbols */
NULL, /* parse_args */
gld${EMULATION_NAME}_add_options,
gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/elf32.em.provide 2005-07-14 08:31:59.626035818 -0700
+++ binutils/ld/emultempl/elf32.em 2005-07-14 10:13:48.094368080 -0700
@@ -1064,7 +1064,7 @@ gld${EMULATION_NAME}_provide_bound_symbo
section alignment affecting where the section starts. */
static void
-gld${EMULATION_NAME}_provide_init_fini_syms (void)
+gld${EMULATION_NAME}_provide_section_symbols (void)
{
if (!link_info.relocatable && link_info.executable)
{
@@ -1097,7 +1097,7 @@ gld${EMULATION_NAME}_before_allocation (
referred to by dynamic objects. */
lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
- gld${EMULATION_NAME}_provide_init_fini_syms ();
+ gld${EMULATION_NAME}_provide_section_symbols ();
/* Let the ELF backend work out the sizes of any sections required
by dynamic linking. */
@@ -1889,6 +1889,7 @@ struct ld_emulation_xfer_struct ld_${EMU
${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
${LDEMUL_SET_SYMBOLS-NULL},
+ ${LDEMUL_PROVIDE_SYMBOLS-gld${EMULATION_NAME}_provide_section_symbols},
${LDEMUL_PARSE_ARGS-NULL},
gld${EMULATION_NAME}_add_options,
gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/generic.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/generic.em 2005-07-14 09:57:04.708431394 -0700
@@ -136,6 +136,7 @@ struct ld_emulation_xfer_struct ld_${EMU
${LDEMUL_OPEN_DYNAMIC_ARCHIVE-NULL},
${LDEMUL_PLACE_ORPHAN-NULL},
${LDEMUL_SET_SYMBOLS-NULL},
+ ${LDEMUL_PROVIDE_SYMBOLS-NULL},
${LDEMUL_PARSE_ARGS-NULL},
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/emultempl/gld960.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/gld960.em 2005-07-14 09:57:04.709431229 -0700
@@ -142,6 +142,7 @@ struct ld_emulation_xfer_struct ld_gld96
NULL, /* open dynamic archive */
NULL, /* place orphan */
NULL, /* set symbols */
+ NULL, /* provide section symbols */
NULL, /* parse args */
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/emultempl/gld960c.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/gld960c.em 2005-07-14 09:57:04.709431229 -0700
@@ -157,6 +157,7 @@ struct ld_emulation_xfer_struct ld_gld96
NULL, /* open dynamic archive */
NULL, /* place orphan */
NULL, /* set symbols */
+ NULL, /* provide section symbols */
NULL, /* parse args */
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/emultempl/linux.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/linux.em 2005-07-14 09:57:04.709431229 -0700
@@ -197,6 +197,7 @@ struct ld_emulation_xfer_struct ld_${EMU
gld${EMULATION_NAME}_open_dynamic_archive,
NULL, /* place orphan */
NULL, /* set symbols */
+ NULL, /* provide section symbols */
NULL, /* parse args */
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/emultempl/lnk960.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/lnk960.em 2005-07-14 09:57:04.710431065 -0700
@@ -277,6 +277,7 @@ struct ld_emulation_xfer_struct ld_lnk96
NULL, /* open dynamic archive */
NULL, /* place orphan */
NULL, /* set symbols */
+ NULL, /* provide section symbols */
NULL, /* parse args */
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/emultempl/m68kcoff.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/m68kcoff.em 2005-07-14 09:57:04.710431065 -0700
@@ -230,6 +230,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* open dynamic archive */
NULL, /* place orphan */
NULL, /* set symbols */
+ NULL, /* provide section symbols */
NULL, /* parse args */
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/emultempl/pe.em.provide 2005-07-11 14:08:22.000000000 -0700
+++ binutils/ld/emultempl/pe.em 2005-07-14 09:57:04.711430900 -0700
@@ -1830,6 +1830,7 @@ struct ld_emulation_xfer_struct ld_${EMU
gld_${EMULATION_NAME}_open_dynamic_archive,
gld_${EMULATION_NAME}_place_orphan,
gld_${EMULATION_NAME}_set_symbols,
+ NULL, /* provide_section_symbols */
NULL, /* parse_args */
gld${EMULATION_NAME}_add_options,
gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/sunos.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/sunos.em 2005-07-14 09:57:04.712430736 -0700
@@ -1021,6 +1021,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* open dynamic archive */
NULL, /* place orphan */
gld${EMULATION_NAME}_set_symbols,
+ NULL, /* provide_section_symbols */
NULL, /* parse args */
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/emultempl/ticoff.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/ticoff.em 2005-07-14 09:57:04.712430736 -0700
@@ -170,6 +170,7 @@ struct ld_emulation_xfer_struct ld_${EMU
NULL, /* open dynamic archive */
NULL, /* place orphan */
NULL, /* set_symbols */
+ NULL, /* provide_section_symbols */
NULL, /* parse_args */
gld${EMULATION_NAME}_add_options,
gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/vanilla.em.provide 2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/vanilla.em 2005-07-14 09:57:04.712430736 -0700
@@ -73,6 +73,7 @@ struct ld_emulation_xfer_struct ld_vanil
NULL, /* open dynamic archive */
NULL, /* place orphan */
NULL, /* set symbols */
+ NULL, /* provide section symbols */
NULL, /* parse args */
NULL, /* add_options */
NULL, /* handle_option */
--- binutils/ld/ldemul.c.provide 2005-05-16 11:04:39.000000000 -0700
+++ binutils/ld/ldemul.c 2005-07-14 09:57:04.712430736 -0700
@@ -100,6 +100,13 @@ ldemul_set_symbols (void)
}
void
+ldemul_provide_section_symbols (void)
+{
+ if (ld_emulation->provide_section_symbols)
+ ld_emulation->provide_section_symbols ();
+}
+
+void
ldemul_create_output_section_statements (void)
{
if (ld_emulation->create_output_section_statements)
--- binutils/ld/ldemul.h.provide 2005-03-03 08:56:33.000000000 -0800
+++ binutils/ld/ldemul.h 2005-07-14 09:57:04.713430571 -0700
@@ -51,6 +51,8 @@ extern void ldemul_finish
(void);
extern void ldemul_set_symbols
(void);
+extern void ldemul_provide_section_symbols
+ (void);
extern void ldemul_create_output_section_statements
(void);
extern bfd_boolean ldemul_place_orphan
@@ -149,6 +151,9 @@ typedef struct ld_emulation_xfer_struct
reading the script. Used to initialize symbols used in the script. */
void (*set_symbols) (void);
+ /* Used to provide section symbols by linker emulation. */
+ void (*provide_section_symbols) (void);
+
/* Parse args which the base linker doesn't understand.
Return TRUE if the arg needs no further processing. */
bfd_boolean (*parse_args) (int, char **);
--- binutils/ld/ldlang.c.provide 2005-07-14 08:32:50.711431677 -0700
+++ binutils/ld/ldlang.c 2005-07-14 09:57:04.716430078 -0700
@@ -5360,6 +5360,9 @@ lang_process (void)
/* Size up the sections. */
lang_size_sections (NULL, !command_line.relax);
+ /* Assign values for symbols provided by emulation. */
+ ldemul_provide_section_symbols ();
+
/* Now run around and relax if we can. */
if (command_line.relax)
{