[MDEV-9314] fatal build error: viosslfactories.c:58:5: error: dereferencing pointer to incomplete type ‘DH {aka struct dh_st} Created: 2015-12-22  Updated: 2016-02-06  Resolved: 2016-02-06

Status: Closed
Project: MariaDB Server
Component/s: Compiling, SSL
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 5.5.48, 10.0.24, 10.1.12

Type: Bug Priority: Blocker
Reporter: pgnd Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: None
Environment:

lsb_release -rd
Description: openSUSE Leap 42.1 (x86_64)
Release: 42.1
gcc --version
gcc (SUSE Linux) 5.3.1 20151207 [gcc-5-branch revision 231355]


Sprint: 5.5.48-0

 Description   

building git 10.1-branch on linux64

git pull
git clean -xfd
git reset --hard HEAD
git branch -a
	* 10.1
	  remotes/origin/10.1
	  remotes/origin/HEAD -> origin/10.1
 
git log | head
	commit 27e6fd9a596847a1a4c618d16ed43f6885dfe73a
	Author: Sergey Vojtovich <svoj@mariadb.org>
	Date:   Tue Dec 22 14:51:26 2015 +0400
 
	    MDEV-9095 - [PATCH] systemd capability for --memlock
	    
	    Adjust systemd files to enable CAP_IPC_LOCK to allow rootless mlockall
	    (triggered by memlock option).
	    
	    This is amended version of a patch originally submitted by Daniel Black.
 
cmake ..  --debug-output -Wno-dev ...
	...
	-- Generating done
	-- Build files have been written to: /usr/local/src/mariadb/bld
make VERBOSE=1
	...
	[ 75%] Building C object vio/CMakeFiles/vio.dir/viosslfactories.c.o
	cd /usr/local/src/mariadb/bld/vio && /usr/bin/gcc-5  -DHAVE_CONFIG_H -DHAVE_OPENSSL -DHAVE_SYSTEMD -I/usr/local/src/mariadb/bld/include -I/usr/local/src/mariadb/include -I/usr/local/ssl/include  -fno-delete-null-pointer-checks -D_FORTIFY_SOURCE=2 -fmessage-length=0 -fstack-protector  -march=x86-64 -mtune=nocona -I/usr/local/include -pie -fPIC -Wl,-z,relro,-z,now -fstack-protector --param=ssp-buffer-size=4 -DWITH_INNODB_DISALLOW_WRITES -O3 -DNDEBUG -D_FORTIFY_SOURCE=2 -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1   -fPIC -o CMakeFiles/vio.dir/viosslfactories.c.o   -c /usr/local/src/mariadb/vio/viosslfactories.c
	/usr/local/src/mariadb/vio/viosslfactories.c: In function ‘get_dh2048’:
	/usr/local/src/mariadb/vio/viosslfactories.c:57:11: warning: implicit declaration of function ‘DH_new’ [-Wimplicit-function-declaration]
	   if ((dh=DH_new()) == NULL) return(NULL);
	           ^
	/usr/local/src/mariadb/vio/viosslfactories.c:57:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
	   if ((dh=DH_new()) == NULL) return(NULL);
	          ^
	/usr/local/src/mariadb/vio/viosslfactories.c:58:5: error: dereferencing pointer to incomplete type ‘DH {aka struct dh_st}’
	   dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
	     ^
	/usr/local/src/mariadb/vio/viosslfactories.c:58:9: warning: implicit declaration of function ‘BN_bin2bn’ [-Wimplicit-function-declaration]
	   dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
	         ^
	/usr/local/src/mariadb/vio/viosslfactories.c:61:5: warning: implicit declaration of function ‘DH_free’ [-Wimplicit-function-declaration]
	   { DH_free(dh); return(NULL); }
	     ^
	vio/CMakeFiles/vio.dir/build.make:182: recipe for target 'vio/CMakeFiles/vio.dir/viosslfactories.c.o' failed
	make[2]: *** [vio/CMakeFiles/vio.dir/viosslfactories.c.o] Error 1
	make[2]: Leaving directory '/usr/local/src/mariadb/bld'
	CMakeFiles/Makefile2:3432: recipe for target 'vio/CMakeFiles/vio.dir/all' failed
	make[1]: *** [vio/CMakeFiles/vio.dir/all] Error 2
	make[1]: Leaving directory '/usr/local/src/mariadb/bld'
	Makefile:149: recipe for target 'all' failed
	make: *** [all] Error 2



 Comments   
