From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 97B423865C2A for ; Sat, 7 May 2022 09:13:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 97B423865C2A Received: by mail-pj1-x1030.google.com with SMTP id o69so9030702pjo.3 for ; Sat, 07 May 2022 02:13:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=UsjbbY1cxpHmmrHxOv+IisSVFoSS7LqNOPQzIx5XoN8=; b=zD1Mh5Z7zE1SgTEidtzTiL9h3yZwS/xVnLMkIyNDZfn9wCWes+LgU5ojalvNSWZYAI fu6UYGwJJOGeB8KkKGKNVMqdSJu8ZV7/AhadeLDl8XNMYFZOq/YFDW7O2GVo/LxrYCOl UVJ0JwXE2/U0mo2V4X6RtkRSFZ30Agfidyy/gcZ8v0qmWjmHR1VmOJlv7IV195pADKJj alB+2RsTbaAVlU/Avrba8Buls0No9sVLRm4jNDhB1LInjf/GT7OX2KQd7bHaN2buRLr9 Ph/2YDwnRtI0DJz2kxitFzNWN3mr2rcW/qiY+MmqIdCHOO5HpNI4k6bPiIP7FCo96Il7 MaAQ== X-Gm-Message-State: AOAM532+pc1dxI6kXc6AYeMuMUaQDwOXnfE7UBuS3tr9nUjNDqowMjsB Z3JevBZo9y7mAUl56SLiJJ7FYgXinNM= X-Google-Smtp-Source: ABdhPJwxErVw+/ehOAiI9aXboPBwvWjM9Jxn9PEvNZshCci/AHRq4Fvqp4/A27EcyGE+AjTZTaA+ow== X-Received: by 2002:a17:90b:17d0:b0:1dc:ddce:9c25 with SMTP id me16-20020a17090b17d000b001dcddce9c25mr7243006pjb.232.1651914834236; Sat, 07 May 2022 02:13:54 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:760e:9991:9e5b:99e2]) by smtp.gmail.com with ESMTPSA id a29-20020a056a001d1d00b0050dc7628158sm4735779pfx.50.2022.05.07.02.13.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 May 2022 02:13:53 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id ED9091143122; Sat, 7 May 2022 18:43:50 +0930 (ACST) Date: Sat, 7 May 2022 18:43:50 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Fix multiple ubsan warnings in i386-dis.c Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 May 2022 09:13:57 -0000 Commit 39fb369834a3 "opcodes: Make i386-dis.c thread-safe" introduced a number of casts to bfd_signed_vma that cause undefined behaviour with a 32-bit libbfd. Revert those changes. * i386-dis.c (OP_E_memory): Do not cast disp to bfd_signed_vma for negation. (get32, get32s): Don't use bfd_signed_vma here. diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index 1e3266329c1..6ef091ea7d7 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -11634,7 +11634,7 @@ OP_E_memory (instr_info *ins, int bytemode, int sizeflag) { *ins->obufp++ = '-'; *ins->obufp = '\0'; - disp = - (bfd_signed_vma) disp; + disp = -disp; } if (havedisp) @@ -11739,7 +11739,7 @@ OP_E_memory (instr_info *ins, int bytemode, int sizeflag) { *ins->obufp++ = '-'; *ins->obufp = '\0'; - disp = - (bfd_signed_vma) disp; + disp = -disp; } print_displacement (ins, ins->scratchbuf, disp); @@ -11905,28 +11905,28 @@ get64 (instr_info *ins ATTRIBUTE_UNUSED) static bfd_signed_vma get32 (instr_info *ins) { - bfd_signed_vma x = 0; + bfd_vma x = 0; FETCH_DATA (ins->info, ins->codep + 4); - x = *ins->codep++ & (bfd_signed_vma) 0xff; - x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 8; - x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 16; - x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 24; + x = *ins->codep++ & (bfd_vma) 0xff; + x |= (*ins->codep++ & (bfd_vma) 0xff) << 8; + x |= (*ins->codep++ & (bfd_vma) 0xff) << 16; + x |= (*ins->codep++ & (bfd_vma) 0xff) << 24; return x; } static bfd_signed_vma get32s (instr_info *ins) { - bfd_signed_vma x = 0; + bfd_vma x = 0; FETCH_DATA (ins->info, ins->codep + 4); - x = *ins->codep++ & (bfd_signed_vma) 0xff; - x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 8; - x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 16; - x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 24; + x = *ins->codep++ & (bfd_vma) 0xff; + x |= (*ins->codep++ & (bfd_vma) 0xff) << 8; + x |= (*ins->codep++ & (bfd_vma) 0xff) << 16; + x |= (*ins->codep++ & (bfd_vma) 0xff) << 24; - x = (x ^ ((bfd_signed_vma) 1 << 31)) - ((bfd_signed_vma) 1 << 31); + x = (x ^ ((bfd_vma) 1 << 31)) - ((bfd_vma) 1 << 31); return x; } -- Alan Modra Australia Development Lab, IBM