From: Florian Krohm Date: Thu, 15 May 2025 21:42:19 +0000 (+0000) Subject: Compile code that gets linked with libc by adding -fhosted. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b429488ff5aa59bc684d48755bf6e6d866262cd7;p=thirdparty%2Fvalgrind.git Compile code that gets linked with libc by adding -fhosted. 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. --- diff --git a/auxprogs/Makefile.am b/auxprogs/Makefile.am index 3a2d0d176..4a10fb1cf 100644 --- a/auxprogs/Makefile.am +++ b/auxprogs/Makefile.am @@ -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 diff --git a/auxprogs/valgrind-di-server.c b/auxprogs/valgrind-di-server.c index 1b6506e3d..a7607c069 100644 --- a/auxprogs/valgrind-di-server.c +++ b/auxprogs/valgrind-di-server.c @@ -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); diff --git a/auxprogs/valgrind-listener.c b/auxprogs/valgrind-listener.c index 158f11c08..5607e138d 100644 --- a/auxprogs/valgrind-listener.c +++ b/auxprogs/valgrind-listener.c @@ -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); diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am index 784459569..4ead1542b 100644 --- a/coregrind/Makefile.am +++ b/coregrind/Makefile.am @@ -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 diff --git a/coregrind/vgdb-invoker-ptrace.c b/coregrind/vgdb-invoker-ptrace.c index 3a6a455d0..a6df5dc07 100644 --- a/coregrind/vgdb-invoker-ptrace.c +++ b/coregrind/vgdb-invoker-ptrace.c @@ -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) diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 409ceac5d..dab425d68 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -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; diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c index bb9210193..73b802efc 100644 --- a/drd/drd_pthread_intercepts.c +++ b/drd/drd_pthread_intercepts.c @@ -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); diff --git a/helgrind/hg_intercepts.c b/helgrind/hg_intercepts.c index e639abca8..b1082cd4b 100644 --- a/helgrind/hg_intercepts.c +++ b/helgrind/hg_intercepts.c @@ -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; diff --git a/memcheck/tests/vbit-test/Makefile.am b/memcheck/tests/vbit-test/Makefile.am index ded4ab174..d406da76b 100644 --- a/memcheck/tests/vbit-test/Makefile.am +++ b/memcheck/tests/vbit-test/Makefile.am @@ -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@) diff --git a/memcheck/tests/vbit-test/irops.c b/memcheck/tests/vbit-test/irops.c index 4755ce41c..33c78fef1 100644 --- a/memcheck/tests/vbit-test/irops.c +++ b/memcheck/tests/vbit-test/irops.c @@ -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); } diff --git a/none/tests/s390x/disasm-test/Makefile.am b/none/tests/s390x/disasm-test/Makefile.am index 61d4f3196..9d3ee3a29 100644 --- a/none/tests/s390x/disasm-test/Makefile.am +++ b/none/tests/s390x/disasm-test/Makefile.am @@ -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@ diff --git a/none/tests/s390x/disasm-test/opcode.c b/none/tests/s390x/disasm-test/opcode.c index 6acf25ec7..ef0649133 100644 --- a/none/tests/s390x/disasm-test/opcode.c +++ b/none/tests/s390x/disasm-test/opcode.c @@ -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 &&