https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127267
--- Comment #5 from Jeffrey A. Law <law at gcc dot gnu.org> ---
I've done a bit of debugging here. I'm of the opinion that Roger's patches are
correct and that the regressions with his patch are some kind of secondary
failure in the linker or perhaps a memory clash issue.
If we start peeking at _exit we see this sequence in the relevant .o file
74: 3c 02 00 00 lui r2,0x0
74: R_IQ2000_HI16 __trap0
78: 34 42 00 00 ori r2,r2,0x0
78: R_IQ2000_LO16 __trap0
7c: 00 40 f8 09 jalr r31,r2
That lines up with my expectation. We compute the address of __trap0 and jump
to it. And if we look at the executable for __trap0 we see:
8000c708 T __trap0
root@261cb125754d:/home/jlaw/jenkins/workspace/iq2000-elf/iq2000-elf-obj/gcc/gcc#
%
iq2000-elf-gdb ./a.out
x/10i 0x8000c708
x/10i 0x8000c708
0x8000c708 <__trap0>: nop
0x8000c70c <__trap0+4>: or r4,r0,r4
0x8000c710 <__trap0+8>: nop
0x8000c714 <__trap0+12>: or r5,r0,r5
0x8000c718 <__trap0+16>: nop
0x8000c71c <__trap0+20>: or r6,r0,r6
0x8000c720 <__trap0+24>: nop
0x8000c724 <__trap0+28>: or r7,r0,r7
0x8000c728 <__trap0+32>: nop
0x8000c72c <__trap0+36>: or r11,r0,r4
Which again fits my expectation. That's the sequence I see if I go look at the
source for trap0 on the iq2000 port. Now if I look at the exit sequence in the
actual binary:
0x8000c4a8 <_exit+96>: jal 0x80010648 <__deregister_frame_info>
0x8000c4ac <_exit+100>: nop
0x8000c4b0 <_exit+104>: or r7,r0,r0
0x8000c4b4 <_exit+108>: or r6,r0,r0
0x8000c4b8 <_exit+112>: or r5,r0,r18
=> 0x8000c4bc <_exit+116>: lui r2,0x1
0x8000c4c0 <_exit+120>: ori r2,r2,0xc708
0x8000c4c4 <_exit+124>: jalr r31,r2
0x8000c4c8 <_exit+128>: ori r4,r0,0x1
That's going to compute 0x1c708. Naturally when we hit that transfer of
control we go off into the weeds and eventually get a failure.
There's a bit of weirdnes with the addresses on iq2000 which I don't understand
yet, but that's just so clearly wrong and matches the actual behavior I see in
the simulator.
No idea why it trips with Roger's patch, but I have seen the iq2000 port be a
bit flakey through the years. Anyway, I'm going to push Roger's patch and
close out this bug.