]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Compile code that gets linked with libc by adding -fhosted.
authorFlorian Krohm <flo2030@eich-krohm.de>
Thu, 15 May 2025 21:42:19 +0000 (21:42 +0000)
committerFlorian Krohm <flo2030@eich-krohm.de>
Thu, 15 May 2025 21:42:19 +0000 (21:42 +0000)
The use of -fno-builtin interfers with -Wformat: no format warnings will
be given when both options are present. Because -fno-builtin means: when
you encounter a function that has the same name as a built-in function,
forget everything you know about that function.
That includes functions attributes. And without __attribute__((format...))
there will be no -Wformat warnings.

The fix is to append -fhosted when compiling something that gets linked
with libc. As command line options are processed left to right adding
-fhosted at the end overrides any earlier -fno-builtin option.

Fix compiler warnings.

Add some ugly ifdeffery to drd/drd_intercepts.c. I could not figure out how
to rewrite the offensive printf to avoid testcase breakage.

12 files changed:
auxprogs/Makefile.am
auxprogs/valgrind-di-server.c
auxprogs/valgrind-listener.c
coregrind/Makefile.am
coregrind/vgdb-invoker-ptrace.c
coregrind/vgdb.c
drd/drd_pthread_intercepts.c
helgrind/hg_intercepts.c
memcheck/tests/vbit-test/Makefile.am
memcheck/tests/vbit-test/irops.c
none/tests/s390x/disasm-test/Makefile.am
none/tests/s390x/disasm-test/opcode.c

index 3a2d0d17629efb89948eae19bdadbe98198c6339..4a10fb1cf8a23b035bc763b90d48dca261d49374 100644 (file)
@@ -33,7 +33,7 @@ bin_PROGRAMS = valgrind-listener valgrind-di-server
 
 valgrind_listener_SOURCES = valgrind-listener.c
 valgrind_listener_CPPFLAGS  = $(AM_CPPFLAGS_PRI) -I$(top_srcdir)/coregrind
-valgrind_listener_CFLAGS    = $(AM_CFLAGS_PRI)
+valgrind_listener_CFLAGS    = $(AM_CFLAGS_PRI) -fhosted
 valgrind_listener_CCASFLAGS = $(AM_CCASFLAGS_PRI)
 valgrind_listener_LDFLAGS   = $(AM_CFLAGS_PRI)
 if VGCONF_PLATVARIANT_IS_ANDROID
@@ -52,7 +52,7 @@ endif
 
 valgrind_di_server_SOURCES   = valgrind-di-server.c
 valgrind_di_server_CPPFLAGS  = $(AM_CPPFLAGS_PRI) -I$(top_srcdir)/coregrind
-valgrind_di_server_CFLAGS    = $(AM_CFLAGS_PRI)
+valgrind_di_server_CFLAGS    = $(AM_CFLAGS_PRI) -fhosted
 valgrind_di_server_CCASFLAGS = $(AM_CCASFLAGS_PRI)
 valgrind_di_server_LDFLAGS   = $(AM_CFLAGS_PRI)
 if VGCONF_PLATVARIANT_IS_ANDROID
@@ -87,7 +87,7 @@ endif
 
 getoff_@VGCONF_ARCH_PRI@_@VGCONF_OS@_SOURCES   = getoff.c
 getoff_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CPPFLAGS  = $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
-getoff_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS    = $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
+getoff_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS    = $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) -fhosted
 getoff_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CCASFLAGS = $(AM_CCASFLAGS_PRI)
 getoff_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS   = $(AM_CFLAGS_PRI) @LIB_UBSAN@
 if HAVE_DLINFO_RTLD_DI_TLS_MODID
