This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH for i386: --no-copy-relocs
On Sat, Jun 23, 2001 at 04:57:05PM -0700, H . J . Lu wrote:
> On Sat, Jun 23, 2001 at 03:21:25PM -0700, H . J . Lu wrote:
> > On Sat, Jun 23, 2001 at 02:55:51AM +0930, Alan Modra wrote:
> > > On Thu, Jun 21, 2001 at 05:33:25PM -0700, Ian Lance Taylor wrote:
> > > >
> > > > If a symbol is only referenced from writable sections, then omitting
> > > > the COPY relocation is OK because those sections can not be shared anyhow.
> > >
> > > Here's a first pass at this change. Not overmuch tested yet ;)
> > > but I need to sleep. HJ, you said you'd happily test this for me,
> > > so here it is. ChangeLog coming later.
> > >
> > >
> >
> > Here is a testcase.
> >
> > # make
> > gcc -O -g -fPIC -c -o main.o main.c
> > gcc -O -g -fPIC -c -o foo.o foo.c
> > gcc -static -o foo main.o foo.o
> > for f in foo; do echo "Running: $f"; ./$f; \
> > if [ $? != 0 ]; then echo Failed; fi; done
> > Running: foo
> > Failed
> > # ./foo
> > zsh: 1862 segmentation fault ./foo
> >
> >
> > I am looking into it now.
> >
> >
> > H.J.
>
> Alan,
>
> This patch seems to work for me. The condition we want to check is
> a symbol is defined, but not defined in the regular object. I think we
> should check ELF_LINK_HASH_DEF_DYNAMIC, not ELF_LINK_HASH_DEF_REGULAR
> since the common symbol in the regular object won't set
> ELF_LINK_HASH_DEF_REGULAR.
>
> I will also check if it handls the weak symbol right.
>
>
No. The weak symbol is broken. This patch works. Alan, what do you
think? Could you please double check the rest of your changes?
Thanks.
H.J.
----
2001-06-23 H.J. Lu <hjl@gnu.org>
* elf32-i386.c (elf_i386_relocate_section): Check the
ELF_LINK_HASH_DEF_DYNAMIC to see if a symbol is not defined
in the regular object file. Treat the weak definition as
the normal one.
--- elf32-i386.c.new Sat Jun 23 16:44:18 2001
+++ elf32-i386.c Sat Jun 23 17:00:39 2001
@@ -1693,9 +1693,10 @@ elf_i386_relocate_section (output_bfd, i
&& h != NULL
&& h->dynindx != -1
&& (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
- && (h->root.type == bfd_link_hash_defweak
- || (h->elf_link_hash_flags
- & ELF_LINK_HASH_DEF_REGULAR) == 0)))
+ && ((h->root.type == bfd_link_hash_defweak
+ || h->root.type == bfd_link_hash_defined)
+ && (h->elf_link_hash_flags
+ & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))
{
Elf_Internal_Rel outrel;
boolean skip, relocate;