From: Nick Clifton <nickc@cambridge.redhat.com>
To: "H . J . Lu" <hjl@lucon.org>
Cc: binutils@sources.redhat.com, Ian Lance Taylor <ian@zembu.com>
Subject: Re: elf_link_hash_entry vs generic_link_hash_entry
Date: Fri, 24 Aug 2001 09:35:00 -0000 [thread overview]
Message-ID: <m3lmk9fmgc.fsf@north-pole.nickc.cambridge.redhat.com> (raw)
In-Reply-To: <20010823120958.A18304@lucon.org>
Hi H.J.
> How about this patch?
>
> H.J.
> ----
> 2001-08-23 H.J. Lu <hjl@gnu.org>
>
> * elflink.h (elf_link_add_object_symbols): Don't merge section
> nor add the file to the loaded list if the linker hash table
> is not an an ELF linker hash table.
This patch does not appear to be based against the current binutils
sources. (I guess it was made against your own source tree ?)
Instead I created a modified version of your patch.
I had to make one change though - I reverted the definition of
elf_hash_table() back to its original version, since it cannot be
allowed to return NULL. (It is used in too many places as the first
argument to elf_link_hash_lookup). Instead I created a new macro
called 'is_elf_hash_table' and I added code to check it in
elf_link_add_object_symbols(), like this.
Cheers
Nick
2001-08-24 Nick Clifton <nickc@cambridge.redhat.com>
* elf-bfd.h (elf_hash_table): Revert definition.
(is_elf_hash_table): New macro.
* elflink.h (elf_link_add_object_symbols): Test
is_elf_hash_table before accessing ELF only fields in hash
structure.
(elf_link_create_dynamic_sections): Fail if not using an ELF
hash structure.
(elf_add_dynamic_entry): Fail if not using an ELF hash
structure.
(elf_link_record_local_dynamic_symbol): Fail if not using an
ELF hash structure.
(size_dynamic_sections): Fail if not using an ELF hash
structure.
(elf_adjust_dynamic_symbol): Fail if not using an ELF
hash structure.
(elf_bfd_final_link): Fail if not using an ELF hash
structure.
Index: elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.102
diff -p -r1.102 elflink.h
*** elflink.h 2001/08/24 11:17:28 1.102
--- elflink.h 2001/08/24 16:28:30
*************** elf_link_add_object_symbols (abfd, info)
*** 916,922 ****
--- 916,925 ----
Elf_External_Sym *esymend;
struct elf_backend_data *bed;
boolean dt_needed;
+ struct elf_link_hash_table * hash_table;
+ hash_table = elf_hash_table (info);
+
bed = get_elf_backend_data (abfd);
add_symbol_hook = bed->elf_add_symbol_hook;
collect = bed->collect;
*************** elf_link_add_object_symbols (abfd, info)
*** 970,976 ****
{
struct elf_link_hash_entry *h;
! h = elf_link_hash_lookup (elf_hash_table (info), name,
false, false, true);
/* FIXME: What about bfd_link_hash_common? */
--- 973,979 ----
{
struct elf_link_hash_entry *h;
! h = elf_link_hash_lookup (hash_table, name,
false, false, true);
/* FIXME: What about bfd_link_hash_common? */
*************** elf_link_add_object_symbols (abfd, info)
*** 1085,1097 ****
format. FIXME: If there are no input BFD's of the same
format as the output, we can't make a shared library. */
if (info->shared
! && ! elf_hash_table (info)->dynamic_sections_created
&& abfd->xvec == info->hash->creator)
{
if (! elf_link_create_dynamic_sections (abfd, info))
goto error_return;
}
}
else
{
asection *s;
--- 1088,1103 ----
format. FIXME: If there are no input BFD's of the same
format as the output, we can't make a shared library. */
if (info->shared
! && is_elf_hash_table (info)
! && ! hash_table->dynamic_sections_created
&& abfd->xvec == info->hash->creator)
{
if (! elf_link_create_dynamic_sections (abfd, info))
goto error_return;
}
}
+ else if (! is_elf_hash_table (info))
+ goto error_return;
else
{
asection *s;
*************** elf_link_add_object_symbols (abfd, info)
*** 1194,1200 ****
n->name = anm;
n->by = abfd;
n->next = NULL;
! for (pn = &elf_hash_table (info)->needed;
*pn != NULL;
pn = &(*pn)->next)
;
--- 1200,1206 ----
n->name = anm;
n->by = abfd;
n->next = NULL;
! for (pn = & hash_table->needed;
*pn != NULL;
pn = &(*pn)->next)
;
*************** elf_link_add_object_symbols (abfd, info)
*** 1209,1216 ****
to clear runpath. Do _NOT_ bfd_release, as that
frees all more recently bfd_alloc'd blocks as
well. */
! if (rpath && elf_hash_table (info)->runpath)
! elf_hash_table (info)->runpath = NULL;
n = ((struct bfd_link_needed_list *)
bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));
--- 1215,1222 ----
to clear runpath. Do _NOT_ bfd_release, as that
frees all more recently bfd_alloc'd blocks as
well. */
! if (rpath && hash_table->runpath)
! hash_table->runpath = NULL;
n = ((struct bfd_link_needed_list *)
bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));
*************** elf_link_add_object_symbols (abfd, info)
*** 1225,1231 ****
n->name = anm;
n->by = abfd;
n->next = NULL;
! for (pn = &elf_hash_table (info)->runpath;
*pn != NULL;
pn = &(*pn)->next)
;
--- 1231,1237 ----
n->name = anm;
n->by = abfd;
n->next = NULL;
! for (pn = & hash_table->runpath;
*pn != NULL;
pn = &(*pn)->next)
;
*************** elf_link_add_object_symbols (abfd, info)
*** 1252,1258 ****
n->name = anm;
n->by = abfd;
n->next = NULL;
! for (pn = &elf_hash_table (info)->runpath;
*pn != NULL;
pn = &(*pn)->next)
;
--- 1258,1264 ----
n->name = anm;
n->by = abfd;
n->next = NULL;
! for (pn = & hash_table->runpath;
*pn != NULL;
pn = &(*pn)->next)
;
*************** elf_link_add_object_symbols (abfd, info)
*** 1277,1298 ****
/* If this is the first dynamic object found in the link, create
the special sections required for dynamic linking. */
! if (! elf_hash_table (info)->dynamic_sections_created)
! {
! if (! elf_link_create_dynamic_sections (abfd, info))
! goto error_return;
! }
if (add_needed)
{
/* Add a DT_NEEDED entry for this dynamic object. */
! oldsize = _bfd_stringtab_size (elf_hash_table (info)->dynstr);
! strindex = _bfd_stringtab_add (elf_hash_table (info)->dynstr, name,
true, false);
if (strindex == (bfd_size_type) -1)
goto error_return;
! if (oldsize == _bfd_stringtab_size (elf_hash_table (info)->dynstr))
{
asection *sdyn;
Elf_External_Dyn *dyncon, *dynconend;
--- 1283,1302 ----
/* If this is the first dynamic object found in the link, create
the special sections required for dynamic linking. */
! if (! hash_table->dynamic_sections_created)
! if (! elf_link_create_dynamic_sections (abfd, info))
! goto error_return;
if (add_needed)
{
/* Add a DT_NEEDED entry for this dynamic object. */
! oldsize = _bfd_stringtab_size (hash_table->dynstr);
! strindex = _bfd_stringtab_add (hash_table->dynstr, name,
true, false);
if (strindex == (bfd_size_type) -1)
goto error_return;
! if (oldsize == _bfd_stringtab_size (hash_table->dynstr))
{
asection *sdyn;
Elf_External_Dyn *dyncon, *dynconend;
*************** elf_link_add_object_symbols (abfd, info)
*** 1302,1309 ****
have already included this dynamic object in the
link, just ignore it. There is no reason to include
a particular dynamic object more than once. */
! sdyn = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
! ".dynamic");
BFD_ASSERT (sdyn != NULL);
dyncon = (Elf_External_Dyn *) sdyn->contents;
--- 1306,1312 ----
have already included this dynamic object in the
link, just ignore it. There is no reason to include
a particular dynamic object more than once. */
! sdyn = bfd_get_section_by_name (hash_table->dynobj, ".dynamic");
BFD_ASSERT (sdyn != NULL);
dyncon = (Elf_External_Dyn *) sdyn->contents;
*************** elf_link_add_object_symbols (abfd, info)
*** 1313,1320 ****
{
Elf_Internal_Dyn dyn;
! elf_swap_dyn_in (elf_hash_table (info)->dynobj, dyncon,
! &dyn);
if (dyn.d_tag == DT_NEEDED
&& dyn.d_un.d_val == strindex)
{
--- 1316,1322 ----
{
Elf_Internal_Dyn dyn;
! elf_swap_dyn_in (hash_table->dynobj, dyncon, & dyn);
if (dyn.d_tag == DT_NEEDED
&& dyn.d_un.d_val == strindex)
{
*************** elf_link_add_object_symbols (abfd, info)
*** 1969,1993 ****
bfd_size_type oldsize;
bfd_size_type strindex;
/* The symbol from a DT_NEEDED object is referenced from
the regular object to create a dynamic executable. We
have to make sure there is a DT_NEEDED entry for it. */
dt_needed = false;
! oldsize = _bfd_stringtab_size (elf_hash_table (info)->dynstr);
! strindex = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
elf_dt_soname (abfd),
true, false);
if (strindex == (bfd_size_type) -1)
goto error_return;
if (oldsize
! == _bfd_stringtab_size (elf_hash_table (info)->dynstr))
{
asection *sdyn;
Elf_External_Dyn *dyncon, *dynconend;
! sdyn = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
".dynamic");
BFD_ASSERT (sdyn != NULL);
--- 1971,1998 ----
bfd_size_type oldsize;
bfd_size_type strindex;
+ if (! is_elf_hash_table (info))
+ goto error_return;
+
/* The symbol from a DT_NEEDED object is referenced from
the regular object to create a dynamic executable. We
have to make sure there is a DT_NEEDED entry for it. */
dt_needed = false;
! oldsize = _bfd_stringtab_size (hash_table->dynstr);
! strindex = _bfd_stringtab_add (hash_table->dynstr,
elf_dt_soname (abfd),
true, false);
if (strindex == (bfd_size_type) -1)
goto error_return;
if (oldsize
! == _bfd_stringtab_size (hash_table->dynstr))
{
asection *sdyn;
Elf_External_Dyn *dyncon, *dynconend;
! sdyn = bfd_get_section_by_name (hash_table->dynobj,
".dynamic");
BFD_ASSERT (sdyn != NULL);
*************** elf_link_add_object_symbols (abfd, info)
*** 1998,2004 ****
{
Elf_Internal_Dyn dyn;
! elf_swap_dyn_in (elf_hash_table (info)->dynobj,
dyncon, &dyn);
BFD_ASSERT (dyn.d_tag != DT_NEEDED ||
dyn.d_un.d_val != strindex);
--- 2003,2009 ----
{
Elf_Internal_Dyn dyn;
! elf_swap_dyn_in (hash_table->dynobj,
dyncon, &dyn);
BFD_ASSERT (dyn.d_tag != DT_NEEDED ||
dyn.d_un.d_val != strindex);
*************** elf_link_add_object_symbols (abfd, info)
*** 2155,2160 ****
--- 2160,2166 ----
&& ! info->relocateable
&& ! info->traditional_format
&& info->hash->creator->flavour == bfd_target_elf_flavour
+ && is_elf_hash_table (info)
&& (info->strip != strip_all && info->strip != strip_debugger))
{
asection *stab, *stabstr;
*************** elf_link_add_object_symbols (abfd, info)
*** 2170,2176 ****
secdata = elf_section_data (stab);
if (! _bfd_link_section_stabs (abfd,
! &elf_hash_table (info)->stab_info,
stab, stabstr,
&secdata->stab_info))
goto error_return;
--- 2176,2182 ----
secdata = elf_section_data (stab);
if (! _bfd_link_section_stabs (abfd,
! & hash_table->stab_info,
stab, stabstr,
&secdata->stab_info))
goto error_return;
*************** elf_link_add_object_symbols (abfd, info)
*** 2178,2192 ****
}
}
! if (! info->relocateable && ! dynamic)
{
asection *s;
for (s = abfd->sections; s != NULL; s = s->next)
if ((s->flags & SEC_MERGE)
! && ! _bfd_merge_section (abfd,
! &elf_hash_table (info)->merge_info,
! s, &elf_section_data (s)->merge_info))
goto error_return;
}
--- 2184,2198 ----
}
}
! if (! info->relocateable && ! dynamic
! && is_elf_hash_table (info))
{
asection *s;
for (s = abfd->sections; s != NULL; s = s->next)
if ((s->flags & SEC_MERGE)
! && ! _bfd_merge_section (abfd, & hash_table->merge_info, s,
! & elf_section_data (s)->merge_info))
goto error_return;
}
*************** elf_link_create_dynamic_sections (abfd,
*** 2219,2224 ****
--- 2225,2233 ----
struct elf_link_hash_entry *h;
struct elf_backend_data *bed;
+ if (! is_elf_hash_table (info))
+ return false;
+
if (elf_hash_table (info)->dynamic_sections_created)
return true;
*************** elf_add_dynamic_entry (info, tag, val)
*** 2343,2348 ****
--- 2352,2360 ----
size_t newsize;
bfd_byte *newcontents;
+ if (! is_elf_hash_table (info))
+ return false;
+
dynobj = elf_hash_table (info)->dynobj;
s = bfd_get_section_by_name (dynobj, ".dynamic");
*************** elf_link_record_local_dynamic_symbol (in
*** 2379,2384 ****
--- 2391,2399 ----
unsigned long dynstr_index;
char *name;
+ if (! is_elf_hash_table (info))
+ return false;
+
/* See if the entry exists already. */
for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next)
if (entry->input_bfd == input_bfd && entry->input_indx == input_indx)
*************** NAME(bfd_elf,size_dynamic_sections) (out
*** 2895,2900 ****
--- 2910,2918 ----
if (info->hash->creator->flavour != bfd_target_elf_flavour)
return true;
+ if (! is_elf_hash_table (info))
+ return false;
+
/* The backend may have to create some sections regardless of whether
we're dynamic or not. */
bed = get_elf_backend_data (output_bfd);
*************** elf_fix_symbol_flags (h, eif)
*** 3542,3553 ****
--- 3560,3573 ----
backend specifically; we can't just clear PLT-related data here. */
if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
&& eif->info->shared
+ && is_elf_hash_table (eif->info)
&& (eif->info->symbolic
|| ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
|| ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
{
struct elf_backend_data *bed;
+
bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
|| ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
*************** elf_adjust_dynamic_symbol (h, data)
*** 3602,3607 ****
--- 3622,3630 ----
if (h->root.type == bfd_link_hash_indirect)
return true;
+ if (! is_elf_hash_table (eif->info))
+ return false;
+
/* Fix the symbol flags. */
if (! elf_fix_symbol_flags (h, eif))
return false;
*************** elf_bfd_final_link (abfd, info)
*** 4511,4516 ****
--- 4534,4542 ----
boolean merged;
size_t relativecount = 0;
asection *reldyn = 0;
+
+ if (! is_elf_hash_table (info))
+ return false;
if (info->shared)
abfd->flags |= DYNAMIC;
next prev parent reply other threads:[~2001-08-24 9:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <si66bh2zdl.fsf@daffy.airs.com>
2001-08-22 0:44 ` Nick Clifton
2001-08-22 1:06 ` Thiemo Seufer
2001-08-22 7:02 ` Ian Lance Taylor
2001-08-23 9:22 ` H . J . Lu
2001-08-23 11:36 ` H . J . Lu
2001-08-23 12:10 ` H . J . Lu
2001-08-24 9:35 ` Nick Clifton [this message]
2001-08-24 9:54 ` H . J . Lu
2001-08-24 10:02 ` H . J . Lu
2001-08-24 9:18 ` Nick Clifton
2001-08-24 9:22 ` H . J . Lu
2001-08-28 15:53 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3lmk9fmgc.fsf@north-pole.nickc.cambridge.redhat.com \
--to=nickc@cambridge.redhat.com \
--cc=binutils@sources.redhat.com \
--cc=hjl@lucon.org \
--cc=ian@zembu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).