GCC-Java-4.9.1

Introduction to GCC-Java

See the introduction to the Java language and system at java-1.7.0.65. The GNU Compiler Collection (GCC) contains a Java compiler to native code. Together with the ecj Java compiler from Eclipse (to bytecode), it provides a way to build an acceptable JVM from source. However, since the release of OpenJDK, the development of GCC-Java has almost stopped, and the built JVM is an old version. One reason to build this system is that it can be used to bootstrap OpenJDK-1.7.0.65/IcedTea-2.5.2, without the need for downloading a Java binary.

This package is known to build and work properly using an LFS-7.6 systemd platform.

[Caution]

Caution

Using the instructions on this page will have the effect that the C and C++ compiler and libraries will be reinstalled, overwriting the ones on your system. This may lead to some issues. Please read the note and caution on the GCC-4.9.1 page.

Package Information

Additional Downloads

GCC Dependencies

Required

Zip-3.0, UnZip-6.0, and Which-2.20

Recommended

Optional

GTK+-2.24.24 and Libart for building the AWT peer

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/gcc-java

Installation of GCC Java

The instructions below assume that the C and C++ compilers have the same version as the one you are installing, so that a “bootstrap” is not necessary. If you are upgrading the GCC version, then remove the --disable-bootstrap from the ./configure options below.

As in LFS, fix a problem identified upstream:

sed -i 's/if \((code.*))\)/if (\1 \&\& \!DEBUG_INSN_P (insn))/' gcc/sched-deps.c

Install GCC Java by running the following commands:

sed -i 's/\(install.*:\) install-.*recursive/\1/' libffi/Makefile.in         &&
sed -i 's/\(install-data-am:\).*/\1/'             libffi/include/Makefile.in &&

patch -Np1 -i ../gcc-4.9.1-upstream_fixes-1.patch &&

cp ../ecj-latest.jar ./ecj.jar &&

mkdir ../gcc-build &&
cd    ../gcc-build &&

../gcc-4.9.1/configure           \
    --prefix=/usr                \
    --disable-multilib           \
    --with-system-zlib           \
    --disable-bootstrap          \
    --enable-java-home           \
    --with-jvm-root-dir=/opt/gcj \
    --with-antlr-jar=$(pwd)/../antlr-4.2.2-complete.jar \
    --enable-languages=java &&
make

If you have installed additional packages such as Valgrind and GDB, the GCC part of the testsuite will run more tests than in LFS. Some of those will report FAIL and others XPASS (pass when expected to FAIL). To run the tests, issue:

ulimit -s 32768 &&
make -k check

The tests are very long, and the results may be hard to find in the logs, specially if you use job control with make. You can get a summary of the tests with:

../gcc-4.9.1/contrib/test_summary

Now, as the root user:

make install &&

mkdir -pv /usr/share/gdb/auto-load/usr/lib              &&
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib &&

