libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Build failure with Link-Time Optimization


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Build failure with Link-Time Optimization
Date: Sun, 31 Dec 2023 12:14:59 +0100
User-agent: Mozilla Thunderbird

I see now. I've put in an initializer (to 0) on the code path that your c++ compiler had a false-positive identification of a use of an uninitialized variable on. The code path was definitively dead, but as this removes the compiler warning and simplifies mental load on human code auditors, I think we can "afford" the unnecessary initialization of the variable to 0. Changed in Git a532889e..de02ef13.

Happy hacking!

Christian

On 12/28/23 18:52, Sergey Sudnitsyn wrote:
Here you go - but as I mentioned earlier - extracting the relevant pieces of the application is next to impossible - and I am not getting the same errors when running microhttpd's
`make check`.

g++ -m64 -O3 -DNDEBUG -fdata-sections -ffunction-sections -s -flto -fPIE -fPIC -fstack-protector-strong -D_FORTIFY_SOURCE=2 -std=c++20 -Waddress -Waggressive-loop-optimizations -Wall -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wfatal-errors -Wfloat-equal -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wformat=2 -Wimport -Winit-self -Wno-inline -Winvalid-pch -Wlogical-op -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Woverlength-strings -Wparentheses -Wpedantic -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wsign-conversion -Wstack-protector -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default -Wswitch-enum -Wtrigraphs -Wundef -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunsafe-loop-optimizations -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wno-deprecated-declarations -Wc++11-compat -Wconversion-null -Wctor-dtor-privacy -Weffc++ -Winvalid-pch -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wsign-promo -Wstrict-null-sentinel -Wno-useless-cast -Wzero-as-null-pointer-constant -Wstack-protector -fstack-protector-all -Wno-non-virtual-dtor -Wno-reorder -Wno-sign-conversion -Wno-float-equal -Wno-old-style-cast -Wno-zero-as-null-pointer-constant -m64 -Wl,--gc-sections -s -flto -pie -z noexecstack -z relro -z now -fuse-ld=gold -s main.cpp.o -o bin/main myapplication_libs.a -lmicrohttpd -lcurl -lgnutls /usr/lib64/libz.so -lpthread -lgcrypt -lgpg-error -lhogweed -lnettle -lgmp

src/microhttpd/connection.c: In function ‘connection_alloc_memory’:
src/microhttpd/connection.c:281:10: error: ‘need_to_free’ may be used uninitialized [-Werror=maybe-uninitialized]   281 |       if (c->read_buffer_size - c->read_buffer_offset >= need_to_free)
       |          ^
compilation terminated due to -Wfatal-errors.
lto1: all warnings being treated as errors


On Thu, 28 Dec 2023 at 06:26, Christian Grothoff <grothoff@gnunet.org <mailto:grothoff@gnunet.org>> wrote:

    I think it might be helpful if you could share the *exact* compiler
    invocation (make V=1) and error message you are getting...

    On 12/27/23 11:38, Sergey Sudnitsyn wrote:
     > Thank you.
     > I don't know what's so special about my setup - I am getting the
    same
     > error with GCC 12 & 13 - compiling for both x86_64 & aarch64.
     > Compiler flags - nothing unusual - -O3 -flto  - but maybe
    warnings are a
     > bit overzealous (-Wuninitialized -Wstack-protector).
     > I'll try producing a sample that reproduces this - and will use
     > suggested workaround in the meantime.
     >
     > On Tue, 26 Dec 2023 at 17:21, Evgeny Grin <k2k@yandex.ru
    <mailto:k2k@yandex.ru>
     > <mailto:k2k@yandex.ru <mailto:k2k@yandex.ru>>> wrote:
     >
     >     Hi Sergey,
     >
     >     Are you using some special compiler or linker parameters?
    Some special
     >     compiler or linker versions?
     >
     >     I regularly test MHD with LTO. I've retested the current git
    master
     >     with
     >     LTO and cannot reproduce.
     >     No errors, nor even warnings.
     >
     >     If you check the code you will find that both mentioned
    variables are
     >     not used before initialisation. (Please provide the code path
    if I'm
     >     wrong).
     >
     >     Unless variables are really used as uninitialised (which
    should be a
     >     bug
     >     and needs to be fixed), I'd avoid unneeded initialisation to
    save the
     >     code size (and negligible performance).
     >
     >     If your compiler/linker complaint is false positive, you
    probably may
     >     workaround it with '-ftrivial-auto-var-init' parameter.
     >
     >     Let me know the details, please.
     >
     >     --
     >     Evgeny
     >
     >     On 26/12/2023 16:14, Sergey Sudnitsyn wrote:
     >      > When LTO is enabled, linking fails complaining about
    potentially
     >      > uninitialized variables;
     >      > It's hard to provide a small sample reproducing this, but
    I hope the
     >      > patch can be applied even without it since it's innocent
    enough
     >     (diff
     >      > against commit 8bb481f ):
     >      >
     >      > diff --git a/src/microhttpd/connection.c
     >     b/src/microhttpd/connection.c
     >      > index f9892a55..e5dd1a45 100644
     >      > --- a/src/microhttpd/connection.c
     >      > +++ b/src/microhttpd/connection.c
     >      > @@ -653,7 +653,7 @@ MHD_connection_alloc_memory_ (struct
     >     MHD_Connection
     >      > *connection,
     >      >   {
     >      >     struct MHD_Connection *const c = connection; /* a
    short alias */
     >      >     struct MemoryPool *const pool = c->pool; /* a short
    alias */
     >      > - size_t need_to_be_freed; /**< The required amount of
    additional
     >     free
     >      > memory */
     >      > + size_t need_to_be_freed = 0; /**< The required amount of
     >     additional
     >      > free memory */
     >      >     void *res;
     >      >
     >      >     res = MHD_pool_try_alloc (pool, size, &need_to_be_freed);
     >      > @@ -4468,7 +4468,7 @@ process_request_body (struct
    MHD_Connection
     >      > *connection)
     >      >         { /* Need the parse the chunk size line */
     >      >           /** The number of found digits in the chunk size
    number */
     >      >           size_t num_dig;
     >      > - uint64_t chunk_size;
     >      > + uint64_t chunk_size = 0;
     >      >           bool broken;
     >      >           bool overflow;
     >      >
     >




reply via email to

[Prev in Thread] Current Thread [Next in Thread]