From patchwork Sun May 24 00:09:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 135508 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAFBA4BAE7E5 for ; Sun, 24 May 2026 00:11:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAFBA4BAE7E5 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=bGVtG5Zs X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 4A6654BAE7C1 for ; Sun, 24 May 2026 00:10:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A6654BAE7C1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4A6654BAE7C1 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2607:f8b0:4864:20::1035 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1779581426; cv=pass; b=xeVyalvkUljc1ejfKZU5aFFCxa4UmvEvdYBwVuE7FA7DICpckY17TTFwNNm0327h6ABhquPQKh84W3pjFPPnRW1QdZ7UsSg3UBC3dxficWSWN68v50zbWfI7Fcb+WrWLsxd4mF4OlH4BoM5AGRUByq4VE3Ra+Gr/u4ui4SF38fs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1779581426; c=relaxed/simple; bh=fFdK2xMhIuePFwqgV/DkQVOp2jwHZ3dh6LQHSM/KkkQ=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=s3Ry57n4NJBmuTot3EsrHopJNDtR0vbgpTjW3fLC2fAg2SIU4fHjnBgRYX36eJajhul3mk3J0R53ZQJYqdM2RhKbU4kDqsVrUQjeRXVtbo4ClVR4ygP4Uu0uqtX+OQqO7KMYfMEUsuaMCSXKU09U5KtBbnMBM+DSo4PFdLLYSCM= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=bGVtG5Zs DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A6654BAE7C1 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-3680540a6efso4764075a91.2 for ; Sat, 23 May 2026 17:10:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1779581425; cv=none; d=google.com; s=arc-20240605; b=U2IhwzcWeQXbaz0BPFCaa+okWZx6e0+JjWBEYH7f52LDpqZr+u3//AN7vL34jlO0EJ DlWlbMbqBRTyFOdiRTw1KulNeQG7DZfiFMMBWZ3GH9v/18ZfQmXqdMK/h4O0DXY+ojTf BRMNZJritPX7BJNV6JcjGZchAkftYRDocigQ+DJ1jbe/R5TXGZAyUKM8Pup+YjmzKIwS Jg/os6jcrvqX69/T7WXPoevyj/L20EDrHSBJ0/UkunAehfGggr5KpeT1zRxUQR6QTNLx UpPkI+sgO5LkBWL1Bi4bQtrz9gcP16k3u9Q2dlZNky5V8+TXQyxeSUOOE33MDwb4HV0R ST9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=fJNHVv6EyYM8QQX6Q0HvGpBm6TVj/JdWCfQjllnQg+8=; fh=apbHyaSyQwxqE2QYizyZGDHjt8RXpbk42B88awIMbII=; b=fHdwKaVEqU7Z3P5/SykpLUDxD2/gEpntA/Za/qM4CcVk+8uTMbyDXcqd9wG8IuZQXZ WDU9LMJWnjmifJFnON/p5urI8pZY2cRWgssTSL/YWBsoZee5dIo3HK1wf8m1LIWqDyvH 42oj91PV4wuZXgpXTmp+J6fNch9//W3MXigoeOPSVs4hZW4lk8n3kJ1V7qIWIKmlp/JH 1eJU7XHf2wGObhcMBxzsj/4u4Ez985fa2ZB34MjlH87ru9DgR6yPGF1nQgBWYt9xbJKW h6b5rJt1VLGmEd3KUPe+IZ2kUElTysW716sbO4J8lw1ZCbsOr7DaWl9yd7lK3+MlJ7WZ 98eA==; darn=sourceware.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779581425; x=1780186225; darn=sourceware.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fJNHVv6EyYM8QQX6Q0HvGpBm6TVj/JdWCfQjllnQg+8=; b=bGVtG5Zs5n6ESwj7K6b2bIURFhbLK0ghkJ8SZBTSeTNq+CxQxRKehdrQp5RjvXUvLk KTieJ9fpWv/YR49s1SB6aZI3UaNLR2sYvXk6aFKjScv3DfDXCXt9sorZkTeRHqehMoyf 1yhchbSr464gEhui08rw3eCPeSs2DAEjH1o4fM95hmbZePvOM474K77D7VaEgtBvBjem puxM9g1nd13VBTpffyWozuc0OeMipVa6NlfOa5T0nK8PIltzPIveOxCtd+HD21iW9mmU vKQZwNeKVdL1OKTYOi6vw3xBr64c8KM9Xx75KxEsXTEiflimNIrHO0KdAt9XLuXywDM4 vFyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779581425; x=1780186225; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fJNHVv6EyYM8QQX6Q0HvGpBm6TVj/JdWCfQjllnQg+8=; b=B4KjpSCKj9hjT17JdsaQNQc08mHmtV/HNylJUTfWKvTh22j+DrM5/LhP+yDY7bAUdh ttYY1q2zJlL/8UcYakTfts16HtwM0505GY5Kg9TCT5rCm9TclM0igbGjGuEgaPtf8BzS lYYxyNrFH3jlFwq2G007VJYTFUy9r/QBQA7oJEgRr/rmvPCYeqU++JGn3XdaiH73HOfW 3fXdTCB9BTXHnKIl0gfhZx9TPulkYjLI94cWTkTS01zocFyNFSKv6VtCS2ZGsmn7K+5j /gML1ps4H47LP917bpsIpUgnM0e1vcccQOV1J0r+NWbYFLxWZjMstIsbG5jGn381k/5K CIQw== X-Gm-Message-State: AOJu0Yw7Cg9AgqcvEfRRqzNlnZCCjhyVuii8Q9/KkMuN8r2csN377tO5 ADY7+7eZG2vJrLE+S0bh4CmBf2Fe/t53PHHTchJ0pnD2IxrEuInDOQ323MeaTIesWe8wLiY8AA6 vMg+UN65HowuVmrZKLU/lOJoIIaSgSFg= X-Gm-Gg: Acq92OH/qAJoAYD17PvipwXSM9EF63bGRMXWJD/f/XDaulQc0lN/jIGhs2emRbGSkPW mxiE66lcZ/D3FPDr+UI3/lTAxSR8pRR8q0haGw7jSOgVRp04KuCDJXO/7uLwqzcEyhkPWUL3bZP VLarqNESU4pVhb8EPP7oNKglxV5qzTLt9oUC3bi7lR836Mt6FdlXjSQUg1ihbKE0ylElzfCPWlL P6b3SxZYYb0qnVezJxkb5oN4DeIJR5hIesNB+3y56Emmzv3tJiqBWQVs07bznuUo9OxQfByKS0J Y7bRQc9kkWOw6fzG X-Received: by 2002:a17:90b:2cc4:b0:368:ac5f:d31b with SMTP id 98e67ed59e1d1-36a6764631amr8400527a91.24.1779581424981; Sat, 23 May 2026 17:10:24 -0700 (PDT) MIME-Version: 1.0 References: <9a6fd40f-1081-41e3-8050-e000ba78fcfb@suse.com> <916dde10-59ed-4180-86e6-a42677b90c20@suse.com> In-Reply-To: <916dde10-59ed-4180-86e6-a42677b90c20@suse.com> From: "H.J. Lu" Date: Sun, 24 May 2026 08:09:47 +0800 X-Gm-Features: AVHnY4Lcoc2cItqXe9_WPN5RHT2v3bxUcDjKiJZuHeUuYI0Bq1Yq3fe0hm5A2OA Message-ID: Subject: [PATCH] x86: Pass "%s" to i386_dis_printf as the format string To: Jan Beulich Cc: Binutils , Nick Clifton X-Spam-Status: No, score=-3010.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org On Fri, May 15, 2026 at 9:08 PM Jan Beulich wrote: > > Model this after operand handling, such that comments can be emitted in > the same order as operands. %rip-relative address comments remain > separate for now. While there correct style for the symbols associated > with immediates: These aren't "comment starts", but symbol names. > --- > As long as we want to continue to use the ->print_address_func() hook, > properly unifying %rip-relative comments with others won't be possible. > That, however, is in line with direct addresses also getting printed > specially, similarly by using ->print_address_func(). > > Was it really intended for the original -Mannotate test to be run only for > Linux targets? It certainly isn't intended here, yet I'd like the new > tests to be in the same directory as the original one. x86-64.exp, > however, bails right away for non-Linux (and remote hosts). I guess at > least the *.d based testing loop should be moved up. Tests truly only > working for Linux can easily be constrained in the *.d files themselves. > > --- /dev/null > +++ b/binutils/testsuite/binutils-all/x86-64/comments.d > @@ -0,0 +1,14 @@ > +#name: disassembly comments (AT&T) > +#ld: > +#objdump: -dwMannotate,att > + > +.*: +file format .* > + > + > +Disassembly of section .text: > + > +[0-9a-f]+ <_start>: > +[ ]*[0-9a-f]+: 48 c7 05 [0-9a-f ]+ movq \$0x[0-9a-f]+,0x[0-9a-f]+\(%rip\) +# \[_start\], [0-9a-f]+ > +[ ]*[0-9a-f]+: 31 c0 xor %eax,%eax > +[ ]*[0-9a-f]+: c3 ret > +#pass > --- /dev/null > +++ b/binutils/testsuite/binutils-all/x86-64/comments.s > @@ -0,0 +1,9 @@ > + .text > + .global _start > +_start: > + movq $_start, fptr(%rip) > + xor %eax, %eax > + ret > + > + .data > +fptr: .quad -1 > --- /dev/null > +++ b/binutils/testsuite/binutils-all/x86-64/comments-intel.d > @@ -0,0 +1,14 @@ > +#name: disassembly comments (Intel) > +#source: comments.s > +#ld: > +#objdump: -dwMannotate,intel > + > +.*: +file format .* > + > + > +Disassembly of section .text: > + > +[0-9a-f]+ <_start>: > +[ ]*[0-9a-f]+: 48 c7 05 [0-9a-f ]+ mov QWORD PTR \[rip\+0x[0-9a-f]+\],0x[0-9a-f]+ +# [0-9a-f]+ , \[_start\] > +[ ]*[0-9a-f]+: 31 c0 xor eax,eax > +[ ]*[0-9a-f]+: c3 ret > --- a/opcodes/i386-dis.c > +++ b/opcodes/i386-dis.c > @@ -179,8 +179,7 @@ struct instr_info > > char obuf[MAX_OPERAND_BUFFER_SIZE]; > char *obufp; > - char cbuf[COMMENT_BUFFER_SIZE]; > - char * cbufp; > + char *cbufp; > char *mnemonicendp; > const uint8_t *start_codep; > uint8_t *codep; > @@ -258,6 +257,7 @@ struct instr_info > signed char op_index[MAX_OPERANDS]; > bool op_riprel[MAX_OPERANDS]; > char *op_out[MAX_OPERANDS]; > + char *cm_out[MAX_OPERANDS]; > bfd_vma op_address[MAX_OPERANDS]; > bfd_vma start_pc; > > @@ -9749,7 +9749,6 @@ print_insn (bfd_vma pc, disassemble_info > .start_codep = priv.the_buffer, > .codep = priv.the_buffer, > .obufp = ins.obuf, > - .cbufp = ins.cbuf, > .last_lock_prefix = -1, > .last_repz_prefix = -1, > .last_repnz_prefix = -1, > @@ -9761,6 +9760,7 @@ print_insn (bfd_vma pc, disassemble_info > .fwait_prefix = -1, > }; > char op_out[MAX_OPERANDS][MAX_OPERAND_BUFFER_SIZE]; > + char cm_out[MAX_OPERANDS][COMMENT_BUFFER_SIZE]; > > priv.orig_sizeflag = AFLAG | DFLAG; > if ((info->mach & bfd_mach_i386_i386) != 0) > @@ -9874,6 +9874,8 @@ print_insn (bfd_vma pc, disassemble_info > { > op_out[i][0] = 0; > ins.op_out[i] = op_out[i]; > + cm_out[i][0] = 0; > + ins.cm_out[i] = cm_out[i]; > } > > sizeflag = priv.orig_sizeflag; > @@ -9992,6 +9994,7 @@ print_insn (bfd_vma pc, disassemble_info > for (i = 0; i < MAX_OPERANDS; ++i) > { > ins.obufp = ins.op_out[i]; > + ins.cbufp = ins.cm_out[i]; > ins.op_ad = MAX_OPERANDS - 1 - i; > if (dp->op[i].rtn > && !dp->op[i].rtn (&ins, dp->op[i].bytemode, sizeflag)) > @@ -10317,6 +10320,10 @@ print_insn (bfd_vma pc, disassemble_info > riprel = ins.op_riprel[i]; > ins.op_riprel[i] = ins.op_riprel[MAX_OPERANDS - 1 - i]; > ins.op_riprel[MAX_OPERANDS - 1 - i] = riprel; > + > + char *tmp = ins.cm_out[i]; > + ins.cm_out[i] = ins.cm_out[MAX_OPERANDS - 1 - i]; > + ins.cm_out[MAX_OPERANDS - 1 - i] = tmp; > } > } > else > @@ -10364,22 +10371,23 @@ print_insn (bfd_vma pc, disassemble_info > needcomma = 1; > } > > + const char *sep = " # "; > for (i = 0; i < MAX_OPERANDS; i++) > if (ins.op_index[i] != -1 && ins.op_riprel[i]) > { > - i386_dis_printf (info, dis_style_comment_start, " # "); > + i386_dis_printf (info, dis_style_comment_start, sep); > + sep = ", "; > (*info->print_address_func) > ((bfd_vma)(ins.start_pc + (ins.codep - ins.start_codep) > + ins.op_address[ins.op_index[i]]), > - info); > - break; > + info); > + } > + else if (*ins.cm_out[i]) > + { > + i386_dis_printf (info, dis_style_comment_start, sep); > + sep = ", "; > + i386_dis_printf (info, dis_style_symbol, "%s", ins.cm_out[i]); > } > - if (ins.cbufp != ins.cbuf) > - { > - if (i == MAX_OPERANDS) > - i386_dis_printf (info, dis_style_comment_start, " # "); > - i386_dis_printf (info, dis_style_comment_start, "%s", ins.cbuf); > - } > > ret = ins.codep - priv.the_buffer; > out: > @@ -10760,6 +10768,7 @@ dofloat (instr_info *ins, int sizeflag) commit aeced13ee0cd570d78cb37ab1f9bba840958515a Author: Jan Beulich Date: Fri May 22 08:49:12 2026 +0200 x86/disasm: rework comment handling caused: libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../opcodes -I. -I../../opcodes -I../bfd -I../../opcodes/../include -I../../opcodes/../bfd -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m32 -march=i686 -mtune=generic -msse2 -mfpmath=sse -mstackrealign -fasynchronous-unwind-tables -fstack-clash-protection -mtls-dialect=gnu -flto=8 -std=gnu11 -fprofile-generate -flto=jobserver -ffat-lto-objects -MT i386-dis.lo -MD -MP -MF .deps/i386-dis.Tpo -c ../../opcodes/i386-dis.c -fPIC -DPIC -o .libs/i386-dis.o ../../opcodes/i386-dis.c: In function ‘print_insn’: ../../opcodes/i386-dis.c:10378:9: error: format not a string literal and no format arguments [-Werror=format-security] 10378 | i386_dis_printf (info, dis_style_comment_start, sep); | ^~~~~~~~~~~~~~~ ../../opcodes/i386-dis.c:10387:9: error: format not a string literal and no format arguments [-Werror=format-security] 10387 | i386_dis_printf (info, dis_style_comment_start, sep); | ^~~~~~~~~~~~~~~ cc1: some warnings being treated as errors make[4]: *** [Makefile:1076: i386-dis.lo] Error 1 Since i386_dis_printf is declared as static void ATTRIBUTE_PRINTF_3 i386_dis_printf (const disassemble_info *, enum disassembler_style, const char *, ...); the 3rd argument should be a string literal as the format string. Pass "%s" to i386_dis_printf as the format string to fix the regression. PR binutils/34168 * i386-dis.c (print_insn): Pass "%s" to i386_dis_printf as the format string. From 13bc2a41289071dad06f27330e30ec00b6122ba2 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 24 May 2026 08:04:26 +0800 Subject: [PATCH] x86: Pass "%s" to i386_dis_printf as the format string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit aeced13ee0cd570d78cb37ab1f9bba840958515a Author: Jan Beulich Date: Fri May 22 08:49:12 2026 +0200 x86/disasm: rework comment handling caused: libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../opcodes -I. -I../../opcodes -I../bfd -I../../opcodes/../include -I../../opcodes/../bfd -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m32 -march=i686 -mtune=generic -msse2 -mfpmath=sse -mstackrealign -fasynchronous-unwind-tables -fstack-clash-protection -mtls-dialect=gnu -flto=8 -std=gnu11 -fprofile-generate -flto=jobserver -ffat-lto-objects -MT i386-dis.lo -MD -MP -MF .deps/i386-dis.Tpo -c ../../opcodes/i386-dis.c -fPIC -DPIC -o .libs/i386-dis.o ../../opcodes/i386-dis.c: In function ‘print_insn’: ../../opcodes/i386-dis.c:10378:9: error: format not a string literal and no format arguments [-Werror=format-security] 10378 | i386_dis_printf (info, dis_style_comment_start, sep); | ^~~~~~~~~~~~~~~ ../../opcodes/i386-dis.c:10387:9: error: format not a string literal and no format arguments [-Werror=format-security] 10387 | i386_dis_printf (info, dis_style_comment_start, sep); | ^~~~~~~~~~~~~~~ cc1: some warnings being treated as errors make[4]: *** [Makefile:1076: i386-dis.lo] Error 1 Since i386_dis_printf is declared as static void ATTRIBUTE_PRINTF_3 i386_dis_printf (const disassemble_info *, enum disassembler_style, const char *, ...); the 3rd argument should be a string literal as the format string. Pass "%s" to i386_dis_printf as the format string to fix the regression. PR binutils/34168 * i386-dis.c (print_insn): Pass "%s" to i386_dis_printf as the format string. Signed-off-by: H.J. Lu --- opcodes/i386-dis.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index 1faf1fa7785..3a5db14a1dc 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -10375,7 +10375,7 @@ print_insn (bfd_vma pc, disassemble_info *info, int intel_syntax) for (i = 0; i < MAX_OPERANDS; i++) if (ins.op_index[i] != -1 && ins.op_riprel[i]) { - i386_dis_printf (info, dis_style_comment_start, sep); + i386_dis_printf (info, dis_style_comment_start, "%s", sep); sep = ", "; (*info->print_address_func) ((bfd_vma)(ins.start_pc + (ins.codep - ins.start_codep) @@ -10384,7 +10384,7 @@ print_insn (bfd_vma pc, disassemble_info *info, int intel_syntax) } else if (*ins.cm_out[i]) { - i386_dis_printf (info, dis_style_comment_start, sep); + i386_dis_printf (info, dis_style_comment_start, "%s", sep); sep = ", "; i386_dis_printf (info, dis_style_symbol, "%s", ins.cm_out[i]); } -- 2.54.0