chown -v -R root:root \
    /usr/lib/gcc/*linux-gnu/4.9.1/include{,-fixed} &&

gcj -o ecj ../ecj-latest.jar \
    --main=org.eclipse.jdt.internal.compiler.batch.Main &&
mv ecj /usr/bin &&
ln -sfv ../../../usr/bin/ecj /opt/gcj/bin/javac

Command Explanations

The two sed commands prevent the installation of the libffi library bundled with GCC, since it is outdated compared to libffi-3.1.

patch ... gcc-4.9.1-upstream_fixes-1.patch: This patch corrects bugs in the C++ compiler, which lead to segmentation faults in some cases.

mkdir ../gcc-build; cd ../gcc-build: The GCC documentation recommends building the package in a dedicated build directory.

--disable-multilib: This parameter ensures that files are created for the specific architecture of your computer.

--with-system-zlib: Uses the system zlib instead of the bundled one.

--disable-bootstrap: Prevents the C and C++ compilers to recompile themselves. You should use this switch only if the installed C and C++ compilers are the same version as the ones you install.

--enable-java-home: Creates a directory layout similar to that of a JVM.

--with-jvm-root-dir=/opt/gcj: Installs the JVM in the specified location.

--with-antlr-jar=...: Specifies the location of ANTLR, which is needed to build gjdoc. Remove if you have not downloaded antlr.

--enable-languages=java: This command identifies which language to build. Note it is unavoidable that the C and C++ compilers be built too.

--enable-java-awt=gtk: Allows to build the Java AWT GTK+2 peer. Needed to have a fully functional JVM.

ulimit -s 32768: This command prevents several tests from running out of stack space.

make -k check: This command runs the test suite without stopping if any errors are encountered.

../gcc-4.9.1/contrib/test_summary: This command will produce a summary of the test suite results. You can append | grep -A7 Summ to the command to produce an even more condensed version of the summary. You may also wish to redirect the output to a file for review and comparison later on.

chown -v -R root:root /usr/lib/gcc/*linux-gnu/...: If the package is built by a user other than root, the ownership of the installed include directory (and its content) will be incorrect. This commands changes the ownership to the root user and group.

gcj -o ecj ...: compiles the eclipse compiler to native code, which is much faster than bytecode. This compiler is then used as a javac replacement in the JVM.

Configuring GCC-Java

Configuration Information

The configuration is the same as for OpenJDK-1.7.0.65/IcedTea-2.5.2, replacing /opt/jdk with /opt/gcj.

Contents

Installed Programs: aot-compile, ecj, gappletviewer, gc-analyze, gcj, gcj-dbtool, gcjh, gij, gjar, gjarsigner, gjavah, gjdoc, gkeytool, gnative2ascii, gorbd, grmic, grmid, grmiregistry, gserialver, gtnameserv, jcf-dump, jv-convert, rebuild-gcj-db. Symbolic links to these files are located in /opt/gcj/bin
Installed Libraries: libgcj_bc.so, libgcj.so, libgcj-tools.so libgij.so, and numerous other run-time libraries and executables in /usr/lib/gcc and /usr/libexec/gcc
Installed Directories: /usr/include/c++/4.9.1/{gcj,gnu,java,javax,org,sun}, /usr/lib/gcj-4.9.1-15, /usr/lib/security, /opt/gcj/{bin,jre} and /usr/share/java

Some program and library names and descriptions are not listed here, but can be found at ../../../../lfs/view/7.6-systemd/chapter06/gcc.html#contents-gcc as they were initially installed during the building of LFS.

Short Descriptions

aot-compile

searches a directory for Java bytecode and uses gcj to compile it to native code.

ecj

is the eclipse compiler.

gappletviewer

loads and run a Java applet.

gc-analyze

analyzes garbage collector (GC) memory dumps from Java code.

gcj

is an ahead-of-time compiler for the Java language.

gcj-dbtool

is a tool for creating and manipulating class file mapping databases.

gcjh

generates header files from Java class files.

gij

is the GNU interpreter for Java bytecode.

gjar

is an (partial) implementation of the jar utility that comes with Sun's JDK.

gjarsigner

is a Java ARchive (JAR) file signing and verification tool.

gjavah

generates header files from Java class files.

gjdoc

is a documentation tool similar to javadoc.

gkeytool

manages private keys and public certificates in a Java environment.

gnative2ascii

is an encoding converter for Java.

gorbd

is an object request broker daemon.

grmic

generates stubs for Remote Method Invocation.

grmid

RMI activation system daemon.

grmiregistry

starts a remote object registry on the current host.

gserialver

prints the serialVersionUID of the specified class.

gtnameserv

starts a naming service.

jcf-dump

prints information about Java class files.

jv-convert

converts files from one encoding to another.

rebuild-gcj-db

Merge the per-solib databases made by aot-compile into one system-wide database.

Last updated on 2014-09-20 17:45:42 -0700