-gl option causes all executables to crash on MIPS
Original Reporter info from Mantis: jcowgill
-
Reporter name: James Cowgill
Original Reporter info from Mantis: jcowgill
- Reporter name: James Cowgill
Description:
Attempting 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 -abpo8+1 (2017-05-19) mips GNU/Linux
Linux eller 4.9.0-0.bpo.3-octeon #1 SMP Debian 4.9.25-1
(sid_mipsel-dchroot)jcowgill@eller:/fpc$ cat hworld.pas/fpc$ fpc hworld.pas
program Hello;
begin
writeln ('Hello, world.')
end.
(sid_mipsel-dchroot)jcowgill@eller:
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 /fpc$ fpc -gl hworld.pas
Hello, world.
(sid_mipsel-dchroot)jcowgill@eller:
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 information:
Running 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.
Mantis conversion info:
- Mantis ID: 32138
- OS: Debian
- OS Build: Unstable
- Platform: Linux/MIPS (EL, o32)
- Version: 3.0.2
- Fixed in version: 3.1.1
- Fixed in revision: 36781 (#6f613960)
- Target version: 4.0.0