Using ELLCC

Getting Started

If ELLCC is installed on your system you can run the ecc or ecc++ compiler by using the compiler’s full path name:

[test@main ~]$ /home/test/ellcc/bin/ecc main.c

Or you can add the ELLCC bin directory to your PATH. A simple way to do this is to execute the ellcc command in the installation directory:

[test@main ~]$ ellcc/ellcc

You’ll end up in a shell with the PATH set up properly. In the following examples, it’s assumed that the bin directory is in your path.

Compiling a program is simple. Here’s an example:

[test@main ~]$ cat main.c
#include 

int main()
{
  printf("hello world\n");
}

[test@main ~]$ ecc main.c
[test@main ~]$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /home/test/ellcc/libecc/lib/x86_64-linux/libc.so, BuildID[sha1]=083edc79d82ffe3b3c50f1499fc40cc31c89dd01, not stripped
[test@main ~]$ ./a.out
hello world
[test@main ~]$ 

You’ll notice that the executable file, a.out, is a dynamically linked file using shared libraries. You can generate an statically linked version with the -static option:

[test@main ~]$ ecc main.c -static
[test@main ~]$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=c88f6148b5c9715d5ad85bb224e943cb9503c64e, not stripped

A similar example using C++:

[test@main ~]$ cat main.cpp
#include 

int main()
{
  std::cout << "hello world" << std::endl;
}
[test@main ~]$ ecc++ main.cpp
[test@main ~]$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /home/rich/tmp/ellcc/libecc/lib/x86_64-linux/libc.so, BuildID[sha1]=edf3947828346add24dc5673e2370e2a1a1a8031, not stripped
[test@main ~]$ ./a.out
hello world
[test@main ~]$ 

Cross Compiling

Using ecc as a cross compiler is as simple as adding the -target option. The -target option takes a configuration name as an argument. A configuration name is of the form <arch>-<environment>.

Available configurations are:

Processor -target option OS Endian Float
32 bit ARMv6 arm32v6-linux Linux Little Hard
32 bit ARMv6 arm32v6sf-linux Linux Little Soft
32 bit ARM arm32v7ebsf-linux Linux Big Soft
32 bit ARM arm32v7eb-linux Linux Big Hard
32 bit ARM arm32v7sf-linux Linux Little Soft
32 bit ARM arm32v7-linux Linux Little Hard
ARM Cortex-M3 cortex-m3-linux Linux Little Soft
64 bit ARM AArch64 arm64v8-linux Linux Little Hard
32 bit Mips mips32r2el-linux Linux Little Hard
32 bit Mips mips32r2elsf-linux Linux Little Soft
32 bit Mips mips32r2-linux Linux Big Hard
32 bit Mips mips32r2sf-linux Linux Big Soft
32 bit PowerPC ppc32-linux Linux Big Hard
64 bit PowerPC ppc64le-linux Linux Little Hard
32 bit X86 x86_32-linux Linux Little Hard
64 bit X86 x86_64-linux Linux Little Hard

You can use the -target option to select the processor:

[test@main ~]$ ecc -target arm32v7-linux hello.c

or you can make a symbolic link like this

[test@main ~]$ cd ellcc/bin
[test@main bin]$ ln -s ecc arm32v7-linux-ecc
[test@main bin]$

to avoid having to specify the "-target" explicitly.

[test@main ~]$ arm32v7-linux-ecc main.c
[test@main ~]$ file a.out
a.out: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /home/test/ellcc/libecc/lib/arm32v7-linux/libc.so, BuildID[sha1]=cb7455270bb2c561827690f7a1a6bf4d79fdd831, not stripped
[test@main ~]$

To compile a program, a typical command line looks like this:

[test@main ~]$ ecc -target mips32r2-linux main.c

This will create a Mips executable a.out if everything is installed correctly.
You might get errors that look like this:

[test@main ~]$ ecc -target mips32r2-linux main.c
/home/test/ellcc/bin/ecc-ld: cannot find /home/test/ellcc/libecc/lib/mips32r2-linux/Scrt1.o: No such file or directory
/home/test/ellcc/bin/ecc-ld: cannot find -lc
/home/test/ellcc/bin/ecc-ld: cannot find -lcompiler-rt
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation
[test@main ~]$ 

That means that the run-time libraries for that target have not been built or installed. The ELLCC binary distribution and the default build when building from source have libraries only for the build host. Whether you are using the binary distribution or have built ELLCC from source, you can install pre-compiled run-time libraries for all the supported targets using the ellcc install libraries command:

