summaryrefslogtreecommitdiff
path: root/bfd/elflink.h
diff options
context:
space:
mode:
authorH.J. Lu <hjl@lucon.org>2003-06-18 00:30:04 +0000
committerH.J. Lu <hjl@lucon.org>2003-06-18 00:30:04 +0000
commit0382bf352ac17ba76855db27bafe619d2f176fca (patch)
tree019c366abc17d98c337c08b8d531e15cef77b96b /bfd/elflink.h
parent314953b1e486496a0ab85645148fc47adce1a473 (diff)
downloadgdb-0382bf352ac17ba76855db27bafe619d2f176fca.tar.gz
bfd/
2003-06-17 H.J. Lu <hongjiu.lu@intel.com> * section.c (struct sec): Put back kept_section. (STD_SECTION): Put back kept_section initialization. * bfd-in2.h: Regenerate. * elflink.h (elf_link_input_bfd): Also check discarded linkonce sections for relocateable output. Use kept_section to preserve debug information discarded by linkonce. ld/ 2003-06-17 H.J. Lu <hongjiu.lu@intel.com> * ldlang.c (section_already_linked): Put back assignment of kept_section.
Diffstat (limited to 'bfd/elflink.h')
-rw-r--r--bfd/elflink.h36
1 files changed, 27 insertions, 9 deletions
diff --git a/bfd/elflink.h b/bfd/elflink.h
index b960c73f9cb..64554e716ed 100644
--- a/bfd/elflink.h
+++ b/bfd/elflink.h
@@ -5005,9 +5005,9 @@ elf_link_input_bfd (finfo, input_bfd)
from discarded sections and section symbols from
removed link-once sections. Complain about relocs
against discarded sections. Zero relocs against removed
- link-once sections. */
- if (!finfo->info->relocateable
- && !elf_section_ignore_discarded_relocs (o))
+ link-once sections. Preserve debug information as much
+ as we can. */
+ if (!elf_section_ignore_discarded_relocs (o))
{
Elf_Internal_Rela *rel, *relend;
@@ -5016,6 +5016,7 @@ elf_link_input_bfd (finfo, input_bfd)
for ( ; rel < relend; rel++)
{
unsigned long r_symndx = ELF_R_SYM (rel->r_info);
+ asection *sec;
if (r_symndx >= locsymcount
|| (elf_bad_symtab (input_bfd)
@@ -5030,14 +5031,22 @@ elf_link_input_bfd (finfo, input_bfd)
/* Complain if the definition comes from a
discarded section. */
+ sec = h->root.u.def.section;
if ((h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
- && elf_discarded_section (h->root.u.def.section))
+ && elf_discarded_section (sec))
{
if ((o->flags & SEC_DEBUGGING) != 0)
{
BFD_ASSERT (r_symndx != 0);
- memset (rel, 0, sizeof (*rel));
+ /* Try to preserve debug information. */
+ if ((o->flags & SEC_DEBUGGING) != 0
+ && sec->kept_section != NULL
+ && sec->_cooked_size == sec->kept_section->_cooked_size)
+ h->root.u.def.section
+ = sec->kept_section;
+ else
+ memset (rel, 0, sizeof (*rel));
}
else
finfo->info->callbacks->error_handler
@@ -5051,7 +5060,7 @@ elf_link_input_bfd (finfo, input_bfd)
}
else
{
- asection *sec = finfo->sections[r_symndx];
+ sec = finfo->sections[r_symndx];
if (sec != NULL && elf_discarded_section (sec))
{
@@ -5059,9 +5068,18 @@ elf_link_input_bfd (finfo, input_bfd)
|| (sec->flags & SEC_LINK_ONCE) != 0)
{
BFD_ASSERT (r_symndx != 0);
- rel->r_info
- = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info));
- rel->r_addend = 0;
+ /* Try to preserve debug information. */
+ if ((o->flags & SEC_DEBUGGING) != 0
+ && sec->kept_section != NULL
+ && sec->_cooked_size == sec->kept_section->_cooked_size)
+ finfo->sections[r_symndx]
+ = sec->kept_section;
+ else
+ {
+ rel->r_info
+ = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info));
+ rel->r_addend = 0;
+ }
}
else
{