Go-sqlite3: Warning and note in sqlite3-binding.c

Created on 14 Apr 2020  Â·  11Comments  Â·  Source: mattn/go-sqlite3

Every time my application starts or tests are run I get the following in my output:

# github.com/mattn/go-sqlite3
sqlite3-binding.c: In function ‘sqlite3SelectNew’:
sqlite3-binding.c:128049:10: warning: function may return address of local variable [-Wreturn-local-addr]
128049 |   return pNew;
       |          ^~~~
sqlite3-binding.c:128009:10: note: declared here
128009 |   Select standin;
       |          ^~~~~~~

I can get round this by adding -w to the CFLAGS option inside sqlite3.go

Is there a better way to get rid of this warning and note?

I am running on Fedora 32 x86_64

Most helpful comment

I have added -Wno-return-local-addr" to my environment variables in .bashrc which has got rid of all that mess for the time being.

export CGO_CFLAGS="-g -O2 -Wno-return-local-addr"

All 11 comments

I have added -Wno-return-local-addr" to my environment variables in .bashrc which has got rid of all that mess for the time being.

export CGO_CFLAGS="-g -O2 -Wno-return-local-addr"

A user of a product I am one of the maintainers for complained about the same thing. If you're able I'm interested in your gcc, glibc, and libsqlite3 versions; as it works fine for me.

For ref my versions are 9.3, 2.31, and 3.31.1

with

sqlite3 --version
    3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1

build with gcc10

    echo $CC $CXX $CPP
        /usr/bin/gcc-10 /usr/bin/g++-10 /usr/bin/cpp-10
    $CC --version
        gcc-10 (SUSE Linux) 10.1.1 20200507 [revision dd38686d9c810cecbaa80bb82ed91caaa58ad635]
    go build github.com/mattn/go-sqlite3
        # github.com/mattn/go-sqlite3
        sqlite3-binding.c: In function ‘sqlite3SelectNew’:
        sqlite3-binding.c:128049:10: warning: function may return address of local variable [-Wreturn-local-addr]
        128049 |   return pNew;
               |          ^~~~
        sqlite3-binding.c:128009:10: note: declared here
        128009 |   Select standin;
               |          ^~~~~~~

and, build with gcc9

    echo $CC $CXX $CPP
        /usr/bin/gcc-9 /usr/bin/g++-9 /usr/bin/cpp-9
    $CC --version
        gcc-9 (SUSE Linux) 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2]
    go build github.com/mattn/go-sqlite3

=====> NO SQLITE3 ERROR <====

Yeah, looks like a gcc 10 issue, 9.3 works fine. It's likely the issue lies with libsqlite3-0 3.31.1 and gcc 10.x. Either a new warning being detected or a problem with 10.x - a lot of issues were resolved in 10.1 marked as regressions introduced between 9.3 and 10.0 (~700) so it could be that.

looks likely

git clone https://github.com/sqlite/sqlite.git
cd sqlite
git checkout version-3.31.1
gcc --version
    gcc (SUSE Linux) 10.1.1 20200507 [revision dd38686d9c810cecbaa80bb82ed91caaa58ad635]
./configure
make
    ...
    libtool: link: /usr/bin/gcc-10 -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -D_FORTIFY_SOURCE=2 -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -DSQLITE_OS_UNIX=1 -I. -I/usr/local/src/sqlite/src -I/usr/local/src/sqlite/ext/rtree -I/usr/local/src/sqlite/ext/icu -I/usr/local/src/sqlite/ext/fts3 -I/usr/local/src/sqlite/ext/async -I/usr/local/src/sqlite/ext/session -I/usr/local/src/sqlite/ext/userauth -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_HAVE_ZLIB=1 -DHAVE_READLINE=0 -DHAVE_EDITLINE=1 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_OFFSET_SQL_FUNC -DSQLITE_ENABLE_DESERIALIZE -o sqlite3 shell.c sqlite3.c  -ledit -ldl -lz -lpthread -Wl,-rpath -Wl,/usr/local/sqlite-gcc10-test/lib64
    In function 'zipfileComparePath',
        inlined from 'zipfileUpdate' at shell.c:5784:11:
    shell.c:5656:17: warning: '__builtin_memcmp_eq' specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
     5656 |   if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
          |                 ^~~~~~~~~~~~~~~~~~
    sqlite3.c: In function ‘sqlite3SelectNew’:
    sqlite3.c:128048:10: warning: function may return address of local variable [-Wreturn-local-addr]
    128048 |   return pNew;
           |          ^~~~
    sqlite3.c:128008:10: note: declared here
    128008 |   Select standin;
           |          ^~~~~~~
    sqlite3.c:128008:10: note: declared here
    sqlite3.c: In function 'sqlite3SelectNew':
    sqlite3.c:128048:10: warning: function may return address of local variable [-Wreturn-local-addr]
    128048 |   return pNew;
           |          ^~~~
    sqlite3.c:128008:10: note: declared here
    128008 |   Select standin;
           |          ^~~~~~~
    sqlite3.c:128008:10: note: declared here
    ...

In my case...

$ go get -u -v github.com/mattn/go-sqlite3
# github.com/mattn/go-sqlite3
sqlite3-binding.c: In function ‘sqlite3SelectNew’:
sqlite3-binding.c:128049:10: warning: function may return address of local variable [-Wreturn-local-addr]
128049 |   return pNew;
       |          ^~~~
sqlite3-binding.c:128009:10: note: declared here
128009 |   Select standin;
       |          ^~~~~~~

ClearLinux version:

$ swupd check-update 
Current OS version: 33100
Latest server version: 33100
There are no updates available

GCC Version

$ gcc --version
gcc (Clear Linux OS for Intel Architecture) 10.1.1 20200513 releases/gcc-10.1.0-36-gf2b77b928a
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

windows 10 x64 2004 has the same issue

This is an upstream bug with libsqlite3, not sure where their bug tracker is.

This is an upstream bug with libsqlite3, not sure where their bug tracker is.

https://www3.sqlite.org/cgi/src/ticket

There's a discussion on the SQLite Forum about this issue, including a candidate patch.

Facing this issue with GoORM, which uses this sqlite3 driver. Any workarounds?

Update - adding this env variable fixed it, export CGO_CFLAGS="-g -O2 -Wno-return-local-addr"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eaglebush picture eaglebush  Â·  7Comments

student020341 picture student020341  Â·  9Comments

ghost picture ghost  Â·  6Comments

gaorongfu picture gaorongfu  Â·  10Comments

apertureless picture apertureless  Â·  4Comments