View Issue Details

IDProjectCategoryView StatusLast Update
0032138FPCCompilerpublic2017-07-24 09:34
ReporterJames CowgillAssigned ToPierre Muller 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinux/MIPS (EL, o32)OSDebianOS VersionUnstable
Product Version3.0.2Product Build 
Target Version4.0.0Fixed in Version3.1.1 
Summary0032138: -gl option causes all executables to crash on MIPS
DescriptionAttempting to use the -gl option on MIPS causes all output binaries to crash on startup with SIGBUS.
Steps To Reproduce(sid_mipsel-dchroot)jcowgill@eller:~/fpc$ uname -a
Linux eller 4.9.0-0.bpo.3-octeon 0000001 SMP Debian 4.9.25-1~bpo8+1 (2017-05-19) mips GNU/Linux
(sid_mipsel-dchroot)jcowgill@eller:~/fpc$ cat hworld.pas
program Hello;
begin
  writeln ('Hello, world.')
end.
(sid_mipsel-dchroot)jcowgill@eller:~/fpc$ fpc hworld.pas
Free Pascal Compiler version 3.0.2+dfsg-4+b1 [2017/07/10] for mipsel
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for MIPSEL
Compiling hworld.pas
Assembling hello
Linking hworld
/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld.bfd: /usr/lib/fpc/3.0.2/units/mipsel-linux/rtl/system.o: warning: linking abicalls files with non-abicalls files
4 lines compiled, 0.3 sec
(sid_mipsel-dchroot)jcowgill@eller:~/fpc$ ./hworld
Hello, world.
(sid_mipsel-dchroot)jcowgill@eller:~/fpc$ fpc -gl hworld.pas
Free Pascal Compiler version 3.0.2+dfsg-4+b1 [2017/07/10] for mipsel
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for MIPSEL
Compiling hworld.pas
Assembling hello
Linking hworld
/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld.bfd: /usr/lib/fpc/3.0.2/units/mipsel-linux/rtl/system.o: warning: linking abicalls files with non-abicalls files
4 lines compiled, 0.3 sec
(sid_mipsel-dchroot)jcowgill@eller:~/fpc$ ./hworld
Bus error
Additional InformationRunning the program in gdb gives a strange invalid program counter value:

(gdb) run
Starting program: /home/jcowgill/fpc/hworld

Program received signal SIGBUS, Bus error.
main () at hworld.pas:2
2 begin
(gdb) print $pc
$1 = (^(procedure )) 0x4001c1 <main>

Since the $pc is exactly 1 above "main", I expect the linker thinks "main" is a mips16 function and has added 1 to the function offset so that the processor performs a mips16 ISA switch when calling it (although this mips processor does not support mips16).

Sure enough the symbol in the .o file is marked as MIPS16:
(sid_mipsel-dchroot)jcowgill@eller:~/fpc$ readelf --syms hworld.o | grep main
    32: 00000000 120 FUNC GLOBAL DEFAULT [MIPS16] 13 main

My current thinking is that the .stabs directives (which reference the "main" function label) confuse gas into thinking that main is a mips16 function. Adding a ".set nomips16" at the very top of the assembly file seems to fix it.
TagsNo tags attached.
Fixed in Revision36781
FPCOldBugId
FPCTarget
Attached Files

Activities

Pierre Muller

2017-07-12 08:36

developer   ~0101667

  I just tested your code on our testsuite machine,

I am unable to reproduce your problem using the official 3.0.2 mips release.

  Could you check if the official release has the same behavior?
For this, you woul need to download and install 3.0.2 release directly
from freepascal.org website.

  The behavior you see might be related to +dfsg-4-b1 debian
specific changes. I have no idea what those changes are...

Pierre Muller

2017-07-12 08:55

developer   ~0101668


  I just tested your code on our testsuite machine,

I was able to reproduce your problem using the official 3.0.2 mipsel release.

I can also confirm that adding
.set nomips16
line at the start of the assembler file fixes the bus error.

I tested adding -ao-no-mips16
(which adds -no-mips16 arg to assembler call)
does not seem to work.

  I don't know the current status of mips16 support
in Free Pascal compiler, so adding
.set nomips16
unconditionally might not be the correct solution.

Pierre
 

James Cowgill

2017-07-12 17:21

reporter   ~0101671

Hi,

I downloaded the official mips (big endian) release and I can still reproduce the bug. The "+dfsg-4+b1" comes from the Debian package. fpc MIPS was recently added to Debian and this is one of the bugs that was discovered from that.

I would have thought that adding -no-mips16 would fix it so I had a look at why it wasn't working, and it looks like this may in fact be an assembler bug. It looks like the bug only occurs if a ".stabs" directive are used before any ".set" directives. I guess noone noticed it because stabs isn't used a lot anymore, and GCC emits a bunch of ".set" directives right at the top of the assembly file.

I'll let you know when I submit a bug about it.

Thanks,
James

James Cowgill

2017-07-12 17:57

reporter   ~0101673

Here's the bug I filed:
https://sourceware.org/bugzilla/show_bug.cgi?id=21762

You can close this one if you want.

Pierre Muller

2017-07-24 09:34

developer   ~0101874

As the bug might need a long time to be
handled by binutils, and that numerous existing GNU assembler
have this problem anyway, I added an
explicit '.set nompis16'
pseudo-instruction in front of stabs debug information output.

  Please test a trunk after revision 36781 and confirm
that this fixes the report problem.

  Thanks for this report!

Pierre Muller

Issue History

Date Modified Username Field Change
2017-07-11 23:14 James Cowgill New Issue
2017-07-12 08:36 Pierre Muller Note Added: 0101667
2017-07-12 08:36 Pierre Muller Assigned To => Pierre Muller
2017-07-12 08:36 Pierre Muller Status new => feedback
2017-07-12 08:55 Pierre Muller Note Added: 0101668
2017-07-12 08:55 Pierre Muller Status feedback => confirmed
2017-07-12 17:21 James Cowgill Note Added: 0101671
2017-07-12 17:57 James Cowgill Note Added: 0101673
2017-07-24 09:34 Pierre Muller Fixed in Revision => 36781
2017-07-24 09:34 Pierre Muller Note Added: 0101874
2017-07-24 09:34 Pierre Muller Status confirmed => resolved
2017-07-24 09:34 Pierre Muller Fixed in Version => 3.1.1
2017-07-24 09:34 Pierre Muller Resolution open => fixed
2017-07-24 09:34 Pierre Muller Target Version => 4.0.0