tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
179 stars 13 forks source link

Possible compiler bug #83

Open lukflug opened 3 years ago

lukflug commented 3 years ago

I've tried to use GCC-IA16 to write a real mode OS. However, I've ran into an issue, which may be a compiler bug:

ia16-elf-gcc -ffreestanding -I. -pipe -O2 -Wall -Wextra -v -save-temps -c lib/klib.c -o lib/klib.o
ia16-elf-gcc: warning: -pipe ignored because -save-temps specified
Using built-in specs.
COLLECT_GCC=ia16-elf-gcc
Target: ia16-elf
Configured with: ../gcc-ia16/configure --target=ia16-elf --prefix=/mnt/c/Users/[REDACTED]/Documents/Git/LibreDOS/toolchain --disable-nls --enable-languages=c --without-headers --disable-multilib
Thread model: single
gcc version 6.3.0 (GCC)
COLLECT_GCC_OPTIONS='-ffreestanding' '-I' '.' '-pipe' '-O2' '-Wall' '-Wextra' '-v' '-save-temps' '-c' '-o' 'lib/klib.o'
 /mnt/c/Users/[REDACTED]/Documents/Git/LibreDOS/toolchain/libexec/gcc/ia16-elf/6.3.0/cc1 -E -quiet -v -I . lib/klib.c -Wall -Wextra -ffreestanding -O2 -fpch-preprocess -o klib.i
ignoring nonexistent directory "/mnt/c/Users/[REDACTED]/Documents/Git/LibreDOS/toolchain/lib/gcc/ia16-elf/6.3.0/../../../../ia16-elf/sys-include"
ignoring nonexistent directory "/mnt/c/Users/[REDACTED]/Documents/Git/LibreDOS/toolchain/lib/gcc/ia16-elf/6.3.0/../../../../ia16-elf/include"
#include "..." search starts here:
#include <...> search starts here:
 .
 /mnt/c/Users/[REDACTED]/Documents/Git/LibreDOS/toolchain/lib/gcc/ia16-elf/6.3.0/include
 /mnt/c/Users/[REDACTED]/Documents/Git/LibreDOS/toolchain/lib/gcc/ia16-elf/6.3.0/include-fixed
End of search list.
COLLECT_GCC_OPTIONS='-ffreestanding' '-I' '.' '-pipe' '-O2' '-Wall' '-Wextra' '-v' '-save-temps' '-c' '-o' 'lib/klib.o'
 /mnt/c/Users/[REDACTED]/Documents/Git/LibreDOS/toolchain/libexec/gcc/ia16-elf/6.3.0/cc1 -fpreprocessed klib.i -quiet -dumpbase klib.c -auxbase-strip lib/klib.o -O2 -Wall -Wextra -version -ffreestanding -o klib.s
GNU C11 (GCC) version 6.3.0 (ia16-elf)
        compiled by GNU C version 8.3.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C11 (GCC) version 6.3.0 (ia16-elf)
        compiled by GNU C version 8.3.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: fffd419c039024ff09e72dee2ac417db
lib/klib.c: In function 'kalloc':
lib/klib.c:188:1: error: unrecognizable insn:
 }
 ^
(insn 218 103 107 12 (parallel [
            (set (mem:HI (plus:HI (reg:HI 121 [ heap_chunk ])
                        (unspec:HI [
                                (reg:HI 122 [ heap_chunk+2 ])
                            ] 1)) [2 heap_chunk_1->free+0 S2 A524288 AS1])
                (plus:HI (minus:HI (subreg:HI (reg:SI 34 [ _21 ]) 2)
                        (eq:HI (reg:CCZ_C 14 cc)
                            (const_int 0 [0])))
                    (const_int 0 [0])))
            (clobber (reg:CC 14 cc))
        ]) lib/klib.c:166 -1
     (nil))
lib/klib.c:188:1: internal compiler error: in extract_insn, at recog.c:2287
0x8ce1e3 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)
        ../../gcc-ia16/gcc/rtl-error.c:108
0x8ce219 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
        ../../gcc-ia16/gcc/rtl-error.c:116
0x8a369f extract_insn(rtx_insn*)
        ../../gcc-ia16/gcc/recog.c:2287
0xcc08d7 decompose_multiword_subregs
        ../../gcc-ia16/gcc/lower-subreg.c:1466
0xcc16fd execute
        ../../gcc-ia16/gcc/lower-subreg.c:1736
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

I'm building this on Debian WSL2.

Here is the preprocessed source file: klib.i (Sorry for the somewhat messy code)

tkchia commented 3 years ago

Hello @lukflug,

Thanks for the report. Yes, this is a bug — the compiler should not flag an "internal compiler error", ever. I will see how I can fix this issue.

Thank you!

tkchia commented 3 years ago

Hello @lukflug,

I am currently trying to reduce the input code you supplied, to a smaller input that triggers the bug, which will hopefully be easier to easier to reason about.

In the meantime, it seems to me that you can work around this bug, by declaring heap_chunk_ptr as an unsigned rather than an unsigned long (I believe it only needs to hold a 16-bit segment component value?).

Thank you!

lukflug commented 3 years ago

Thank you for the swift response!

The bug was triggered by adding following line (which I did to track down a logic error in my code):

kprn_x(((unsigned int)((unsigned long)(heap_chunk) >> 16)));

This line is located in the infinite for loop inside kalloc.

I hope this helps!