[test@main ~]$ cd ellcc
[test@main ellcc] ellcc install libraries
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 67.9M  100 67.9M    0     0   336M      0 --:--:-- --:--:-- --:--:--  336M
libecc/lib/
libecc/lib/ppc64el-linux/
libecc/lib/ppc64el-linux/libmenu.so
libecc/lib/ppc64el-linux/libmetalink.so
libecc/lib/ppc64el-linux/libpthread.a
libecc/lib/ppc64el-linux/crtn.o
...
libecc/lib/mips64r2-linux/libz.so.1
libecc/lib/mips64r2-linux/libpanel.so
libecc/lib/mips64r2-linux/libc.so
libecc/lib/mips64r2-linux/libmenu.a
libecc/lib/mips64r2-linux/libmenuw.so
libecc/lib/mips64r2-linux/libpanelw.so
libecc/lib/mips64r2-linux/libterminfo.a
libecc/lib/mips64r2-linux/libmbedx509.so.0
libecc/lib/mips64r2-linux/libexpat.so.1.6.4
libecc/lib/mips64r2-linux/libtermcap.a
libecc/lib/mips64r2-linux/libmenuw.a
libecc/lib/mips64r2-linux/librt.a
[test@main ellcc]$ cd ..
[test@main ~]$ ecc -target mips32r2-linux main.c
[test@main ~]$ file a.out
a.out: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /home/test/ellcc/libecc/lib/mips32r2-linux/libc.so, BuildID[sha1]=e35c923f9bfd8dad6ca95cbf28a0f5cb50ebdda3, not stripped
[test@main ~]$

Tool Configuration Files

All of these tool configurations are defined by configuration files in ellcc/libecc/toolinfo. These files are just text files in YAML format. You can make your own configuration by copying one of the existing files and modifying it as required.

Upgrading a Binary Distribution

When a new version of ELLCC comes out you can upgrade to it with ellcc upgrade. If you try it before a new version is available you'll get this:

[test@main ellcc]$ ellcc upgrade
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5324  100  5324    0     0  40793      0 --:--:-- --:--:-- --:--:-- 40953
At the latest revision: 2017-07-29
package 'ellcc-libraries' is up to date.
[test@main ellcc]$

Checking Current Component Versions

You can check the versions of the various ELLCC components with the ellcc versions command:

[test@main ~]$ ellcc versions
Current versions:
         Package: Revision                                     Date
-----------------------------------------------------------------------------
           ellcc: 2017-07-29
                  The latest ELLCC release
                  http:// ellcc.org
    binutils-gdb: git-4c9dc8114942ec02e1adacf9aea6d65dc5849e9c 2017-07-29
                  Source level debugger, assemblers, linker, and utilities
                  http://www.gnu.org/software/binutils
          c-ares: git-33bf5ba35e2df09ecde9530816733965bb4053e4 2017-07-29
                  Asynchronous DNS library
                  http://c-ares.haxx.se
     compiler-rt: svn-309487                                   2017-07-29
                  Low level compiler support library
                  https://compiler-rt.llvm.org/
            curl: tar-7.54.1                                   2017-07-25
                  Command line tool and library for transferring data with URL syntax
                  http://curl.haxx.se
          curses: git-4c156be994dc8b74d2b03c67b3018b55b19d2f8a 2017-07-29
                  NetBSD curses terminal handling library
                  https://github.com/sabotage-linux/netbsd-curses
           expat: git-6a8267696c3e6ec24838688b63ce0b7cf15b3e55 2017-07-29
                  XML parsing library
                  http://expat.sourceforge.net
          libcxx: svn-309487                                   2017-07-29
                  LLVM's libc++ standard library
                  https://libcxx.llvm.org
         libedit: tar-20170329-3.1                             2017-07-25
                  Command history editing library
                  http://thrysoee.dk/editline
     libmetalink: tar-0.1.3                                    2017-07-25
                  Add Metalink functionality such as parsing Metalink XML files
                  https://launchpad.net/libmetalink
         libssh2: git-6762664e7e82e334f6e0d0d1719f0e57c044d186 2017-07-29
                  Client-side library implementing the SSH2 protocol
                  http://www.libssh2.org
            llvm: svn-309487                                   2017-07-29
                  clang/LLVM C/C++ compiler
                  http://www.llvm.org
         mbedtls: git-5a1c0e716242acfc7027c78e36487f8df1786c83 2017-07-29
                  Transport Layer Security (TLS) library
                  https://tls.mbed.org
            musl: git-a08910fc2cc739f631b75b2d09b8d72a0d64d285 2017-07-29
                  C standard library
                  http://www.musl-libc.org
         nghttp2: tar-1.24.0                                   2017-07-25
                  Library providing HTTP/2 support
                  https://nghttp2.org
        patchelf: git-29c085fd9d3fc972f75b3961905d6b4ecce7eb2b 2017-07-29
                  The latest ELLCC release
                  http:// ellcc.org
            zlib: git-cacf7f1d4e3d44d871b605da3b647f07d718623f 2017-07-29
                  Compression library
                  http://www.zlib.net
[test@main ~]$