@@ -104,7 +104,7 @@ endif
 if VGCONF_HAVE_PLATFORM_SEC
 getoff_@VGCONF_ARCH_SEC@_@VGCONF_OS@_SOURCES   = getoff.c
 getoff_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CPPFLAGS  = $(AM_CPPFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
-getoff_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS    = $(AM_CFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
+getoff_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CFLAGS    = $(AM_CFLAGS_@VGCONF_PLATFORM_SEC_CAPS@) -fhosted
 getoff_@VGCONF_ARCH_SEC@_@VGCONF_OS@_CCASFLAGS = $(AM_CCASFLAGS_SEC)
 getoff_@VGCONF_ARCH_SEC@_@VGCONF_OS@_LDFLAGS   = $(AM_CFLAGS_SEC)
 if HAVE_DLINFO_RTLD_DI_TLS_MODID
index 1b6506e3da61dc147cd2cec4a99b147d45b99298..a7607c06962cda9b748b36350d8d15dda89c4828 100644 (file)
@@ -1172,7 +1172,7 @@ int main (int argc, char** argv)
                  break;
 
            if (i >= M_CONNECTIONS) {
-              fprintf(stderr, "\n\nMore than %d concurrent connections.\n"
+              fprintf(stderr, "\n\nMore than %u concurrent connections.\n"
                       "Restart the server giving --max-connect=INT on the\n"
                       "commandline to increase the limit.\n\n",
                       M_CONNECTIONS);
index 158f11c088cb2830d43879d4896d88f745af852c..5607e138db0dfe77bf36e7beb35b9e378184abf5 100644 (file)
@@ -355,7 +355,7 @@ int main (int argc, char** argv)
                  break;
 
            if (i >= M_CONNECTIONS) {
-              fprintf(stderr, "\n\nMore than %d concurrent connections.\n"
+              fprintf(stderr, "\n\nMore than %u concurrent connections.\n"
                       "Restart the listener giving --max-connect=INT on the\n"
                       "commandline to increase the limit.\n\n",
                       M_CONNECTIONS);
index 784459569db0ab4bb8cee572c73b3e657b94dfc3..4ead1542b0c73bf256e1ab56d433cbcd6d5d43aa 100644 (file)
@@ -62,7 +62,7 @@ AR = ${LTO_AR}
 RANLIB = ${LTO_RANLIB}
 
 valgrind_CPPFLAGS  = $(AM_CPPFLAGS_PRI)
-valgrind_CFLAGS    = $(AM_CFLAGS_PRI) $(LTO_CFLAGS)
+valgrind_CFLAGS    = $(AM_CFLAGS_PRI) $(LTO_CFLAGS) -fhosted
 valgrind_CCASFLAGS = $(AM_CCASFLAGS_PRI)
 valgrind_LDFLAGS   = $(AM_CFLAGS_PRI) @LIB_UBSAN@
 # If there is no secondary platform, and the platforms include x86-darwin,
@@ -104,7 +104,7 @@ vgdb_SOURCES += vgdb-invoker-freebsd.c
 endif
 
 vgdb_CPPFLAGS  = $(AM_CPPFLAGS_PRI) $(GDB_SCRIPTS_DIR)
-vgdb_CFLAGS    = $(AM_CFLAGS_PRI) $(LTO_CFLAGS)
+vgdb_CFLAGS    = $(AM_CFLAGS_PRI) $(LTO_CFLAGS) -fhosted
 vgdb_CCASFLAGS = $(AM_CCASFLAGS_PRI)
 vgdb_LDFLAGS   = $(AM_CFLAGS_PRI) @LIB_UBSAN@
 if VGCONF_PLATVARIANT_IS_ANDROID
index 3a6a455d035963e48f16499fefc77814f35f6efb..a6df5dc07db7ade1438daade2fa06c59411777ad 100644 (file)
@@ -271,10 +271,10 @@ Bool waitstopped (pid_t pid, int signal_expected, const char *msg)
             msg, signal_expected);
       p = waitpid(pid, &status, __WALL);
       DEBUG(1, "after waitpid pid %d p %d status 0x%x %s\n", pid, p,
-            status, status_image (status));
+            (unsigned)status, status_image (status));
       if (p != pid) {
          ERROR(errno, "%s waitpid pid %d in waitstopped %d status 0x%x %s\n",
-               msg, pid, p, status, status_image (status));
+               msg, pid, p, (unsigned)status, status_image (status));
          return False;
       }
 
@@ -867,7 +867,7 @@ Bool invoker_invoke_gdbserver (pid_t pid)
         web search '[patch] Fix syscall restarts for amd64->i386 biarch'
         e.g. http://sourceware.org/ml/gdb-patches/2009-11/msg00592.html */
      *(long *)&user_save.regs.rax = *(int*)&user_save.regs.rax;
-     DEBUG(1, "Sign extending %8.8lx to %8.8lx\n",
+     DEBUG(1, "Sign extending %8.8llx to %8.8llx\n",
            user_mod.regs.rax, user_save.regs.rax);
    }
 #elif defined(VGA_arm)
index 409ceac5d65cbc13dcfe8e819d7712c8dd8faecf..dab425d6804e21f33939f4c7a2069d3e828d46f1 100644 (file)
@@ -732,7 +732,7 @@ getpkt(char *buf, int fromfd, int ackfd)
         break;
 
      TSFPRINTF(stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
-               (c1 << 4) + c2, csum, buf);
+               (unsigned)((c1 << 4) + c2), (unsigned)csum, buf);
      ssize_t res = 0;
      while (res == 0) {
         res = write(ackfd, "-", 1);
@@ -1080,7 +1080,7 @@ receive_packet_start:
 
    if (!(csum == (c1 << 4) + c2)) {
       TSFPRINTF(stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
-                (c1 << 4) + c2, csum, buf);
+                (unsigned)((c1 << 4) + c2), (unsigned)csum, buf);
       if (!noackmode)
          if (!write_to_gdb ("-", 1))
             return -1;
index bb921019319b6f8810b25485acb6224562e9006c..73b802efce05ecad8750ac1bc9be3c63e77c3638 100644 (file)
@@ -1556,7 +1556,14 @@ sem_t* sem_open_intercept(const char *name, int oflag, mode_t mode,
    CALL_FN_W_WWWW(ret, fn, name, oflag, mode, value);
    // To do: figure out why gcc 9.2.1 miscompiles this function if the printf()
    // call below is left out.
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-zero-length"
+#endif
    printf("");
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
    VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ_DRD_POST_SEM_OPEN,
                                    ret != SEM_FAILED ? ret : 0,
                                    name, oflag, mode, value);
index e639abca843c892d5f1a02b4141a826dcae5c6cc..b1082cd4b923297462ec55500f5fa99b0703df4e 100644 (file)
@@ -3550,7 +3550,7 @@ PTH_FUNC(sem_t*, semZuopen,
 
    if (TRACE_SEM_FNS) {
       fprintf(stderr, "<< sem_open(\"%s\",%ld,%lx,%lu) ",
-                      name,oflag,mode,value);
+                      name,oflag,(unsigned long)mode,value);
       fflush(stderr);
    }
 
@@ -3790,7 +3790,7 @@ static long QMutex_tryLock_WRK(void* self)
                 void *, self, long, (ret & 0xFF) ? True : False);
 
    if (TRACE_QT4_FNS) {
-      fprintf(stderr, " :: Q::tryLock -> %lu >>\n", ret);
+      fprintf(stderr, " :: Q::tryLock -> %ld >>\n", ret);
    }
    
    return ret;
@@ -3827,7 +3827,7 @@ static long QMutex_tryLock_int_WRK(void* self, long arg2)
                void *, self, long, (ret & 0xFF) ? True : False);
 
    if (TRACE_QT4_FNS) {
-      fprintf(stderr, " :: Q::tryLock(int) -> %lu >>\n", ret);
+      fprintf(stderr, " :: Q::tryLock(int) -> %ld >>\n", ret);
    }
    
    return ret;
index ded4ab174775cc19fea2e7fba3bd8b2ada18b92d..d406da76bddbd9bc01a0ff3144b1b8851e62ad51 100644 (file)
@@ -48,7 +48,7 @@ vbit_test_CPPFLAGS     = $(AM_CPPFLAGS_PRI) \
                          -I$(top_srcdir)/include  \
                          -I$(top_srcdir)/memcheck \
                          -I$(top_srcdir)/VEX/pub
-vbit_test_CFLAGS       = $(AM_CFLAGS_PRI)
+vbit_test_CFLAGS       = $(AM_CFLAGS_PRI) -fhosted
 vbit_test_DEPENDENCIES = $(top_builddir)/VEX/libvex-@VGCONF_ARCH_PRI@-@VGCONF_OS@.a
 vbit_test_LDADD        = $(top_builddir)/VEX/libvex-@VGCONF_ARCH_PRI@-@VGCONF_OS@.a
 vbit_test_LDFLAGS      = $(AM_CFLAGS_PRI) @LIB_UBSAN@
@@ -67,7 +67,7 @@ vbit_test_sec_CPPFLAGS     = $(AM_CPPFLAGS_SEC) \
                              -I$(top_srcdir)/include  \
                              -I$(top_srcdir)/memcheck \
                              -I$(top_srcdir)/VEX/pub
-vbit_test_sec_CFLAGS       = $(AM_CFLAGS_SEC) \
+vbit_test_sec_CFLAGS       = $(AM_CFLAGS_SEC) -fhosted \
                              $(AM_CFLAGS_@VGCONF_PLATFORM_SEC_CAPS@)
 vbit_test_sec_DEPENDENCIES = $(top_builddir)/VEX/libvex-@VGCONF_ARCH_SEC@-@VGCONF_OS@.a \
                              $(TOOL_LDADD_@VGCONF_PLATFORM_SEC_CAPS@)
index 4755ce41ccd9a6a1fb8d66279fdd55ec1bf9ba81..33c78fef1a245f5dafd49132aee7c80bba009d14 100644 (file)
@@ -1449,6 +1449,6 @@ get_irop(IROp op)
       }
    }
 
