Original post is here: eklausmeier.goip.de
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.
1git clone https://git.symas.net/cobolworx/gcc-cobol.git
2Cloning into 'gcc-cobol'...
3remote: Enumerating objects: 2364034, done.
4remote: Counting objects: 100% (407/407), done.
5remote: Compressing objects: 100% (168/168), done.
6remote: Total 2364034 (delta 287), reused 343 (delta 234), pack-reused 2363627
7Receiving objects: 100% (2364034/2364034), 805.41 MiB | 18.46 MiB/s, done.
8Resolving deltas: 100% (1947302/1947302), done.
9Updating files: 100% (101783/101783), done.
Downloading the auxiliary libs is fast:
1cd gcc-cobol
2wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
3wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
4wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
5wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
Then create build directory:
1mkdir build && cd build
Now configure:
1CFLAGS="-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:
1time 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
1make install
It will install in /usr/local/gcobol
.
2. Compiling COBOL programs. I used the hello-word program
1 IDENTIFICATION DIVISION.
2 PROGRAM-ID. hello.
3 PROCEDURE DIVISION.
4 DISPLAY "Hello, world".
For compiling this COBOL program I first tried
1/usr/local/gcobol/bin/gcobol hello2.cbl -o hello2
This gives error message
1/bin/ld: /lib/../lib64/crt1.o: in function `_start':
2(.text+0x1b): undefined reference to `main'
3/bin/ld: /tmp/cc5ZAQDK.o: in function `hello':
4hello2.cbl:(.text+0x5e): undefined reference to `__gg__initialize_variable'
5/bin/ld: hello2.cbl:(.text+0x72): undefined reference to `__gg__initialize_variable'
6/bin/ld: hello2.cbl:(.text+0x86): undefined reference to `__gg__initialize_variable'
7/bin/ld: hello2.cbl:(.text+0x9a): undefined reference to `__gg__initialize_variable'
8/bin/ld: hello2.cbl:(.text+0xae): undefined reference to `__gg__initialize_variable'
9/bin/ld: /tmp/cc5ZAQDK.o:hello2.cbl:(.text+0xc2): more undefined references to `__gg__initialize_variable' follow
10/bin/ld: /tmp/cc5ZAQDK.o: in function `hello':
11hello2.cbl:(.text+0x52f): undefined reference to `__gg__refer_resolve_minimal'
12/bin/ld: hello2.cbl:(.text+0x54d): undefined reference to `__gg__display_resolved'
13collect2: error: ld returned 1 exit status
Next I tried
1/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:
1/bin/ld: warning: cannot find entry symbol _start; defaulting to 00000000004023a0
Running the resulting program
1Hello, world
2zsh: segmentation fault (core dumped) ./hello2
Clearly this COBOL compiler is still in its infancy.
Next I tried
1000010 IDENTIFICATION DIVISION.
2000020 PROGRAM-ID. hello.
3000030 AUTHOR. Elmar Klausmeier.
4000040 DATE-WRITTEN. 01-Jul-2004.
5000050
6000060 DATA DIVISION.
7000070 WORKING-STORAGE SECTION.
8000080 01 I PIC 9(5).
9000090
10000100 PROCEDURE DIVISION.
11000110 DISPLAY "Hello World!".
12 PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
13 DISPLAY I
14 END-PERFORM.
15
16000140 STOP RUN.
17000150
Compiling gives:
1cobol1: syntax error, line 1 at '000010'
2cobol1: 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:
1cobol1: syntax error, line 40 at 'PROCEDURE DIVISION'
2cobol1: error: failed compiling xdamcnt.cbl
So I had to remove the LINKAGE SECTION
. Then I got
1cobol1: parser_goto:6111: function not implemented
2cobol1: parser_goto:6111: function not implemented
3cobol1: syntax error, line 122 at 'end-if'
4cobol1: 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
1/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.
- Resulting programs can crash but shouldn't.
- Resulting programs may give entirely wrong results.
- Many COBOL statements are not supported.
- The binaries are almost 30-times bigger than the binaries produced with GnuCOBOL.
- 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.