From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 17FAB3857400 for ; Fri, 29 Jul 2022 19:41:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 17FAB3857400 Received: by mail-pf1-x436.google.com with SMTP id b133so5492158pfb.6 for ; Fri, 29 Jul 2022 12:41:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ycXCzaXZdtSKdREwxJe4Plp/BVv/yIz3ODMDQrUeY1M=; b=pi4gmrR2gKa7ZMRvVQCgGTuC1V3nLOAhY8wml2krr38sWGllbWzIZNLzhtCzO6Fst4 ZUGKiNMDJuDOkY4tm4q6y0R2VlrLgK++KRnM3MgzUIo7ohcweMJJtleIIEvb4bDPSx0d yc15GDG45YzDXG5CVW5uXi4TXnHpbJ+mG8dOzOQ0EYSMPEY075Po0sCZO13E7LnWiaf7 XtHxo9AwLJgRvOjXVUu/X53g6UVVMxIv4fYnfVZg8Fke8y3OczMgmdIKgUD+q8RsY6Vz vXI3H7yC3rzCtF4Pif6eUUKaVcl5akLnffClEMj6e0mTddnUCine8OQacol05cxDJcpI HYNA== X-Gm-Message-State: AJIora9XGLdvWVqMHZ0j5iACXRgUh2x0Veu/50E9SOFRB6ZIZRpIJeR9 TKWo7V9qfWBaRFSdBdXg0/goB32GSWLhZTKsKTlOm8joUrs= X-Google-Smtp-Source: AGRyM1va8XFNzZP2NiqztZanMlxGuglKCy/+yRyp/ptYZxaKpYJ7pPQ55tk7PtSWxHKraYDzD1gYC0H6Ad2vQetIPNg= X-Received: by 2002:a63:4c0d:0:b0:41a:77fe:2bc8 with SMTP id z13-20020a634c0d000000b0041a77fe2bc8mr4090603pga.82.1659123698746; Fri, 29 Jul 2022 12:41:38 -0700 (PDT) MIME-Version: 1.0 References: <20220726192216.1751042-1-luca.boccassi@gmail.com> In-Reply-To: <20220726192216.1751042-1-luca.boccassi@gmail.com> From: Cary Coutant Date: Fri, 29 Jul 2022 12:41:27 -0700 Message-ID: Subject: Re: [PATCH] gold: add --package-metadata To: luca.boccassi@gmail.com Cc: Binutils Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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 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: Fri, 29 Jul 2022 19:41:42 -0000 > Following the same format as the implementation in ld: > 9e2bb0cb5e74aed4158f08495534922d7108f928 > > Generate a .note.package FDO package metadata ELF note, following > the spec: https://systemd.io/ELF_PACKAGE_METADATA/ > > If the jansson library is available at build time (and it is explicitly > enabled), link ld to it, and use it to validate that the input is > correct JSON, to avoid writing garbage to the file. The > configure option --enable-jansson has to be used to explicitly enable > it (error out when not found). This allows bootstrappers (or others who > are not interested) to seamlessly skip it without issues. I reviewed the earlier discussion and I had some of the same questions and concerns as others did there, so they've all been answered. I'd have preferred an option syntax that would let you build up the metadata info one key/value pair at a time. Given that it has already been accepted for ld, however, I'll OK it for gold as well, with the following fixes... + json_t *json = json_loads (desc, 0, &json_error); C++ coding conventions here: no space before the paren in a function call. + if (!json) + gold_fatal(_("error: --package-metadata=%s does not contain valid " + "JSON: %s\n"), + desc, json_error.text); + else + json_decref (json); Put the shorter, non-error path first (i.e., make it "if (json)...else..."), and use { } for the longer error path (even though it's only one statement, I think braces around a multi-line statement help readability). Also, no space before the paren. + if (trailing_padding != 0) + { + posd = new Output_data_zero_fill(trailing_padding, 0); + os->add_output_section_data(posd); + } The braces and what's inside them need an extra two spaces of indent. -cary