This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] Fix .tbss handling
- From: Jakub Jelinek <jakub at redhat dot com>
- To: binutils at sources dot redhat dot com
- Date: Thu, 25 Jul 2002 18:26:50 +0200
- Subject: [PATCH] Fix .tbss handling
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Ulrich reported that .tbss has always size 0 in section table, even if
it had some real size, and what's worse is that it is 0 even for relocatable
link, which means space won't be created for tbss if linking through
ld -r -o foo.o ...
ld -shared -o foo.so ... foo.o ...
The following patch fixes this, ok to commit?
2002-07-25 Jakub Jelinek <jakub@redhat.com>
* elf.c (elf_fake_sections): Fix up .tbss sh_size and sh_type.
* ldlang.c (lang_add_section): Don't turn .tbss into normal sections
for relocatable link.
(lang_size_sections_1): Don't make .tbss zero size for relocatable
link.
--- bfd/elf.c.jj Thu Jul 18 11:34:06 2002
+++ bfd/elf.c Thu Jul 18 23:57:49 2002
@@ -2443,7 +2443,20 @@ elf_fake_sections (abfd, asect, failedpt
if ((asect->flags & SEC_GROUP) == 0 && elf_group_name (asect) != NULL)
this_hdr->sh_flags |= SHF_GROUP;
if ((asect->flags & SEC_THREAD_LOCAL) != 0)
- this_hdr->sh_flags |= SHF_TLS;
+ {
+ this_hdr->sh_flags |= SHF_TLS;
+ if (asect->_raw_size == 0 && (asect->flags & SEC_HAS_CONTENTS) == 0)
+ {
+ struct bfd_link_order *o;
+
+ this_hdr->sh_size = 0;
+ for (o = asect->link_order_head; o != NULL; o = o->next)
+ if (this_hdr->sh_size < o->offset + o->size)
+ this_hdr->sh_size = o->offset + o->size;
+ if (this_hdr->sh_size)
+ this_hdr->sh_type = SHT_NOBITS;
+ }
+ }
/* Check for processor-specific section types. */
if (bed->elf_backend_fake_sections
--- ld/ldlang.c.jj Thu Jul 18 11:38:46 2002
+++ ld/ldlang.c Thu Jul 18 23:42:51 2002
@@ -1218,7 +1218,7 @@ lang_add_section (ptr, section, output,
}
/* For now make .tbss normal section. */
- if (flags & SEC_THREAD_LOCAL)
+ if ((flags & SEC_THREAD_LOCAL) && ! link_info.relocateable)
flags |= SEC_LOAD;
section->output_section->flags |= flags;
@@ -3055,7 +3055,8 @@ lang_size_sections_1 (s, output_section_
if (bfd_is_abs_section (os->bfd_section))
ASSERT (after == os->bfd_section->vma);
else if ((os->bfd_section->flags & SEC_HAS_CONTENTS) == 0
- && (os->bfd_section->flags & SEC_THREAD_LOCAL))
+ && (os->bfd_section->flags & SEC_THREAD_LOCAL)
+ && ! link_info.relocateable)
os->bfd_section->_raw_size = 0;
else
os->bfd_section->_raw_size =
Jakub