@@ -1,3 +1,26 @@
+2014-10-21 David Malcolm <dmalcolm@redhat.com>
+
+ * docs/intro/install.rst ("Installation via packages"): Drop
+ this section.
+ ("Installation from source"): Drop this section, moving parts
+ of it to https://gcc.gnu.org/wiki/JIT and some others to
+ docs/internals/index.rst.
+ ("Hello world"): This section becomes the only remaining part
+ of this file. Eliminate references to pkg-config.
+
+ * docs/internals/index.rst
+ ("Using a working copy without installing every time"): Rewrite
+ as...
+ ("Working on the JIT library"): ...new section, aimed at
+ contributors (and myself) working from a build directory,
+ eliminating references to installation. Add description
+ of pertinent configuration options.
+ ("Running the test suite"): Add setting of LIBRARY_PATH to
+ description of how to run a built binary outside of the test
+ suite.
+ ("Environment variables"): New section, describing pertinent
+ environment variables.
+
2014-10-20 David Malcolm <dmalcolm@redhat.com>
* jit-recording.c (gcc::jit::dump::dump): Handle fopen failures
@@ -18,20 +18,10 @@
Internals
=========
-Using a working copy without installing every time
---------------------------------------------------
-When directly working on the library you can avoid needing to install to
-test every change.
-
-You need to do a ``make install`` of the ``gcc`` subdirectory to install
-the driver binary (the top-level ``gcc`` binary). This is used internally
-by the library for converting from .s assembler files to .so shared
-libraries. Specifically, it looks for an executable on the ``$PATH`` with
-a name expanded by the ``configure`` script from
-``${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}``,
-such as ``x86_64-unknown-linux-gnu-gcc-5.0.0``.
-
-For example, if you configured with a prefix of ``$PREFIX`` like this:
+Working on the JIT library
+--------------------------
+Having checked out the source code (to "src"), you can configure and build
+the JIT library like this:
.. code-block:: bash
@@ -45,39 +35,44 @@ For example, if you configured with a prefix of ``$PREFIX`` like this:
--disable-bootstrap \
--enable-checking=release \
--prefix=$PREFIX
+ nice make -j4 # altering the "4" to however many cores you have
-then you can install (once) to ensure that ``$PREFIX/bin/`` is populated:
+This should build a libgccjit.so within jit/build/gcc:
.. code-block:: console
- [build]$ ll ../install/bin/*gcc*
- -rwxr-xr-x. 3 david david 2733458 Oct 6 14:25 ../install/bin/gcc
- -rwxr-xr-x. 2 david david 136921 Oct 6 14:25 ../install/bin/gcc-ar
- -rwxr-xr-x. 2 david david 136857 Oct 6 14:25 ../install/bin/gcc-nm
- -rwxr-xr-x. 2 david david 136869 Oct 6 14:25 ../install/bin/gcc-ranlib
- -rwxr-xr-x. 3 david david 2733458 Oct 6 14:25 ../install/bin/x86_64-unknown-linux-gnu-gcc
- -rwxr-xr-x. 3 david david 2733458 Oct 6 14:25 ../install/bin/x86_64-unknown-linux-gnu-gcc-5.0.0
- -rwxr-xr-x. 2 david david 136921 Oct 6 14:25 ../install/bin/x86_64-unknown-linux-gnu-gcc-ar
- -rwxr-xr-x. 2 david david 136857 Oct 6 14:25 ../install/bin/x86_64-unknown-linux-gnu-gcc-nm
- -rwxr-xr-x. 2 david david 136869 Oct 6 14:25 ../install/bin/x86_64-unknown-linux-gnu-gcc-ranlib
+ [build] $ file gcc/libgccjit.so*
+ gcc/libgccjit.so: symbolic link to `libgccjit.so.0'
+ gcc/libgccjit.so.0: symbolic link to `libgccjit.so.0.0.1'
+ gcc/libgccjit.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped
-Note the presence above of ``../install/bin/x86_64-unknown-linux-gnu-gcc``.
+Here's what those configuration options mean:
-When building code using the API you need to ensure that ``-I`` points to
-the directory containing ``libgccjit.h`` and ``-L`` points to the
-directory containing the built library.
+.. option:: --enable-host-shared
-When running binaries (or debugging them), you'll need to manually set
-``LD_LIBRARY_PATH`` to the directory containing ``libgccjit.so``, and
-``PATH`` needs to contain the path to the installed binaries.
+ Configuring with this option means that the compiler is built as
+ position-independent code, which incurs a slight performance hit,
+ but it necessary for a shared library.
-and then you can run from a built (but not installed) copy:
+.. option:: --enable-languages=jit
-.. code-block:: console
+ This specifies which frontends to build. The JIT library looks like
+ a frontend to the rest of the code.
+
+.. option:: --disable-bootstrap
+
+ For hacking on the "jit" subdirectory, performing a full
+ bootstrap can be overkill, since it's unused by a bootstrap. However,
+ when submitting patches, you should remove this option, to ensure that
+ the compiler can still bootstrap itself.
- [gcc]$ PATH=../../install/bin:$PATH LD_LIBRARY_PATH=. ./testsuite/jit/test-factorial.exe
+.. option:: --enable-checking=release
-without needing to reinstall everything for every tweak to the library.
+ The compile can perform extensive self-checking as it runs, useful when
+ debugging, but slowing things down.
+
+ For maximum speed, configure with ``--enable-checking=release`` to
+ disable this self-checking.
Running the test suite
----------------------
@@ -117,11 +112,75 @@ and once a test has been compiled, you can debug it directly:
.. code-block:: console
- [gcc] $ PATH=../../install/bin:$PATH \
+ [gcc] $ PATH=.:$PATH \
LD_LIBRARY_PATH=. \
+ LIBRARY_PATH=. \
gdb --args \
testsuite/jit/test-factorial.exe
+Environment variables
+---------------------
+When running client code against a locally-built libgccjit, three
+environment variables need to be set up:
+
+.. envvar:: LD_LIBRARY_PATH
+
+ `libgccjit.so` is dynamically linked into client code, so if running
+ against a locally-built library, ``LD_LIBRARY_PATH`` needs to be set
+ up appropriately. The library can be found within the "gcc"
+ subdirectory of the build tree:
+
+ .. code-block:: console
+
+ $ file libgccjit.so*
+ libgccjit.so: symbolic link to `libgccjit.so.0'
+ libgccjit.so.0: symbolic link to `libgccjit.so.0.0.1'
+ libgccjit.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, not stripped
+
+.. envvar:: PATH
+
+ The library uses a driver executable for converting from .s assembler
+ files to .so shared libraries. Specifically, it looks for a name
+ expanded from
+ ``${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}``
+ such as ``x86_64-unknown-linux-gnu-gcc-5.0.0``.
+
+ Hence ``PATH`` needs to include a directory where the library can
+ locate this executable.
+
+ The executable is normally installed to the installation bindir
+ (e.g. /usr/bin), but a copy is also created within the "gcc"
+ subdirectory of the build tree for running the testsuite, and for ease
+ of development.
+
+.. envvar:: LIBRARY_PATH
+
+ The driver executable invokes the linker, and the latter needs to locate
+ support libraries needed by the generated code, or you will see errors
+ like:
+
+ .. code-block:: console
+
+ ld: cannot find crtbeginS.o: No such file or directory
+ ld: cannot find -lgcc
+ ld: cannot find -lgcc_s
+
+ Hence if running directly from a locally-built copy (without installing),
+ ``LIBRARY_PATH`` needs to contain the "gcc" subdirectory of the build
+ tree.
+
+For example, to run a binary that uses the library against a non-installed
+build of the library in LIBGCCJIT_BUILD_DIR you need an invocation of the
+client code like this, to preprend the dir to each of the environment
+variables:
+
+.. code-block:: console
+
+ $ LD_LIBRARY_PATH=$(LIBGCCJIT_BUILD_DIR):$(LD_LIBRARY_PATH) \
+ PATH=$(LIBGCCJIT_BUILD_DIR):$(PATH) \
+ LIBRARY_PATH=$(LIBGCCJIT_BUILD_DIR):$(LIBRARY_PATH) \
+ ./jit-hello-world
+ hello world
Overview of code structure
--------------------------
@@ -17,153 +17,25 @@
.. default-domain:: c
-Getting Started
----------------
+Getting Started: "Hello world"
+==============================
-Installation via packages
-=========================
-
-It's easiest to use pre-built packages of the library.
-
-Fedora and RHEL
-***************
-RPM packages of libgccjit (and its Python 2 and 3 bindings) are
-available for Fedora and RHEL, for i386 and x86_64.
-
-These currently should be treated as experimental.
-
-See https://copr.fedoraproject.org/coprs/dmalcolm/libgccjit/
-for information on subscribing to the appropriate repository for
-your system. Having done this,
-
-.. code-block:: bash
-
- sudo yum install libgccjit-devel
-
-should give you both the JIT library (`libgccjit`) and the header files
-needed to develop against it (`libgccjit-devel`):
-
-.. code-block:: console
-
- $ rpm -qlv libgccjit
- lrwxrwxrwx 1 root root 18 Aug 12 07:56 /usr/lib64/libgccjit.so.0 -> libgccjit.so.0.0.1
- -rwxr-xr-x 1 root root 14463448 Aug 12 07:57 /usr/lib64/libgccjit.so.0.0.1
-
- $ rpm -qlv libgccjit-devel
- -rwxr-xr-x 1 root root 37654 Aug 12 07:56 /usr/include/libgccjit++.h
- -rwxr-xr-x 1 root root 28967 Aug 12 07:56 /usr/include/libgccjit.h
- lrwxrwxrwx 1 root root 14 Aug 12 07:56 /usr/lib64/libgccjit.so -> libgccjit.so.0
-
-
-Other distributions
-*******************
-
-Prebuilt packages for other distributions would be most welcome; please
-contact the `jit mailing list`_.
-
-
-Installation from source
-========================
-If pre-built packages are not available, you can built the library from
-source. Doing so currently requires about 4.2G of drive space (for
-the combination of the source tree, the build directory, and the
-installation path).
-
-The code can currently be seen within the git branch "dmalcolm/jit" here:
- http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/dmalcolm/jit
-
-The following will check out a copy of the appropriate branch, to the
-"jit/src" subdirectory:
-
-.. code-block:: bash
-
- mkdir jit
- cd jit
- git clone \
- -b dmalcolm/jit \
- git://gcc.gnu.org/git/gcc.git \
- src
-
-The source tree currently occupies about 2.8G of disk space.
-
-To build it (within the "jit/build" subdirectory, installing to
-"jit/install"):
-
-.. code-block:: bash
-
- mkdir build
- mkdir install
- PREFIX=$(pwd)/install
- cd build
- ../src/configure \
- --enable-host-shared \
- --enable-languages=jit \
- --disable-bootstrap \
- --enable-checking=release \
- --prefix=$PREFIX
- nice make -j4 # altering the "4" to however many cores you have
-
-On my 4-core laptop this takes 17 minutes and 1.1G of disk space
-(it's much faster with many cores and a corresponding -j setting).
-
-This should build a libgccjit.so within jit/build/gcc:
-
-.. code-block:: console
-
- [build] $ file gcc/libgccjit.so*
- gcc/libgccjit.so: symbolic link to `libgccjit.so.0'
- gcc/libgccjit.so.0: symbolic link to `libgccjit.so.0.0.1'
- gcc/libgccjit.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped
-
-Note that this is a branch of GCC, so if it fails to build, you might want
-to consult the `general GCC FAQ <https://gcc.gnu.org/wiki/FAQ>`_ for some
-common issues, before checking on the `jit mailing list`_.
-
-.. _jit mailing list: https://gcc.gnu.org/ml/jit/
-
-You should then be able to install it (to the `--prefix` specified
-earlier) via:
-
-.. code-block:: bash
-
- make install
-
-On my laptop this uses a further 0.4G of disk space.
-
-You should be able to see the header files within the `include`
-subdirectory of the installation prefix:
-
-.. code-block:: console
-
- $ find $PREFIX/include
- /home/david/gcc-jit/install/include
- /home/david/gcc-jit/install/include/libgccjit.h
- /home/david/gcc-jit/install/include/libgccjit++.h
-
-and the library within the `lib` subdirectory:
-
-.. code-block:: console
-
- $ find $PREFIX/lib/libgccjit.*
- /home/david/gcc-jit/install/lib/libgccjit.so
- /home/david/gcc-jit/install/lib/libgccjit.so.0
- /home/david/gcc-jit/install/lib/libgccjit.so.0.0.1
-
-
-"Hello world"
-=============
-
-Let's look at how to build and run programs that use the library.
+Before we look at the details of the API, let's look at building and
+running programs that use the library.
Here's a toy "hello world" program that uses the library to synthesize
-a call to `printf` and use it to write a message to stdout.
+a call to `printf` and uses it to write a message to stdout.
+
+Don't worry about the content of the program for now; we'll cover
+the details in later parts of this tutorial.
.. literalinclude:: ../examples/install-hello-world.c
:language: c
-Copy it to `jit-hello-world.c`.
+Copy the above to `jit-hello-world.c`.
-To build it with prebuilt packages, use:
+Assuming you have the jit library installed, build the test program
+using:
.. code-block:: console
@@ -172,56 +44,9 @@ To build it with prebuilt packages, use:
-o jit-hello-world \
-lgccjit
- # Run the built program:
- $ ./jit-hello-world
- hello world
-
-
-If building against an locally-built install (to `$PREFIX`), you can use
-`pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`_ to
-specify the compilation and linkage flags:
+You should then be able to run the built program:
.. code-block:: console
- $ export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
- $ gcc \
- jit-hello-world.c \
- -o jit-hello-world \
- $(pkg-config libgccjit --cflags --libs)
-
-This is equivalent to handcoding the include and library paths with `-I`
-and `-L` and specifying `-lgccjit` (i.e. linkage against libgccjit):
-
-.. code-block:: console
-
- $ gcc \
- jit-hello-world.c \
- -o jit-hello-world \
- -lgccjit \
- -I$PREFIX/include -L$PREFIX/lib
-
-When running the built test program against a locally-built tree, two
-environment variables need to be set up:
-
-* `LD_LIBRARY_PATH` needs to be set up appropriately so that the dynamic
- linker can locate the `libgccjit.so`
-
-* `PATH` needs to include the `bin` subdirectory below the installation
- prefix, so that the library can locate a driver binary. This is used
- internally by the library for converting from .s assembler files to
- .so shared libraries.
-
- ..
- Specifically, it looks for a name expanded from
- ``${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}`` on the
- ``$PATH``, such as ``x86_64-unknown-linux-gnu-gcc-5.0.0``).
-
-For example, if you configured with a prefix of ``$PREFIX`` like above,
-you need an invocation like this:
-
-.. code-block:: console
-
- $ LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH \
- PATH=$PREFIX/bin:$PATH \
- ./jit-hello-world
+ $ ./jit-hello-world
hello world