, 5 min read

Testing COBOLworx gcc-cobol

In an article An open-source COBOL contender emerges a "real" compiler for COBOL was announced. This newly announced compiler is a frontend to gcc. This contrasts with GnuCOBOL, which translates COBOL to C and then calls gcc. As the performance of GnuCOBOL is a little bit disappointing, see Comparing GnuCOBOL to IBM COBOL, I was interested whether this new compiler provides some relief at the performance front.

The announcement is here: James K. Lowden, Announcement: gcobol.

The source code is here: gcc-cobol, it was here gcc-cobol, but that link no longer works -- dead link.

1. Installation. I followed the steps in README.md. Cloning the repository takes around 5 minutes. It has to download almost 1 GB of data.

git clone https://git.symas.net/cobolworx/gcc-cobol.git
Cloning into 'gcc-cobol'...
remote: Enumerating objects: 2364034, done.
remote: Counting objects: 100% (407/407), done.
remote: Compressing objects: 100% (168/168), done.
remote: Total 2364034 (delta 287), reused 343 (delta 234), pack-reused 2363627
Receiving objects: 100% (2364034/2364034), 805.41 MiB | 18.46 MiB/s, done.
Resolving deltas: 100% (1947302/1947302), done.
Updating files: 100% (101783/101783), done.

Downloading the auxiliary libs is fast:

cd gcc-cobol
wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2

Then create build directory:

mkdir build && cd build

Now configure:

CFLAGS="-g3 -O0" CXXFLAGS="-g3 -O0" ../configure --prefix=/usr/local/gcobol --with-pkgversion='gcc with COBOL front end' --disable-bootstrap --enable-checking --enable-languages=c,c++,cobol

Finally compile:

time make -j4

It took roughly 30 minutes on my NUC, i5-4250U CPU, max. 2.6 GHz, 8 GB RAM. I had to restart the whole compilation once, as some spurious error occured. Just restarting solved the issue.

As I did not want it to interfere with my "real" gcc, I created the /usr/local/gcobol directory beforehand and chown myuser:myuser /usr/local/gcobol. After configuring and making, run

make install

It will install in /usr/local/gcobol.

2. Compiling COBOL programs. I used the hello-word program

        IDENTIFICATION DIVISION.
        PROGRAM-ID. hello.
        PROCEDURE DIVISION.
        DISPLAY "Hello, world".

For compiling this COBOL program I first tried

/usr/local/gcobol/bin/gcobol hello2.cbl -o hello2

This gives error message

/bin/ld: /lib/../lib64/crt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
/bin/ld: /tmp/cc5ZAQDK.o: in function `hello':
hello2.cbl:(.text+0x5e): undefined reference to `__gg__initialize_variable'
/bin/ld: hello2.cbl:(.text+0x72): undefined reference to `__gg__initialize_variable'
/bin/ld: hello2.cbl:(.text+0x86): undefined reference to `__gg__initialize_variable'
/bin/ld: hello2.cbl:(.text+0x9a): undefined reference to `__gg__initialize_variable'
/bin/ld: hello2.cbl:(.text+0xae): undefined reference to `__gg__initialize_variable'
/bin/ld: /tmp/cc5ZAQDK.o:hello2.cbl:(.text+0xc2): more undefined references to `__gg__initialize_variable' follow
/bin/ld: /tmp/cc5ZAQDK.o: in function `hello':
hello2.cbl:(.text+0x52f): undefined reference to `__gg__refer_resolve_minimal'
/bin/ld: hello2.cbl:(.text+0x54d): undefined reference to `__gg__display_resolved'
collect2: error: ld returned 1 exit status

Next I tried

/usr/local/gcobol/bin/gcobol hello2.cbl -o hello2 -lgcobol -lm -nostartfiles

In crt1.o: In function _start': - undefined reference to main' in Linux I found the link flag -nostartfiles. Above command gives:

/bin/ld: warning: cannot find entry symbol _start; defaulting to 00000000004023a0

Running the resulting program

Hello, world
zsh: segmentation fault (core dumped)  ./hello2

Clearly this COBOL compiler is still in its infancy.

Next I tried

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. hello.
000030 AUTHOR.       Elmar Klausmeier.
000040 DATE-WRITTEN. 01-Jul-2004.
000050
000060 DATA DIVISION.
000070 WORKING-STORAGE SECTION.
000080 01 I       PIC 9(5).
000090
000100 PROCEDURE DIVISION.
000110     DISPLAY "Hello World!".
           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
               DISPLAY I
           END-PERFORM.

000140     STOP RUN.
000150

Compiling gives:

cobol1: syntax error, line 1 at '000010'
cobol1: error: failed compiling hello.cbl

This compiler does not like line numbering. Just for the records, line numbering in columns 1-6 is absolute valid COBOL.

I then tried the n-queens problem, see Comparing GnuCOBOL to IBM COBOL. Compiling gives:

cobol1: syntax error, line 40 at 'PROCEDURE DIVISION'
cobol1: error: failed compiling xdamcnt.cbl

So I had to remove the LINKAGE SECTION. Then I got

cobol1: parser_goto:6111: function not implemented
cobol1: parser_goto:6111: function not implemented
cobol1: syntax error, line 122 at 'end-if'
cobol1: error: failed compiling xdamcnt2.cbl

So this COBOL compiler does not understand exit section. I changed all these statements to appropriate go to's to the end of the section. I compiled

/usr/local/gcobol/bin/gcobol xdamcnt2.cbl -o xdamcnt2 -lgcobol -lm -nostartfiles

Running the resulting programs gives entirely wrong results. I double checked that the exact same program compiled with GnuCOBOL gives correct results.

3. Summary. This COBOL compiler is still way pre-alpha. It cannot be used for any real COBOL programs.

  1. Resulting programs can crash but shouldn't.
  2. Resulting programs may give entirely wrong results.
  3. Many COBOL statements are not supported.
  4. The binaries are almost 30-times bigger than the binaries produced with GnuCOBOL.
  5. Looking at the used symbols it looks that many MOVE statements result in function calls, similar to GnuCOBOL. But this indicates that probably no performance gain can be expected against GnuCOBOL.

To put above harsh comments into perspective: The developers never claimed that their compiler is production ready. From the announcement:

We are working on compiling the NIST COBOL test suite, which we expect will take a few months to complete. (...) Today, we want to make the project known to those in the technical community who might most want to know what we're up to, and explain why we'll be asking the questions we're asking.

Added 20-Mar-2022: Heise.de in Frischzellenkur für die Programmiersprache COBOL: Neuer FOSS-Compiler gcobol also mentions the announcement.

Added 12-Feb-2023: A follow-up to this test is here: Testing COBOLworx gcc-cobol #2.