Comment by Sergei Golubchik [ 2015-12-22 ]

This happens, because your OpenSSL is configured with the non-default OPENSSL_NO_DEPRECATED symbol.

I'll try to fix it in the next 5.5 (and following 10.0, 10.1) releases. Meanwhile you can undefine it for MariaDB. For example, use

cmake .. -DCMAKE_CXX_FLAGS=-UOPENSSL_NO_DEPRECATED -DCMAKE_C_FLAGS=-UOPENSSL_NO_DEPRECATED

Comment by Sergei Golubchik [ 2015-12-22 ]

This is the crude patch that fixes the compilation:

diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 133527c..4c251b6 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -110,6 +110,8 @@
 #include <poll.h>
 #endif
 
+#include <openssl/crypto.h>
+
 #include <my_systemd.h>
 
 #define mysqld_charset &my_charset_latin1
@@ -1467,7 +1469,7 @@ static openssl_lock_t *openssl_dynlock_create(const char *, int);
 static void openssl_dynlock_destroy(openssl_lock_t *, const char *, int);
 static void openssl_lock_function(int, int, const char *, int);
 static void openssl_lock(int, openssl_lock_t *, const char *, int);
-static unsigned long openssl_id_function();
+static void openssl_id_function(CRYPTO_THREADID *);
 #endif
 char *des_key_file;
 #ifndef EMBEDDED_LIBRARY
@@ -4663,7 +4665,7 @@ static int init_thread_environment()
   CRYPTO_set_dynlock_destroy_callback(openssl_dynlock_destroy);
   CRYPTO_set_dynlock_lock_callback(openssl_lock);
   CRYPTO_set_locking_callback(openssl_lock_function);
-  CRYPTO_set_id_callback(openssl_id_function);
+  CRYPTO_THREADID_set_callback(openssl_id_function);
 #endif
 #endif
   mysql_rwlock_init(key_rwlock_LOCK_sys_init_connect, &LOCK_sys_init_connect);
@@ -4699,9 +4701,9 @@ static int init_thread_environment()
 
 
 #if defined(HAVE_OPENSSL) && !defined(HAVE_YASSL)
-static unsigned long openssl_id_function()
+static void openssl_id_function(CRYPTO_THREADID *tid)
 {
-  return (unsigned long) pthread_self();
+  tid->val= (unsigned long) pthread_self();
 }
 
 
diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c
index ca4669f..498d8a4 100644
--- a/vio/viosslfactories.c
+++ b/vio/viosslfactories.c
@@ -15,6 +15,8 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #include "vio_priv.h"
+#include <openssl/dh.h>
+#include <openssl/bn.h>
 
 #ifdef HAVE_OPENSSL
 

But it needs to be modified to work for old OpenSSL versions too (and for yassl builds).

Comment by pgnd [ 2015-12-22 ]

> your OpenSSL is configured with the non-default OPENSSL_NO_DEPRECATED symbol.

yep, openssl 1.0.2e here is config'd with "no-deprecated" flag. Not currently 'default', but strongly advised. Been available since openssl v0.9.8 iiuc.

but for MDB build

> cmake .. -DCMAKE_CXX_FLAGS=-UOPENSSL_NO_DEPRECATED -DCMAKE_C_FLAGS=-UOPENSSL_NO_DEPRECATED

doesn't appear to do the trick.

cmake ..  --debug-output -Wno-dev \
 -DCMAKE_C_FLAGS="... -UOPENSSL_NO_DEPRECATED" \
 -DCMAKE_CXX_FLAGS="... -UOPENSSL_NO_DEPRECATED" \
 ...
