Skip to content

Commit

Permalink
configure: Avoid -Werror=maybe-uninitialized
Browse files Browse the repository at this point in the history
The configure script used to compile some code which dereferences memory
with ubsan to verify the compiler can link with ubsan library which
detects dereferencing of uninitialized memory. However, as the
dereferenced memory was allocated in the same code, GCC can statically
detect the unitialized memory dereference and emit maybe-uninitialized
warning. If -Werror is set, this becomes an error, and the configure
script incorrectly thinks the error indicates the compiler cannot use
ubsan.

Fix this error by replacing the code with another function which adds
1 to a signed integer argument. This brings in ubsan to detect if it
causes signed integer overflow. As the value of the argument cannot be
statically determined, the new function is also immune to compiler
warnings.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20230405070030.23148-1-akihiko.odaki@daynix.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
akihikodaki authored and bonzini committed Apr 20, 2023
1 parent a74b0d0 commit 8041e9e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1749,13 +1749,9 @@ if test "$sanitizers" = "yes" ; then
# detect the static linking issue of ubsan, see also:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
cat > $TMPC << EOF
#include <stdlib.h>
int main(void) {
void *tmp = malloc(10);
if (tmp != NULL) {
return *(int *)(tmp + 2);
}
return 1;
int main(int argc, char **argv)
{
return argc + 1;
}
EOF
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
Expand Down

0 comments on commit 8041e9e

Please sign in to comment.