Bug #112893 The C API mysql_stmt_bind_named_param is not exported in libmysqlclient.so.22
Submitted: 31 Oct 2023 8:12 Modified: 31 Oct 2023 9:03
Reporter: Sebastien FLAESCH Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S1 (Critical)
Version:8.2.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: symbol export mysql_stmt_bind_named_param

[31 Oct 2023 8:12] Sebastien FLAESCH
Description:
With the Linux x86 package 

 mysql-8.2.0-linux-glibc2.28-x86_64.tar.xz:

When using mysql_stmt_bind_named_param(), you get this error on link libmysqlclient.so.22: 

mys.c:1072: undefined reference to `mysql_stmt_bind_named_param'

It appears that the mysql_stmt_bind_named_param() function is not exported like other functions such as mysql_stmt_bind_param():

$ readelf -s libmysqlclient.so.22 | grep _named_

$ nm -D --demangle libmysqlclient.so.22 | grep _named_

$ readelf -s libmysqlclient.so.22 | grep mysql_stmt_bind
 12584: 0000000000032760   646 FUNC    LOCAL  DEFAULT   12 mysql_stmt_bind_[...]
 13959: 0000000000032b80   517 FUNC    GLOBAL DEFAULT   12 mysql_stmt_bind_[...]
 13996: 00000000000329f0    17 FUNC    GLOBAL DEFAULT   12 mysql_stmt_bind_param

$ nm -D --demangle libmysqlclient.so.22 | grep mysql_stmt_bind
00000000000329f0 T mysql_stmt_bind_param@@libmysqlclient_22.0
0000000000032b80 T mysql_stmt_bind_result@@libmysqlclient_22.0

How to repeat:
cc -fsanitize=address -fno-omit-frame-pointer  -shared -Xlinker --no-undefined  -o dbmmys_8_2.so mys_8_2.o -L../base -lfglodi -L../../fgllib -lfgl -Wl,-rpath='$ORIGIN/../lib' -L/opt3/dbs/mys/8.2/lib -lmysqlclient 
/usr/bin/ld: mys_8_2.o: in function `bindParameters':
/home/sf/genero/devel/fgl/fgl/src/sqldriver/mysql/mys.c:1072: undefined reference to `mysql_stmt_bind_named_param'
collect2: error: ld returned 1 exit status

Suggested fix:
export the function
[31 Oct 2023 8:27] Sebastien FLAESCH
Looking at the sources of 8.2.0, seems libmysql/CMakeLists.txt is missing to list the mysql_stmt_bind_named_param symbol in

SET(CLIENT_API_FUNCTIONS
   ...

I am not a CMake expert but looks like that's the reason.

Maybe other new C API functions have been forgotten?
[31 Oct 2023 9:03] MySQL Verification Team
Hello Sebastien FLAESCH,

Thank you for the report and feedback!

Thanks,
Umesh
[31 Oct 2023 10:43] MySQL Verification Team
Bug #112896 marked duplicate of this one
[31 Oct 2023 10:46] Daniƫl van Eeden
With this patch:
```
diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt
index f7f11f7b25c..3559e7e00c6 100644
--- a/libmysql/CMakeLists.txt
+++ b/libmysql/CMakeLists.txt
@@ -69,6 +69,7 @@ SET(CLIENT_API_FUNCTIONS
   mysql_query
   mysql_set_server_option
   mysql_stmt_bind_param
+  mysql_stmt_bind_named_param
   mysql_stmt_bind_result
   mysql_stmt_execute
   mysql_stmt_fetch
```

```
[dvaneeden@dve-carbon bld]$ objdump -T library_output_directory/libmysqlclient.so | grep -E 'mysql_stmt.*param'
000000000002ffb0 g    DF .text	000000000000000b  libmysqlclient_22.0 mysql_stmt_param_count
00000000000305e0 g    DF .text	0000000000000011  libmysqlclient_22.0 mysql_stmt_bind_param
000000000002fe80 g    DF .text	0000000000000007  libmysqlclient_22.0 mysql_stmt_param_metadata
00000000000302a0 g    DF .text	0000000000000339  libmysqlclient_22.0 mysql_stmt_bind_named_param
```

And without this patch:
```
[dvaneeden@dve-carbon bld]$ objdump -T library_output_directory/libmysqlclient.so | grep -E 'mysql_stmt.*param'
000000000002ffb0 g    DF .text	000000000000000b  libmysqlclient_22.0 mysql_stmt_param_count
000000000002fff0 g    DF .text	0000000000000338  libmysqlclient_22.0 mysql_stmt_bind_param
000000000002fe80 g    DF .text	0000000000000007  libmysqlclient_22.0 mysql_stmt_param_metadata
```

This is with a clone of the trunk branch of mysql/mysql-server and:
```
mkdir bld
cd bld
cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../boost
make -j8 libmysql
```
[13 Nov 2023 6:10] MySQL Verification Team
Bug #113055 marked as duplicate of this one