This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[possible bug] assertion faliure in reloc16.c
- To: binutils at sources dot redhat dot com
- Subject: [possible bug] assertion faliure in reloc16.c
- From: Kazu Hirata <kazu at hxi dot com>
Hi,
When I tried to compile and link the following files with
h8300-hms-gcc, I got an assertion failure.
/* h8300-hms-gcc -Wall -O2 -fomit-frame-pointer -o main.o -c main.c */
int main ();
void
test ()
{
main ();
}
int
main ()
{
return 0;
}
/* h8300-hms-gcc -Wall -O2 -fomit-frame-pointer -o stupid.o -c stupid.c */
/* The same contents as the above. */
int main ();
void
test ()
{
main ();
}
int
main ()
{
return 0;
}
I know that this will cause multiple definition error at link time.
When a link is done with --relax, it gets worse:
/usr/local/bin/h8300-hms-gcc -mh -Wl,--relax -Wall -o h8os.out main.o stupid.o
stupid.o(.text+0x0):stupid.c: multiple definition of `test'
main.o(.text+0x0):main.c: first defined here
stupid.o(.text+0x6):stupid.c: multiple definition of `main'
main.o(.text+0x6):main.c: first defined here
/usr/local/lib/gcc-lib/h8300-hms/2.96/../../../../h8300-hms/bin/ld: bfd assertion fail ../../src/bfd/reloc16.c:131
collect2: ld returned 1 exit status
Now, how is the linker supposed to handle multiple definitions? I was
looking into bfd_link_callbacks and found multiple_definition, but I
wasn't able to figure out what function this is hooked to. Even if
the input is incorrect, I don't think the linker should crash or cause
an assertion failure.
I am guessing that the reason for the assetion failure is that, when
bfd_perform_slip is called to slip a requested amount of bytes, it
slips both a value in the hash table and a value associated with a
symbol. If we have two symbols, "main", then the first "main" gets
slipped with the value in the hash table slipped as well. When the
second "main" gets slipped, since the value in the hash table has been
slipped, the slip results in inequality between the value associated
with the second "main" and the value in the hash table.
Thanks,
Kazu Hirata