From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SGIVMVnOjmA8JgAAWB0awg (envelope-from ) for ; Sun, 02 May 2021 12:07:53 -0400 Received: by simark.ca (Postfix, from userid 112) id C76041F11C; Sun, 2 May 2021 12:07:53 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9232B1E54D for ; Sun, 2 May 2021 12:07:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09FE83894416; Sun, 2 May 2021 16:07:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09FE83894416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1619971672; bh=185FZ8uOmPn6hrz0kbAuWnKYzCRsTFJAS90dC/KFLqQ=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZXuSAsI5jLSwJX43HhANV4+RxtN7BIimClI/4E6qq/bYV3peDBdZZPEy1i6JnTa58 yKlniroRLLpoXunbtu6ASfNGPYSH5RpxCr2IzqJyUuOgAMxokPADpoVFw7CtyMkSrl iaJw+wgto5WcOpRYKGN/uw0jiL4YZE0BdvIGGjfk= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 428B8388A031 for ; Sun, 2 May 2021 16:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 428B8388A031 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 142G7gGN001268 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 2 May 2021 12:07:47 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 142G7gGN001268 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id CA1CD1E54D for ; Sun, 2 May 2021 12:07:42 -0400 (EDT) Subject: Re: [PATCH] sim: add ATTRIBUTE_PRINTF / ATTRIBUTE_NULL_PRINTF where necessary To: gdb-patches@sourceware.org References: <20210502152454.506379-1-simon.marchi@polymtl.ca> Message-ID: Date: Sun, 2 May 2021 12:07:42 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sun, 2 May 2021 16:07:42 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" yOn 2021-05-02 11:43 a.m., Mike Frysinger wrote: > On 02 May 2021 11:24, Simon Marchi via Gdb-patches wrote: >> I finally got the all-targets sim building with Clang, these are all the >> instances where an ATTRIBUTE_PRINTF or ATTRIBUTE_NULL_PRINTF attribute >> needed to be added to avoid errors like: >> >> /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-profile.c:464:19: error: format string is not a string literal [-Werror,-Wformat-nonliteral] >> vfprintf (fp, fmt, ap); >> ^~~ >> There are more fixes needed to get everything building, but adding these >> attributes is trivial enough, so I send them all in a single patch. > > lgtm, thanks > -mike Actually, I didn't try rebuilding with GCC before sending the patch, I did now and realized this would have broken the build. See updated patch below. >From 80e57ebfa4ad3ea1bb2b03d21c2c549e42903e20 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sun, 2 May 2021 11:55:45 -0400 Subject: [PATCH] sim: add ATTRIBUTE_PRINTF / ATTRIBUTE_NULL_PRINTF where necessary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I finally got the all-targets sim building with Clang, these are all the instances where an ATTRIBUTE_PRINTF or ATTRIBUTE_NULL_PRINTF attribute needed to be added to avoid errors like: /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-profile.c:464:19: error: format string is not a string literal [-Werror,-Wformat-nonliteral] vfprintf (fp, fmt, ap); ^~~ There are more fixes needed to get everything building, but adding these attributes is trivial enough, so I send them all in a single patch. Adding the format attributes introduces some format string errors when building with GCC (because now format strings are checked), so corresponding changes are needed to avoid breaking the build. Other than simple format string specified changes, there is this one: /home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c: In function ‘hw_event_queue_schedule’: /home/simark/src/binutils-gdb/sim/aarch64/../common/hw-events.c:95:15: error: too many arguments for format [-Werror=format-extra-args] 95 | NULL, dummy); | ^~~~~ We can fix it and avoid using a dummy variable by simply calling hw_event_queue_schedule_tracef instead of hw_event_queue_schedule_vtracef. sim/arm/ChangeLog: * armdefs.h (ARMul_ConsolePrint): Use format attribute. * wrapper.c (op_printf): Likewise. sim/bfin/ChangeLog: * interp.c (sim_open): Adjust format string specifier. sim/common/ChangeLog: * hw-events.h (hw_event_queue_schedule_tracef): Use format attribute. (hw_event_queue_schedule_vtracef): Likewise. * hw-tree.h (hw_tree_vparse): Likewise. * sim-profile.c (profile_vprintf): Likewise. * sim-trace.c (dis_printf): Likewise. * sim-trace.h (trace_printf): Likewise. (trace_vprintf): Likewise. * sim-utils.h (sim_do_commandf): Likewise. * hw-events.c (hw_event_queue_schedule): Use hw_event_queue_schedule_tracef. sim/rx/ChangeLog: * trace.c (op_printf): Likewise. sim/v850/ChangeLog: * interp.c (sim_open): Adjust format string specifier. Change-Id: I1445115ce57db15bb8e35dca93014555e7555794 --- sim/arm/armdefs.h | 4 +++- sim/arm/wrapper.c | 4 ++-- sim/bfin/interp.c | 2 +- sim/common/hw-events.c | 7 +------ sim/common/hw-events.h | 4 ++-- sim/common/hw-tree.h | 2 +- sim/common/sim-profile.c | 2 +- sim/common/sim-trace.c | 2 +- sim/common/sim-trace.h | 5 +++-- sim/common/sim-utils.h | 3 ++- sim/rx/trace.c | 2 +- sim/v850/interp.c | 4 ++-- 12 files changed, 20 insertions(+), 21 deletions(-) diff --git a/sim/arm/armdefs.h b/sim/arm/armdefs.h index 2b5ff9b2dfa8..68cf199db6b3 100644 --- a/sim/arm/armdefs.h +++ b/sim/arm/armdefs.h @@ -18,6 +18,7 @@ #include #include #include +#include #define FALSE 0 #define TRUE 1 @@ -415,5 +416,6 @@ extern unsigned ARMul_OSHandleSWI (ARMul_State * state, ARMword number); extern void ARMul_UndefInstr (ARMul_State *, ARMword); extern void ARMul_FixCPSR (ARMul_State *, ARMword, ARMword); extern void ARMul_FixSPSR (ARMul_State *, ARMword, ARMword); -extern void ARMul_ConsolePrint (ARMul_State *, const char *, ...); +extern void ARMul_ConsolePrint (ARMul_State *, const char *, ...) + ATTRIBUTE_PRINTF (2, 3); extern void ARMul_SelectProcessor (ARMul_State *, unsigned); diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c index c89efe4ee971..54a04f424284 100644 --- a/sim/arm/wrapper.c +++ b/sim/arm/wrapper.c @@ -62,8 +62,8 @@ int trace_funcs = 0; static struct disassemble_info info; static char opbuf[1000]; -static int -op_printf (char *buf, char *fmt, ...) +static int ATTRIBUTE_PRINTF (2, 3) +op_printf (char *buf, const char *fmt, ...) { int ret; va_list ap; diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index 2aa9279aef89..a4333daa44dd 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -747,7 +747,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, if (sim_core_read_buffer (sd, NULL, read_map, &c, 4, 1) == 0) { bu16 emuexcpt = 0x25; - sim_do_commandf (sd, "memory-size 0x%lx", BFIN_DEFAULT_MEM_SIZE); + sim_do_commandf (sd, "memory-size 0x%x", BFIN_DEFAULT_MEM_SIZE); sim_write (sd, 0, (void *)&emuexcpt, 2); } diff --git a/sim/common/hw-events.c b/sim/common/hw-events.c index 1c749dd8c27c..81628f0b642f 100644 --- a/sim/common/hw-events.c +++ b/sim/common/hw-events.c @@ -88,12 +88,7 @@ hw_event_queue_schedule (struct hw *me, hw_event_callback *callback, void *data) { - struct hw_event *event; - va_list dummy; - memset (&dummy, 0, sizeof dummy); - event = hw_event_queue_schedule_vtracef (me, delta_time, callback, data, - NULL, dummy); - return event; + return hw_event_queue_schedule_tracef (me, delta_time, callback, data, NULL); } struct hw_event * diff --git a/sim/common/hw-events.h b/sim/common/hw-events.h index 901063b73da2..51ca5bdb2f04 100644 --- a/sim/common/hw-events.h +++ b/sim/common/hw-events.h @@ -39,7 +39,7 @@ struct hw_event *hw_event_queue_schedule_tracef hw_event_callback *handler, void *data, const char *fmt, - ...) ATTRIBUTE_PRINTF (5, 6); + ...) ATTRIBUTE_NULL_PRINTF (5, 6); struct hw_event *hw_event_queue_schedule_vtracef (struct hw *me, @@ -47,7 +47,7 @@ struct hw_event *hw_event_queue_schedule_vtracef hw_event_callback *handler, void *data, const char *fmt, - va_list ap); + va_list ap) ATTRIBUTE_NULL_PRINTF (5, 0); void hw_event_queue_deschedule diff --git a/sim/common/hw-tree.h b/sim/common/hw-tree.h index 86ebf1709cad..85c91ad96521 100644 --- a/sim/common/hw-tree.h +++ b/sim/common/hw-tree.h @@ -39,7 +39,7 @@ struct hw *hw_tree_parse struct hw *hw_tree_vparse (struct hw *root, const char *fmt, - va_list ap); + va_list ap) ATTRIBUTE_PRINTF (2, 0); void hw_tree_finish diff --git a/sim/common/sim-profile.c b/sim/common/sim-profile.c index 75bdc70298cc..455e1a246d93 100644 --- a/sim/common/sim-profile.c +++ b/sim/common/sim-profile.c @@ -454,7 +454,7 @@ profile_option_handler (SIM_DESC sd, /* Profiling output hooks. */ -static void +static void ATTRIBUTE_PRINTF (3, 0) profile_vprintf (SIM_DESC sd, sim_cpu *cpu, const char *fmt, va_list ap) { FILE *fp = PROFILE_FILE (CPU_PROFILE_DATA (cpu)); diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c index 5f161da630bb..26d9556322cf 100644 --- a/sim/common/sim-trace.c +++ b/sim/common/sim-trace.c @@ -889,7 +889,7 @@ dis_read (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, return 0; } -static int +static int ATTRIBUTE_PRINTF (2, 3) dis_printf (SIM_CPU *cpu, const char *fmt, ...) { SIM_DESC sd = CPU_STATE (cpu); diff --git a/sim/common/sim-trace.h b/sim/common/sim-trace.h index 7ff7b021b337..c89084e94401 100644 --- a/sim/common/sim-trace.h +++ b/sim/common/sim-trace.h @@ -653,9 +653,10 @@ do { \ extern void trace_printf (SIM_DESC, sim_cpu *, const char *, ...) - ATTRIBUTE_PRINTF (3, 4); + ATTRIBUTE_PRINTF (3, 4); -extern void trace_vprintf (SIM_DESC, sim_cpu *, const char *, va_list); +extern void trace_vprintf (SIM_DESC, sim_cpu *, const char *, va_list) + ATTRIBUTE_PRINTF (3, 0); /* Debug support. This is included here because there isn't enough of it to justify diff --git a/sim/common/sim-utils.h b/sim/common/sim-utils.h index f089245f25e4..9cc19f5567bc 100644 --- a/sim/common/sim-utils.h +++ b/sim/common/sim-utils.h @@ -68,7 +68,8 @@ struct bfd *sim_load_file (SIM_DESC sd, const char *myname, int lma_p, sim_write_fn do_load); /* Internal version of sim_do_command, include formatting */ -void sim_do_commandf (SIM_DESC sd, const char *fmt, ...); +void sim_do_commandf (SIM_DESC sd, const char *fmt, ...) + ATTRIBUTE_PRINTF (2, 3); /* These are defined in callback.c as cover functions to the vprintf diff --git a/sim/rx/trace.c b/sim/rx/trace.c index caa51b794dfc..a005797b4ecb 100644 --- a/sim/rx/trace.c +++ b/sim/rx/trace.c @@ -96,7 +96,7 @@ compare_symbols (const PTR ap, const PTR bp) static char opbuf[1000]; -static int +static int ATTRIBUTE_PRINTF (2, 3) op_printf (char *buf, char *fmt, ...) { int ret; diff --git a/sim/v850/interp.c b/sim/v850/interp.c index e72dab645dd9..ff2f6a23e56d 100644 --- a/sim/v850/interp.c +++ b/sim/v850/interp.c @@ -215,9 +215,9 @@ sim_open (SIM_OPEN_KIND kind, /* Allocate core managed memory */ /* "Mirror" the ROM addresses below 1MB. */ - sim_do_commandf (sd, "memory region 0,0x100000,0x%lx", V850_ROM_SIZE); + sim_do_commandf (sd, "memory region 0,0x100000,0x%x", V850_ROM_SIZE); /* Chunk of ram adjacent to rom */ - sim_do_commandf (sd, "memory region 0x100000,0x%lx", V850_LOW_END-0x100000); + sim_do_commandf (sd, "memory region 0x100000,0x%x", V850_LOW_END-0x100000); /* peripheral I/O region - mirror 1K across 4k (0x1000) */ sim_do_command (sd, "memory region 0xfff000,0x1000,1024"); /* similarly if in the internal RAM region */ -- 2.30.1