-   fprintf(stderr, "unknown opcode %d\n", op);
+   fprintf(stderr, "unknown opcode %u\n", (unsigned)op);
    exit(1);
 }
index 61d4f3196333e9ca5bac1a58ff2c4fbd4e85451d..9d3ee3a291bace49c90433fae969c4b21f369c8e 100644 (file)
@@ -29,7 +29,7 @@ disasm_test_SOURCES      = $(SOURCES)
 disasm_test_CPPFLAGS     = $(AM_CPPFLAGS_PRI) \
                            -I$(top_srcdir)/VEX/pub \
                            -I$(top_srcdir)/VEX/priv
-disasm_test_CFLAGS       = $(AM_CFLAGS_PRI)
+disasm_test_CFLAGS       = $(AM_CFLAGS_PRI) -fhosted
 disasm_test_DEPENDENCIES = $(top_builddir)/VEX/libvex-@VGCONF_ARCH_PRI@-@VGCONF_OS@.a
 disasm_test_LDADD        = $(top_builddir)/VEX/libvex-@VGCONF_ARCH_PRI@-@VGCONF_OS@.a
 disasm_test_LDFLAGS      = $(AM_CFLAGS_PRI) @LIB_UBSAN@
index 6acf25ec7b6d70d00f98d7ba39b3101d9de9ae6f..ef064913343914eec3b5a3375cebc4419068d137 100644 (file)
@@ -1968,7 +1968,7 @@ parse_opcode(const char *spec)
       printf("opcode: |%s|\n", opc->name);
       for (unsigned i = 0; i < opc->num_opnds; ++i) {
          const opnd *d = opc->opnds + i;
-         printf("opnd %2d: %-8s  type: %-5s", i, d->name,
+         printf("opnd %2u: %-8s  type: %-5s", i, d->name,
                 opnd_kind_as_string(d->kind));
          if (d->kind != OPND_D12XB && d->kind != OPND_D12B &&
              d->kind != OPND_D20XB && d->kind != OPND_D20B &&