From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by sourceware.org (Postfix) with ESMTPS id F289E396DC20 for ; Thu, 28 May 2020 19:59:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F289E396DC20 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04SJtgbe036230 for ; Thu, 28 May 2020 19:59:25 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 318xe1q135-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 28 May 2020 19:59:25 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04SJrfGs078451 for ; Thu, 28 May 2020 19:57:25 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 317j5w8wyv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 May 2020 19:57:24 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 04SJvO55011062 for ; Thu, 28 May 2020 19:57:24 GMT Received: from termi.oracle.com (/10.175.24.68) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 28 May 2020 12:57:23 -0700 From: "Jose E. Marchesi" To: binutils@sourceware.org Subject: [COMMITTED][BPF] bfd: fix handling of R_BPF_INSN_{32, 64} relocations. Date: Thu, 28 May 2020 21:57:10 +0200 Message-ID: <87a71r4yuh.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9635 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 suspectscore=1 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005280131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9635 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 adultscore=0 cotscore=-2147483648 mlxscore=0 bulkscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 impostorscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005280131 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 28 May 2020 19:59:27 -0000 Just pushed the patch below on behalf of David Faust. Salud! Author: David Faust Date: Thu May 28 20:53:29 2020 +0200 bfd: fix handling of R_BPF_INSN_{32,64} relocations. 2020-05-28 David Faust * elf64-bpf.c (bpf_elf_relocate_section): Fix handling of R_BPF_INSN_{32,64} relocations. diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 482bf81e68..05452c5d46 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2020-05-28 David Faust + + * elf64-bpf.c (bpf_elf_relocate_section): Fix handling of + R_BPF_INSN_{32,64} relocations. + 2020-05-28 Stephen Casner * pdp11.c: Implement BRD_RELOC_32 to relocate the low 16 bits of diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c index bf488af81f..641caa1f05 100644 --- a/bfd/elf64-bpf.c +++ b/bfd/elf64-bpf.c @@ -64,7 +64,7 @@ static reloc_howto_type bpf_elf_howto_table [] = MINUS_ONE, /* dst_mask */ TRUE), /* pcrel_offset */ - /* 32-immediate in LDDW instruction. */ + /* 32-immediate in many instructions. Note: handled manually. */ HOWTO (R_BPF_INSN_32, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ @@ -460,6 +460,31 @@ bpf_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, r = bfd_reloc_ok; break; } + case R_BPF_INSN_32: + { + /* Write relocated value */ + bfd_put (howto->bitsize, input_bfd, relocation, + contents + rel->r_offset + 4); + + r = bfd_reloc_ok; + break; + } + case R_BPF_INSN_64: + { + /* + LDDW instructions are 128 bits long, with a 64-bit immediate. + The lower 32 bits of the immediate are in the same position + as the imm32 field of other instructions. + The upper 32 bits of the immediate are stored at the end of + the instruction. + */ + bfd_put (32, input_bfd, (relocation & 0xFFFFFFFF), + contents + rel->r_offset + 4); + bfd_put (32, input_bfd, (relocation >> 32), + contents + rel->r_offset + 12); + r = bfd_reloc_ok; + break; + } default: r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents, rel->r_offset, relocation,