make VERBOSE=1
	...
	[ 75%] Building C object vio/CMakeFiles/vio.dir/viosslfactories.c.o
	cd /usr/local/src/mariadb/bld/vio && /usr/bin/gcc-5  -DHAVE_CONFIG_H -DHAVE_OPENSSL -DHAVE_SYSTEMD -I/usr/local/src/mariadb/bld/include -I/usr/local/src/mariadb/include -I/usr/local/ssl/include  -fno-delete-null-pointer-checks -D_FORTIFY_SOURCE=2 -fmessage-length=0 -fstack-protector  -march=x86-64 -mtune=nocona -I/usr/local/include -UOPENSSL_NO_DEPRECATED -pie -fPIC -Wl,-z,relro,-z,now -fstack-protector --param=ssp-buffer-size=4 -DWITH_INNODB_DISALLOW_WRITES -O3 -DNDEBUG -D_FORTIFY_SOURCE=2 -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1   -fPIC -o CMakeFiles/vio.dir/viosslfactories.c.o   -c /usr/local/src/mariadb/vio/viosslfactories.c
	/usr/local/src/mariadb/vio/viosslfactories.c: In function ‘get_dh2048’:
	/usr/local/src/mariadb/vio/viosslfactories.c:57:11: warning: implicit declaration of function ‘DH_new’ [-Wimplicit-function-declaration]
	   if ((dh=DH_new()) == NULL) return(NULL);
	           ^
	/usr/local/src/mariadb/vio/viosslfactories.c:57:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
	   if ((dh=DH_new()) == NULL) return(NULL);
	          ^
	/usr/local/src/mariadb/vio/viosslfactories.c:58:5: error: dereferencing pointer to incomplete type ‘DH {aka struct dh_st}’
	   dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
	     ^
	/usr/local/src/mariadb/vio/viosslfactories.c:58:9: warning: implicit declaration of function ‘BN_bin2bn’ [-Wimplicit-function-declaration]
	   dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
	         ^
	/usr/local/src/mariadb/vio/viosslfactories.c:61:5: warning: implicit declaration of function ‘DH_free’ [-Wimplicit-function-declaration]
	   { DH_free(dh); return(NULL); }
	     ^
	vio/CMakeFiles/vio.dir/build.make:182: recipe for target 'vio/CMakeFiles/vio.dir/viosslfactories.c.o' failed
	make[2]: *** [vio/CMakeFiles/vio.dir/viosslfactories.c.o] Error 1
	make[2]: Leaving directory '/usr/local/src/mariadb/bld'
	CMakeFiles/Makefile2:3432: recipe for target 'vio/CMakeFiles/vio.dir/all' failed
	make[1]: *** [vio/CMakeFiles/vio.dir/all] Error 2
	make[1]: Leaving directory '/usr/local/src/mariadb/bld'
	Makefile:149: recipe for target 'all' failed
	make: *** [all] Error 2

also, I note you keep changing the priority of these build bugs from 'Blocker'

@ https://mariadb.atlassian.net/secure/ShowConstantsHelp.jspa?decorator=popup#PriorityLevels

"Blocker Blocks development and/or testing work, production could not run."

Inability to build certainly fits that bill, no? Or advise otherwise?

Comment by pgnd [ 2015-12-23 ]

MDB 10.1 branch
+ patch @
https://mariadb.atlassian.net/browse/MDEV-9314?focusedCommentId=79335&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-79335

gets through a successful make

	cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb ...
	make V=1
 
	ldd sql/mysqld | egrep -i "ssl|crypto|pcre"
		libpcre.so.1 => /usr/local/lib64/libpcre.so.1 (0x00007f59b0088000)
		libpcrecpp.so.0 => /usr/local/lib64/libpcrecpp.so.0 (0x00007f59afe7e000)
		libssl.so.1.0.0 => /usr/local/ssl/lib64/libssl.so.1.0.0 (0x00007f59af990000)
		libcrypto.so.1.0.0 => /usr/local/ssl/lib64/libcrypto.so.1.0.0 (0x00007f59af549000)

where

	cmake .. -LAH | egrep -i "ssl|crypto|pcre"
		-- OPENSSL_INCLUDE_DIR = /usr/local/ssl/include
		-- OPENSSL_LIBRARIES = /usr/local/ssl/lib64/libssl.so
		-- CRYPTO_LIBRARY = /usr/local/ssl/lib64/libcrypto.so
		-- OPENSSL_MAJOR_VERSION = 
		-- SSL_LIBRARIES = /usr/local/ssl/lib64/libssl.so;/usr/local/ssl/lib64/libcrypto.so;dl
		CMAKE_EXE_LINKER_FLAGS:STRING= -L/usr/local/lib64  -Wl,-rpath,/usr/local/lib64   -lpcre -lpcrecpp
		CMAKE_SHARED_LINKER_FLAGS:STRING= -L/usr/local/lib64  -Wl,-rpath,/usr/local/lib64   -lpcre -lpcrecpp
		CRYPTO_LIBRARY:FILEPATH=/usr/local/ssl/lib64/libcrypto.so
		OPENSSL_INCLUDE_DIR:PATH=/usr/local/ssl/include
		OPENSSL_LIBRARIES:FILEPATH=/usr/local/ssl/lib64/libssl.so
		OPENSSL_ROOT_DIR:PATH=/usr/local/ssl
		WITH_MYSQLD_LDFLAGS:STRING= -L/usr/local/ssl/lib64  -Wl,-rpath,/usr/local/ssl/lib64   -lssl -lcrypto
		// Which pcre to use (possible values are 'bundled', 'system', or 'auto')
		WITH_PCRE:STRING=auto
		// path to custom SSL installation
		WITH_SSL_PATH:PATH=/usr/local/ssl

and the built, local executable,

	sql/mysqld -V
		sql/mysqld  Ver 10.1.10-MariaDB-log for Linux on x86_64 (Source distribution)

but after install

	rm -rf /usr/local/mariadb
	make install
 
	/usr/local/mariadb/bin/mysqld -V
		/usr/local/mariadb/bin/mysqld: symbol lookup error: /usr/local/mariadb/bin/mysqld: undefined symbol: pcre_stack_guard

checking

	ldd /usr/local/mariadb/bin/mysqld | egrep -i "ssl|crypto|pcre"
		libpcre.so.1 => /usr/lib64/libpcre.so.1 (0x00007fe1d4c16000)
		libpcrecpp.so.0 => /usr/lib64/libpcrecpp.so.0 (0x00007fe1d4a0d000)
		libssl.so.1.0.0 => /lib64/libssl.so.1.0.0 (0x00007fe1d457a000)
		libcrypto.so.1.0.0 => /lib64/libcrypto.so.1.0.0 (0x00007fe1d4187000)

all the links are incorrect.

checking RPATH

	cmake .. -LAH | egrep -i "rpath"
		CMAKE_EXE_LINKER_FLAGS:STRING= -L/usr/local/lib64  -Wl,-rpath,/usr/local/lib64   -lpcre -lpcrecpp
		CMAKE_SHARED_LINKER_FLAGS:STRING= -L/usr/local/lib64  -Wl,-rpath,/usr/local/lib64   -lpcre -lpcrecpp
		CMAKE_SKIP_INSTALL_RPATH:BOOL=NO
		CMAKE_SKIP_RPATH:BOOL=NO
		WITH_MYSQLD_LDFLAGS:STRING= -L/usr/local/ssl/lib64  -Wl,-rpath,/usr/local/ssl/lib64   -lssl -lcrypto

reconfig'ing with

	-DCMAKE_SKIP_INSTALL_RPATH=0 \
	-DCMAKE_SKIP_RPATH=0 \
+	-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=1 \

does the trick. AFter repeat, now after install,

	/usr/local/mariadb/bin/mysqld -V
		sql/mysqld  Ver 10.1.10-MariaDB-log for Linux on x86_64 (Source distribution)

Comment by Sergei Golubchik [ 2015-12-24 ]

Thanks for the tip. When fixing I'll make sure that MariaDB builds and runs with "no-deprecated" openssl.

As for Blocker — for simplicity we don't have he internal "Severity" vs. public "Priority", so this field affects both. So I used to downgrading the priority as users often set it to the maximum possible value. But I agree that this issue is really a Blocker, I'll change it back.

Comment by Sergei Golubchik [ 2016-02-03 ]

I'm compiling MariaDB 5.5 now with openssl -DOPENSSL_NO_DEPRECATED and strangely enough I don't get any warnings or errors for viosslfactories.c. Only for mysqld.cc, I'll fix that.

Generated at Thu Feb 08 07:33:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.