This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: The static linking with -fPIC is broken now
On Wed, Jun 20, 2001 at 09:47:56AM -0700, H . J . Lu wrote:
> I am enclosing a simple testcase here.
>
> # make
> cc -O2 -g -c -o main.o main.c
> cc -fPIC -O2 -g -c foo.c
> foo.c:7: warning: static declaration for `foo2' follows non-static
> cc -fPIC -O2 -g -c bar.c
> ar rcs libfoo.a foo.o bar.o
> cc -static -o main main.o libfoo.a
> for f in main; do echo "Running: $f"; ./$f; \
> if [ $? != 0 ]; then echo Failed; fi; done
> Running: main
> Failed
> # ./main
> zsh: 9648 segmentation fault ./main
>
>
I checked in the following patch to fix the bug.
H.J.
---
2001-06-20 H.J. Lu <hjl@gnu.org>
* elf32-i386.c (elf_i386_size_dynamic_sections): Always
allocate local .got space.
Index: elf32-i386.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf32-i386.c,v
retrieving revision 1.26
diff -u -p -r1.26 elf32-i386.c
--- elf32-i386.c 2001/06/06 15:26:15 1.26
+++ elf32-i386.c 2001/06/20 18:32:32
@@ -1190,6 +1190,7 @@ elf_i386_size_dynamic_sections (output_b
asection *s;
boolean relocs;
boolean reltext;
+ bfd *i;
htab = elf_i386_hash_table (info);
dynobj = htab->root.dynobj;
@@ -1197,7 +1198,6 @@ elf_i386_size_dynamic_sections (output_b
if (htab->root.dynamic_sections_created)
{
- bfd *i;
/* Set the contents of the .interp section to the interpreter. */
if (! info->shared)
@@ -1207,40 +1207,40 @@ elf_i386_size_dynamic_sections (output_b
s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
}
+ }
- /* Set up .got offsets for local syms. */
- for (i = info->input_bfds; i; i = i->link_next)
+ /* Set up .got offsets for local syms. */
+ for (i = info->input_bfds; i; i = i->link_next)
+ {
+ bfd_signed_vma *local_got;
+ bfd_signed_vma *end_local_got;
+ bfd_size_type locsymcount;
+ Elf_Internal_Shdr *symtab_hdr;
+ asection *srel;
+
+ if (bfd_get_flavour (i) != bfd_target_elf_flavour)
+ continue;
+
+ local_got = elf_local_got_refcounts (i);
+ if (!local_got)
+ continue;
+
+ symtab_hdr = &elf_tdata (i)->symtab_hdr;
+ locsymcount = symtab_hdr->sh_info;
+ end_local_got = local_got + locsymcount;
+ s = htab->sgot;
+ srel = htab->srelgot;
+ for (; local_got < end_local_got; ++local_got)
{
- bfd_signed_vma *local_got;
- bfd_signed_vma *end_local_got;
- bfd_size_type locsymcount;
- Elf_Internal_Shdr *symtab_hdr;
- asection *srel;
-
- if (bfd_get_flavour (i) != bfd_target_elf_flavour)
- continue;
-
- local_got = elf_local_got_refcounts (i);
- if (!local_got)
- continue;
-
- symtab_hdr = &elf_tdata (i)->symtab_hdr;
- locsymcount = symtab_hdr->sh_info;
- end_local_got = local_got + locsymcount;
- s = htab->sgot;
- srel = htab->srelgot;
- for (; local_got < end_local_got; ++local_got)
+ if (*local_got > 0)
{
- if (*local_got > 0)
- {
- *local_got = s->_raw_size;
- s->_raw_size += 4;
- if (info->shared)
- srel->_raw_size += sizeof (Elf32_External_Rel);
- }
- else
- *local_got = (bfd_vma) -1;
+ *local_got = s->_raw_size;
+ s->_raw_size += 4;
+ if (info->shared)
+ srel->_raw_size += sizeof (Elf32_External_Rel);
}
+ else
+ *local_got = (bfd_vma) -1;
}
}