Skip to content

OMIT_MEMLOCK build broken #384

@tbvdm

Description

@tbvdm

Building with -DOMIT_MEMLOCK fails on OpenBSD:

$ sed -i -e 's/\([A-Z_]*CFLAGS\)+="/\1="$\1/' configure
$ ./configure --enable-tempstore=yes --disable-editline --disable-tcl CFLAGS='-DSQLITE_HAS_CODEC -DOMIT_MEMLOCK'
[...]
$ make
[...]
./libtool --mode=compile --tag=CC gcc -DSQLITE_HAS_CODEC -DOMIT_MEMLOCK -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/home/tim/src/3rd/sqlcipher/src -I/home/tim/src/3rd/sqlcipher/ext/rtree -I/home/tim/src/3rd/sqlcipher/ext/icu -I/home/tim/src/3rd/sqlcipher/ext/fts3 -I/home/tim/src/3rd/sqlcipher/ext/async -I/home/tim/src/3rd/sqlcipher/ext/session -I/home/tim/src/3rd/sqlcipher/ext/userauth -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG  -DSQLITE_THREADSAFE=1   -DSQLITE_HAVE_ZLIB=1  -DSQLITE_TEMP_STORE=2 -c sqlite3.c
libtool: compile:  gcc -DSQLITE_HAS_CODEC -DOMIT_MEMLOCK -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/home/tim/src/3rd/sqlcipher/src -I/home/tim/src/3rd/sqlcipher/ext/rtree -I/home/tim/src/3rd/sqlcipher/ext/icu -I/home/tim/src/3rd/sqlcipher/ext/fts3 -I/home/tim/src/3rd/sqlcipher/ext/async -I/home/tim/src/3rd/sqlcipher/ext/session -I/home/tim/src/3rd/sqlcipher/ext/userauth -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_HAVE_ZLIB=1 -DSQLITE_TEMP_STORE=2 -c sqlite3.c  -fPIC -DPIC -o .libs/sqlite3.o
sqlite3.c:39210: error: 'close' undeclared here (not in a function)
sqlite3.c:39213: error: 'access' undeclared here (not in a function)
sqlite3.c:39216: error: 'getcwd' undeclared here (not in a function)
sqlite3.c:39242: error: 'read' undeclared here (not in a function)
sqlite3.c:39246: error: 'pread' undeclared here (not in a function)
sqlite3.c:39259: error: 'write' undeclared here (not in a function)
sqlite3.c:39263: error: 'pwrite' undeclared here (not in a function)
sqlite3.c:39288: error: 'unlink' undeclared here (not in a function)
sqlite3.c:39297: error: 'rmdir' undeclared here (not in a function)
sqlite3.c:39301: error: 'fchown' undeclared here (not in a function)
sqlite3.c:39308: error: 'geteuid' undeclared here (not in a function)
sqlite3.c:39315: error: 'mmap' undeclared here (not in a function)
sqlite3.c:39322: error: 'munmap' undeclared here (not in a function)
sqlite3.c:39343: error: 'readlink' undeclared here (not in a function)
sqlite3.c: In function 'unixShmMap':
sqlite3.c:43604: error: 'PROT_READ' undeclared (first use in this function)
sqlite3.c:43604: error: (Each undeclared identifier is reported only once
sqlite3.c:43604: error: for each function it appears in.)
sqlite3.c:43604: error: 'PROT_WRITE' undeclared (first use in this function)
sqlite3.c:43604: error: invalid operands to binary |
sqlite3.c:43605: error: 'MAP_SHARED' undeclared (first use in this function)
sqlite3.c:43606: warning: passing argument 3 of '(void * (*)(void *, size_t,  int,  int,  int,  off_t))aSyscall[22].pCurrent' makes integer from pointer without a cast
sqlite3.c:43606: warning: passing argument 4 of '(void * (*)(void *, size_t,  int,  int,  int,  off_t))aSyscall[22].pCurrent' makes integer from pointer without a cast
sqlite3.c:43607: error: 'MAP_FAILED' undeclared (first use in this function)
sqlite3.c: In function 'unixOpen':
sqlite3.c:44963: error: 'F_OK' undeclared (first use in this function)
sqlite3.c:44963: warning: passing argument 2 of '(int (*)(const char *, int))aSyscall[2].pCurrent' makes integer from pointer without a cast
sqlite3.c: In function 'unixAccess':
sqlite3.c:45168: error: 'W_OK' undeclared (first use in this function)
sqlite3.c:45168: error: 'R_OK' undeclared (first use in this function)
sqlite3.c:45168: error: invalid operands to binary |
sqlite3.c:45168: warning: passing argument 2 of '(int (*)(const char *, int))aSyscall[2].pCurrent' makes integer from pointer without a cast
*** Error 1 in /home/tim/src/3rd/sqlcipher (Makefile:801 'sqlite3.lo')

(The sed command above is a workaround for #382.)

The problem is that mksqlite3c.tcl removes duplicate header inclusions when it generates the amalgamated sqlite3.c. Both crypto_impl.c and os_unix.c include <unistd.h> and <sys/mman.h>, but the ones from crypto_impl.c are hidden behind #ifndef OMIT_MEMLOCK and the ones from os_unix.c are commented away by mksqlite3c.tcl.

I believe the proper way to fix this is to annotate the inclusions in crypto_impl.c with /* amalgamator: dontcache */. The following diff fixes the issue for me:

diff --git a/src/crypto_impl.c b/src/crypto_impl.c
index c7214ed..0baff69 100644
--- a/src/crypto_impl.c
+++ b/src/crypto_impl.c
@@ -35,10 +35,10 @@
 #include "crypto.h"
 #ifndef OMIT_MEMLOCK
 #if defined(__unix__) || defined(__APPLE__) || defined(_AIX)
-#include <errno.h>
-#include <unistd.h>
-#include <sys/resource.h>
-#include <sys/mman.h>
+#include <errno.h> /* amalgamator: dontcache */
+#include <unistd.h> /* amalgamator: dontcache */
+#include <sys/resource.h> /* amalgamator: dontcache */
+#include <sys/mman.h> /* amalgamator: dontcache */
 #elif defined(_WIN32)
 #include <windows.h>
 #endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions