Skip to content

Commit

Permalink
Remove zlib dependency (#799)
Browse files Browse the repository at this point in the history
Remove support for directly reading gzip compressed ELF files. This means we can remove the dependency on zlib which simplifies compilation. (Note this dependency affects the *users* of Sail, not the Sail compiler itself.)
  • Loading branch information
Timmmm authored Nov 27, 2024
1 parent 2825040 commit 34a62cf
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: System dependencies (macOS)
if: startsWith(matrix.os, 'macOS')
run: |
brew install --force --overwrite gpatch gmp z3 pkg-config lzlib zlib opam
brew install --force --overwrite gpatch gmp z3 pkg-config opam
- name: Restore cached opam
id: cache-opam-restore
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
dnf install --assumeyes \
gmp-devel \
pkg-config \
zlib-devel \
openssl \
curl \
git \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.nightly
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu

# Install apt deps
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates build-essential libgmp-dev z3 libz3-dev opam rsync pkg-config m4 zlib1g-dev
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates build-essential libgmp-dev z3 libz3-dev opam rsync pkg-config m4

# Configure opam
RUN opam init -y --no-setup --compiler=5.2.0 --shell=sh --disable-sandboxing
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ RUN apt-get update && \
libgmp-dev \
z3 \
pkg-config \
zlib1g-dev \
sudo && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ eval $(opam config env)
```
Install system dependencies, on Ubuntu (if using WSL see the note below):
```
sudo apt-get install build-essential libgmp-dev z3 pkg-config zlib1g-dev
sudo apt-get install build-essential libgmp-dev z3 pkg-config
```
or [MacOS homebrew](https://brew.sh/):
```
Expand Down
2 changes: 1 addition & 1 deletion doc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian

RUN apt-get update && apt-get install -y --no-install-recommends build-essential git ruby ruby-rubygems opam z3 rsync libgmp-dev pkg-config zlib1g-dev texlive-latex-base texlive-pictures poppler-utils
RUN apt-get update && apt-get install -y --no-install-recommends build-essential git ruby ruby-rubygems opam z3 rsync libgmp-dev pkg-config texlive-latex-base texlive-pictures poppler-utils

RUN gem install asciidoctor asciidoctor-pdf asciidoctor-bibtex asciidoctor-sail rouge

Expand Down
4 changes: 2 additions & 2 deletions doc/asciidoc/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ this needs to be compiled and linked with the C files in the
`$SAIL_DIR/lib` directory:
[source,sh]
----
gcc out.c $SAIL_DIR/lib/*.c -lgmp -lz -I $SAIL_DIR/lib/ -o out
gcc out.c $SAIL_DIR/lib/*.c -lgmp -I $SAIL_DIR/lib/ -o out
----
The C output requires the https://gmplib.org/[GMP library] for arbitrary precision
arithmetic, as well as https://zlib.net/[zlib] for working with compressed ELF binaries.
arithmetic.

There are several Sail options that affect the C output:

Expand Down
10 changes: 5 additions & 5 deletions doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -3112,12 +3112,12 @@ <h3 id="_c_compilation">C compilation</h3>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="sh">gcc out.c <span class="nv">$SAIL_DIR</span>/lib/<span class="k">*</span>.c <span class="nt">-lgmp</span> <span class="nt">-lz</span> <span class="nt">-I</span> <span class="nv">$SAIL_DIR</span>/lib/ <span class="nt">-o</span> out</code></pre>
<pre class="rouge highlight"><code data-lang="sh">gcc out.c <span class="nv">$SAIL_DIR</span>/lib/<span class="k">*</span>.c <span class="nt">-lgmp</span> <span class="nt">-I</span> <span class="nv">$SAIL_DIR</span>/lib/ <span class="nt">-o</span> out</code></pre>
</div>
</div>
<div class="paragraph">
<p>The C output requires the <a href="https://gmplib.org/">GMP library</a> for arbitrary precision
arithmetic, as well as <a href="https://zlib.net/">zlib</a> for working with compressed ELF binaries.</p>
arithmetic.</p>
</div>
<div class="paragraph">
<p>There are several Sail options that affect the C output:</p>
Expand Down Expand Up @@ -4958,7 +4958,7 @@ <h4 id="_automatic_wildcard_insertion">Automatic wildcard insertion</h4>
<pre class="rouge highlight"><code>Warning: Required literal ../examples/cannot_wildcard.sail:17.14-17:
17 | (Some(0b1), _) =&gt; print_endline("3"),
| ^-^
|
|
Sail cannot simplify the above pattern match:
This bitvector pattern literal must be kept, as it is required for Sail to show that the surrounding pattern match is complete.
When translated into prover targets (e.g. Lem, Coq) without native bitvector patterns, they may be unable to verify that the match covers all possible cases.</code></pre>
Expand Down Expand Up @@ -5957,7 +5957,7 @@ <h3 id="_modules">Modules</h3>
6 | let x = alfa();
| ^--^
| Not in scope
|
|
| Try requiring module A to bring the following into scope for module B:
| ../examples/amod.sail:6.4-8:
| 6 |val alfa : unit -&gt; int
Expand Down Expand Up @@ -6681,4 +6681,4 @@ <h2 id="_references">References</h2>
</div>
</div>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions doc/old/usage.tex
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ \subsection{C compilation}
this needs to be compiled and linked with the C files in the
\verb+sail/lib+ directory:
\begin{verbatim}
gcc out.c $SAIL_DIR/lib/*.c -lgmp -lz -I $SAIL_DIR/lib/ -o out
gcc out.c $SAIL_DIR/lib/*.c -lgmp -I $SAIL_DIR/lib/ -o out
\end{verbatim}
The C output requires the GMP library for arbitrary precision
arithmetic, as well as zlib for working with compressed ELF binaries.
arithmetic.
There are several Sail options that affect the C output:
\begin{itemize}
Expand Down
1 change: 0 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ http://www.cl.cam.ac.uk/~pes20/sail/.
(lem (>= "2018-12-14"))
(linksem (>= "0.3"))
conf-gmp
conf-zlib
(yojson (>= 1.6.0))
(pprint (>= 20220103))))

Expand Down
17 changes: 8 additions & 9 deletions lib/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
#include "rts.h"
#include "sail.h"

// Use the zlib library to uncompress ELF.gz files
#include <zlib.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -434,17 +431,18 @@ void load_elf(char *filename, bool *is32bit_p, uint64_t *entry) {
int size = 0;
int chunk = (1<<24); // increments output buffer this much
int read = 0;
gzFile in = gzopen(filename, "rb");
FILE* in = fopen(filename, "rb");
if (in == NULL) { goto fail; }
while (!gzeof(in)) {
while (!feof(in)) {
size = read + chunk;
buffer = (char*)realloc(buffer, size);
if (buffer == NULL) { goto fail; }

int s = gzread(in, buffer+read, size - read);
int s = fread(buffer+read, 1, size - read, in);
if (s < 0) { goto fail; }
read += s;
}
fclose(in);
loadELFHdr(buffer, read, is32bit_p, entry);
free(buffer);
return;
Expand Down Expand Up @@ -587,17 +585,18 @@ int lookup_sym(const char *filename, const char *symname, uint64_t *value) {
int chunk = (1<<24); // increments output buffer this much
int read = 0;
int ret = 0;
gzFile in = gzopen(filename, "rb");
FILE* in = fopen(filename, "rb");
if (in == NULL) { goto fail; }
while (!gzeof(in)) {
while (!feof(in)) {
size = read + chunk;
buffer = (char*)realloc(buffer, size);
if (buffer == NULL) { goto fail; }

int s = gzread(in, buffer+read, size - read);
int s = fread(buffer+read, 1, size - read, in);
if (s < 0) { goto fail; }
read += s;
}
fclose(in);
ret = lookupSymbol(buffer, read, symname, value);
free(buffer);
return ret;
Expand Down
1 change: 0 additions & 1 deletion libsail.opam
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ depends: [
"lem" {>= "2018-12-14"}
"linksem" {>= "0.3"}
"conf-gmp"
"conf-zlib"
"yojson" {>= "1.6.0"}
"pprint" {>= "20220103"}
"odoc" {with-doc}
Expand Down
3 changes: 1 addition & 2 deletions test/builtins/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_c_builtins(name, sail_opts):
tests[filename] = os.fork()
if tests[filename] == 0:
step('{} -no_warn -c {} {} 1> {}.c'.format(sail, sail_opts, filename, basename))
step('gcc {}.c {}/lib/*.c -lgmp -lz -I {}/lib -o {}'.format(basename, sail_dir, sail_dir, basename))
step('gcc {}.c {}/lib/*.c -lgmp -I {}/lib -o {}'.format(basename, sail_dir, sail_dir, basename))
step('./{}'.format(basename))
step('rm {}.c'.format(basename))
step('rm {}'.format(basename))
Expand Down Expand Up @@ -171,4 +171,3 @@ def test_isla_builtins(name):
output = open('tests.xml', 'w')
output.write(xml)
output.close()

4 changes: 2 additions & 2 deletions test/c/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_c(name, c_opts, sail_opts, valgrind, compiler='cc'):
tests[filename] = os.fork()
if tests[filename] == 0:
step('{} -no_warn -c {} {} 1> {}.c'.format(sail, sail_opts, filename, basename))
step('{} {} {}.c {}/lib/*.c -lgmp -lz -I {}/lib -o {}.bin'.format(compiler, c_opts, basename, sail_dir, sail_dir, basename))
step('{} {} {}.c {}/lib/*.c -lgmp -I {}/lib -o {}.bin'.format(compiler, c_opts, basename, sail_dir, sail_dir, basename))
step('./{}.bin > {}.result 2> {}.err_result'.format(basename, basename, basename), expected_status = 1 if basename.startswith('fail') else 0)
step('diff {}.result {}.expect'.format(basename, basename))
if os.path.exists('{}.err_expect'.format(basename)):
Expand All @@ -65,7 +65,7 @@ def test_c2(name, c_opts, sail_opts, valgrind):
tests[filename] = os.fork()
if tests[filename] == 0:
step('{} -no_warn -c2 {} {} -o {}'.format(sail, sail_opts, filename, basename))
step('gcc {} {}.c {}_emu.c {}/lib/*.c -lgmp -lz -I {}/lib -o {}'.format(c_opts, basename, basename, sail_dir, sail_dir, basename))
step('gcc {} {}.c {}_emu.c {}/lib/*.c -lgmp -I {}/lib -o {}'.format(c_opts, basename, basename, sail_dir, sail_dir, basename))
step('./{} > {}.result 2>&1'.format(basename, basename), expected_status = 1 if basename.startswith('fail') else 0)
step('diff {}.result {}.expect'.format(basename, basename))
if valgrind:
Expand Down
2 changes: 1 addition & 1 deletion test/float/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_float(name, sail_opts, compiler, c_opts):
tests[filename] = os.fork()
if tests[filename] == 0:
step('{} -no_warn -c {} {} 1> {}.c'.format(sail, sail_opts, filename, basename))
step('{} {} {}.c {}/lib/*.c -lgmp -lz -I {}/lib -o {}.bin'.format(compiler, c_opts, basename, sail_dir, sail_dir, basename))
step('{} {} {}.c {}/lib/*.c -lgmp -I {}/lib -o {}.bin'.format(compiler, c_opts, basename, sail_dir, sail_dir, basename))
step('./{}.bin > {}.result 2> {}.err_result'.format(basename, basename, basename), expected_status = 1 if basename.startswith('fail') else 0)

step('diff {}.err_result no_error && rm {}.err_result'.format(basename, basename))
Expand Down
2 changes: 1 addition & 1 deletion test/sailcov/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_sailcov():
tests[filename] = os.fork()
if tests[filename] == 0:
step('{} -no_warn -no_memo_z3 -c -c_include sail_coverage.h -c_coverage {}.branches {} -o {}'.format(sail, basename, filename, basename))
step('cc {}.c {}/lib/*.c {}/lib/coverage/libsail_coverage.a -lgmp -lz -lpthread -ldl -I {}/lib -o {}.bin'.format(basename, sail_dir, sail_dir, sail_dir, basename))
step('cc {}.c {}/lib/*.c {}/lib/coverage/libsail_coverage.a -lgmp -lpthread -ldl -I {}/lib -o {}.bin'.format(basename, sail_dir, sail_dir, sail_dir, basename))
step('./{}.bin -c {}.taken'.format(basename, basename))
step('{} --werror --all {}.branches --taken {}.taken {}'.format(sailcov, basename, basename, filename))
step('diff {}.html {}.expect'.format(basename, basename))
Expand Down

0 comments on commit 34a62cf

Please sign in to comment.