From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 51F703858D33 for ; Thu, 9 Mar 2023 11:41:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51F703858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-ot1-x32a.google.com with SMTP id r23-20020a05683001d700b00690eb18529fso858137ota.1 for ; Thu, 09 Mar 2023 03:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678362076; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=doR/FSWI3N6uWqCNTtNYM4IxFEpH84oPeVJbBx2+KlQ=; b=SoykUP+mcjBpioUvVXj45NqN8wTbG6IIHe2Qy9tf2KEMF5/fdBMj1EjuAWLXCxJ3WP esUrNnxdsBlUat7kF9N+7MmjuEcbH+X3vLFhFFUIXfRTHstUjJIoMC/wlolvCy+V4Nix HJNd4+2+AMBUZXnC1MdsI7uJrq2i7qmvD8cZ8Ey8GETXaClQUiDXZYH/Qm8a/IhBhmDK 0jAYR6xhtMD3uVzY8mJ6Y8QWJunTuiqwtvHbLsk2SvQysLgkOF14/s9lPgtEZ6SzE+cz 9d1Ms7b5s0l5DnjhTdOUBm7Fm2MQr8lHMXpys8OdHLpQVDZA2mNiZYcLBWkAFOANUVrm HG4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678362076; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=doR/FSWI3N6uWqCNTtNYM4IxFEpH84oPeVJbBx2+KlQ=; b=1Ep442tc6U/5RBfxyaeGArD7ovAmrnmUUBV1sbGaXrAWhRQIfowAl/m9q06TqTOR9M o+yRK/CtulfydPQ2HdJQgCKzJHycSDAuevGjYiWgvBDF+Ufan4IwqMf9+pYrYo1Ja4MW 8UdNnoA7GcyLOQerbJ0Q1tNjuLUpbak3lcowTmpaG5wnA0kpPf+NfK2sBZnJ6tEG6OQj VUPvoSV+K7lxIqgrFbJDhpzWW6tuTiXOeOLOqrs4NPeD+xPvHS07TTE14IrO8RFpvjqh xoU4nbAmg4Yopuh1DaTr2j7b1wdKxFGPxXlKeR3RrfObcxk4ep/fQxyZFppg0F/Ki+QI 2a/w== X-Gm-Message-State: AO0yUKXDAYRXrlhrKrNicUVMU9897tzqdSbU8QWiR2M4G3VauLUcCk9C JoQDhrJT0Xgndjscp9zUlhoC8vvF2DkJYMogCGUidNrA9rGoDJzUY5NUOA== X-Google-Smtp-Source: AK7set8N+eexTlqBb3yEPamZDu97xep08jzwuTHwN0ZSdB5fHsq0m33het3L1KCtQ0YtfP+X+ekj+NReVRjlI+Jwv5Y= X-Received: by 2002:a9d:4b9a:0:b0:693:dce4:49fb with SMTP id k26-20020a9d4b9a000000b00693dce449fbmr6851605otf.1.1678362076733; Thu, 09 Mar 2023 03:41:16 -0800 (PST) MIME-Version: 1.0 References: <20230309080446.24714-1-nelson@rivosinc.com> In-Reply-To: From: Nelson Chu Date: Thu, 9 Mar 2023 19:41:05 +0800 Message-ID: Subject: Re: [PATCH] RISC-V: Segment fault in riscv_elf_append_rela. To: Alan Modra Cc: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Thanks for the suggestion :) Seems like there are two better solution for n= ow, 1. Add the BFD_ASSERT before calling every riscv_elf_append_rela to make sure the written section exists, and then just return in the riscv_elf_append_rela if the section doesn't exist, to avoid the segment fault. We will know which section is NULL, and where the ASSERT code is. Besides that, since parts of the callers already have the BFD_ASSERT check before calling riscv_elf_append_rela, so this seems the right way to do it. 2. Report error and return false if the section doesn't exist in the riscv_elf_append_rela, and then the callers "goto out" to release the unused data structures in the riscv_elf_relocate_section, or return false if the caller is riscv_elf_finish_dynamic_symbol. But it is hard to report the more detailed errors in the riscv_elf_append_rela, it is not easy to know which caller code meets the problem. I think solution 1 should be better than solution 2? Thanks Nelson On Thu, Mar 9, 2023 at 4:34=E2=80=AFPM Alan Modra wrote: > > On Thu, Mar 09, 2023 at 04:04:46PM +0800, Nelson Chu wrote: > > * elfnn-riscv.c (riscv_elf_append_rela): Abort when the dynamic sec= tion > > doesn't exist. > > It would be nicer to handle this more gracefully by returning an error > to the caller. An abort isn't much better than a segmentation fault > if this can be triggered by user input. > > -- > Alan Modra > Australia Development Lab, IBM