README.txt: add note about compiler-rt BlocksRuntime directory changes
[blocksruntime.git] / README.txt
blob785677d05f51c8ce846fab2a1c55786f7769b047
2 Blocks Runtime
3 ==============
5 This project provides a convenient way to install the BlocksRuntime library
6 from the compiler-rt project (see <http://compiler-rt.llvm.org/>).
8 Several systems (Linux, FreeBSD, MacPorts, etc.) provide the clang compiler
9 either preinstalled or as an available package which has Blocks support
10 (provided the `-fblocks` compiler option is used).
12 Unfortunately, those installer packages do not provide the Blocks runtime
13 library.
15 On the other hand, the compiler-rt library can be downloaded and does contain
16 the Blocks runtime support if properly enabled in the cmake build file.
18 By default, however, the compiler-rt library also builds a compiler runtime
19 support library which is undesirable.
21 This project contains only the BlocksRuntime files (in the `BlocksRuntime`
22 subdirectory) along with tests (in the `BlocksRuntime/tests` subdirectory) and
23 the original `CREDITS.TXT`, `LICENSE.TXT` and `README.txt` from the top-level
24 `compiler-rt` project (which have been placed in the `BlocksRuntime`
25 subdirectory).  Note that in 2014-02 the compiler-rt project moved the
26 BlocksRuntime sources from the `BlocksRuntime` directory to the
27 `lib/BlocksRuntime` directory and moved the tests from the `BlocksRuntime/tests`
28 directory to the `test/BlocksRuntime` directory.  The files themselves, however,
29 remain unchanged and are still the same as they were in 2010-08.
31 This runtime can also be used with the `gcc-apple-4.2` compiler built using the
32 MacPorts.org apple-gcc42 package on Mac OS X.
36 License
37 -------
39 The compiler-rt project (and hence the BlocksRuntime since it's a part of that
40 project) has a very liberal dual-license of either the UIUC or MIT license.
41 The MIT license is fully GPL compatible (and pretty much compatible with just
42 about everything), so there should be no problems linking the
43 `libBlocksRuntime.a` library with your executable.  (Note that on the FSF's site
44 <http://www.gnu.org/licenses/license-list.html>, you find the MIT license under
45 the 'X11 License' section.)  See the `LICENSE.TXT` file in the `BlocksRuntime`
46 subdirectory for all the details.
50 Building
51 --------
53 Since there are only two files to build, a makefile didn't seem warranted.  A
54 special `config.h` file has been created to make the build work.  Build the
55 `libBlocksRuntime.a` library by running:
57         ./buildlib
59 The `gcc` compiler will be used by default, but you can do `CC=clang ./buildlib`
60 for example to use the `clang` compiler instead.  Note that neither `make` nor
61 `cmake` are needed (but `ar` and `ranlib` will be used but they can also be
62 changed with the `AR` and `RANLIB` environment variables similarly to the way
63 the compiler can be changed).
65 **IMPORTANT** Mac OS X Note:  If you are building this library on Mac OS X
66 (presumably to use with a `clang` or `gcc-apple-4.2` built with MacPorts or
67 otherwise obtained), you probably want a fat library with multiple architectures
68 in it.  You can do that with the `CFLAGS` variable like so:
70         CFLAGS='-O2 -arch x86_64 -arch ppc64 -arch i386 -arch ppc' ./buildlib
72 The `buildlib-osx` script will attempt to make an intelligent guess about
73 building an OS X library and then run `buildlib`.  If you're using Mac OS X you
74 can do this to build a FAT OS X library:
76         ./buildlib-osx
80 Testing
81 -------
83 Skip this step at your peril!  It's really quite painless.  You see it's
84 possible that the underlying blocks ABI between the blocks runtime files
85 provided in this project and the blocks ABI used by your version of the clang
86 compiler to implement the `-fblocks` option have diverged in an incompatible
87 way.  If this has happened, at least some of the tests should fail in
88 spectacular ways (i.e. bus faults).  For that reason skipping this step is not
89 recommended.
91 You must have the clang compiler with `-fblocks` support installed for this step
92 (if you don't have a clang compiler with `-fblocks` support available, why
93 bother installing the Blocks runtime in the first place?)  
94 Run the tests like so:
96         ./checktests
98 By default `checktests` expects the `clang` compiler to be available in the
99 `PATH` and named `clang`.  If you are using `gcc-apple-4.2` or your `clang` is
100 named something different (such as `clang-mp-2.9` or `clang-mp-3.0`) run the
101 tests like this instead (replacing `clang-mp-3.0` with your compiler's name):
103         CC=clang-mp-3.0 ./checktests
105 Problems are indicated with a line that starts `not ok`.  You will see a few
106 of these.  The ones that are marked with `# TODO` are expected to fail for the
107 reason shown.  The `copy-block-literal-rdar6439600.c` expected failure is a real
108 failure.  No it's not a bug in the Blocks runtime library, it's actually a bug
109 in the compiler.  You may want to examine the `copy-block-literal-rdar6439600.c`
110 source file to make sure you fully grok the failure so you can avoid getting
111 burned by it in your code.  There may be a fix in the clang project by now (but
112 as of the clang 3.2 release it still seems to fail), however it may be a while
113 until it rolls downhill to your clang package.
115 If you are using `CC=gcc-apple-4.2`, you will probably get two additional expect
116 failure compiler bugs in the `cast.c` and `josh.C` tests.  These extra failures
117 are not failures in the blocks runtime itself, just `gcc` not accepting some
118 source files that `clang` accepts.  You can still use the `libBlocksRuntime.a`
119 library just fine.
121 Note that if you have an earlier version of `clang` (anything before version 2.8
122 see `clang -v`) then `clang++` (C++ support) is either incomplete or missing and
123 the few C++ tests (`.C` extension) will be automatically skipped (if `clang++`
124 is missing) or possibly fail in odd ways (if `clang++` is present but older than
125 version 2.8).
127 Note that the `./checktests` output is TAP (Test Anything Protocol) compliant
128 and can therefore be run with Perl's prove utility like so:
130         prove -v checktests
132 Optionally first setting `CC` like so:
134         CC=gcc-apple-4.2 prove -v checktests
136 Omit the `-v` option for more succinct output.
140 ARM Hard Float Bug
141 ------------------
143 When running on a system that uses the ARM hard float ABI (e.g. RaspberryPi),
144 the clang compiler has a bug.  When passing float arguments to a vararg function
145 they must also be passed on the stack, not just in hardware floating point
146 registers.  The clang compiler does this correctly for normal vararg functions,
147 but fails to do this for block vararg functions.
149 If you really need this, a workaround is to call a normal vararg function that
150 takes a block and `...` arguments.  It can then package up the `...` arguments
151 into a `va_list` and then call the block it was passed as an argument passing
152 the block the `va_list`.  This works fine and avoids the `clang` bug even
153 though it's fugly.
155 The `checktests` script marks this test (`variadic.c`) as expect fail when
156 running the tests on an ARM hard float ABI system if it's able to detect that
157 the ARM hard float ABI is in use.
161 clang -fblocks failure
162 ----------------------
164 If clang is not using the integrated assembler (option `-integrated-as`) then it
165 will incorrectly pass options such as `-fblocks` down to the assembler which
166 will probably not like it.  One example of an error caused by this bug is:
168         gcc: error: unrecognized command line option '-fblocks'
170 In this case clang is not using the integrated assembler (which is not supported
171 on all platforms) and passes the `-fblocks` option down to the gcc assembler
172 which does not like that option at all.
174 The following references talk about this:
176 - <http://thread.gmane.org/gmane.comp.compilers.llvm.devel/56563>
177 - <http://llvm.org/bugs/show_bug.cgi?id=12920>
179 The ugly workaround for this problem is to compile the sources using both the
180 `-S` and `-fblocks` options to produce a `.s` file which can then be compiled
181 into whatever is desired without needing to use the `-fblocks` option.
183 If `checktests` detects this situation it will emit a line similar to this:
185         WARNING: -S required for -fblocks with clang
187 If this is the case, then rules to compile `.c` into `.s` and then compile `.s`
188 into `.o` (or whatever) will be needed instead of the usual compile `.c` into
189 `.o` (or whatever).
191 Note that this workaround is required to use `-fblocks` with the version of
192 clang included with cygwin.
196 Installing
197 ----------
199 Assuming that you have built the library (with `./buildlib`) and are satisfied
200 it works (`./checktests`) then it can be installed with:
202         sudo ./installlib
204 The default installation `prefix` is `/usr/local`, but can be changed to
205 `/myprefix` like so:
207         sudo env prefix=/myprefix ./installlib
209 The include file (`Block.h`) is installed into `$prefix/include` and the library
210 (`libBlocksRuntime.a`) into `$prefix/lib` by default.  (Those can also be
211 changed by setting and exporting `includedir` and/or `libdir` in the same way
212 `prefix` can be changed.)
214 If you want to see what will be installed without actually installing use:
216         ./installlib --dry-run
218 Note that `DESTDIR` is supported by the `installlib` script if that's needed.
219 Just set `DESTDIR` before running `installlib` the same way `prefix` can be set.
223 Sample Code
224 -----------
226 After you have installed the Blocks runtime header and library, you can check
227 to make sure everything's working by building the `sample.c` file.  The
228 instructions are at the top of the file (use `head sample.c` to see them) or
229 just do this (replace `clang` with the name of the compiler you're using):
231         clang -o sample -fblocks sample.c -lBlocksRuntime && ./sample
233 If the above line outputs `Hello world 2` then your Blocks runtime support is
234 correctly installed and fully usable.  Have fun!
236 Note that if you have the problem described above in the section named
237 "clang -fblocks failure", then you'll need to do this instead:
239         clang -S -o sample.s -fblocks sample.c && \
240         clang -o sample sample.s -lBlocksRuntime && ./sample
242 Note that it's possible to use the Blocks runtime without installing it into
243 the system directories.  You simply need to add an appropriate `-I` option to
244 find the `Block.h` header when you compile your source(s).  And a `-L` option to
245 find the `libBlocksRuntime.a` library when you link your executable.  Since
246 `libBlocksRuntime.a` is a static library no special system support will be
247 needed to run the resulting executable.
251 Glibc Problem
252 -------------
254 The `unistd.h` header from older versions of `glibc` has an incompatibility with
255 the `-fblocks` option.  See <http://mackyle.github.io/blocksruntime/#glibc> for
256 a workaround.
258 This problem was corrected with commit 84ae135d3282dc362bed0a5c9a575319ef336884
259 (<http://repo.or.cz/w/glibc.git/commit/84ae135d>) on 2013-11-21 and first
260 appears in `glibc-2.19` released on 2014-02-07.  Since `ldd` is part of `glibc`
261 you can check to see what version of `glibc` you have with:
263         ldd --version
267 Documentation
268 -------------
270 You can find information on the Blocks language extension at these URLs
272 - <http://clang.llvm.org/docs/LanguageExtensions.html#blocks>
273 - <http://clang.llvm.org/docs/BlockLanguageSpec.html>
274 - <http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Blocks>
275 - <http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Blocks/Blocks.pdf>