From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DB2C53858D35 for ; Tue, 14 Feb 2023 16:06:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB2C53858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676390814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FEXGnDHDaNwcOyTsUKRrr6gdpL6UQOOL4Ykr459P4go=; b=ifklE2JrpsXjZVV+QuSYkl/Ect9XCr85l1miXuap6NqYGqAOKKx5uWq7aqCJ5gLAfIy/GI ZdgTcenXw+KRkIsP+WPjguFvtY7xS3In+WuocSdnknVHTRkRaC3c2D/x813Bp10Uan1pdi Qa1FGoPkvenBGS6HBszZKZ+jiHuWb5w= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-163-Pbo8P00jOzCszH4i4VKvew-1; Tue, 14 Feb 2023 11:06:50 -0500 X-MC-Unique: Pbo8P00jOzCszH4i4VKvew-1 Received: by mail-qv1-f71.google.com with SMTP id ib5-20020a0562141c8500b0053c23b938a0so8944785qvb.17 for ; Tue, 14 Feb 2023 08:06:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:references:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FEXGnDHDaNwcOyTsUKRrr6gdpL6UQOOL4Ykr459P4go=; b=030hj9NWDWxy1ZfV/mxiFzJm9WZIzqNuJKSEt8Jao2akWu8JAh2c9WMlrhRyUDQaIX 8oBDglUHldA70ys/iFUgdejtwkG5pq0btqzUM+LZpDcAjHkkaqzYYarvp8pL3c3G2MWk WnwlhOX239HNwF7CCn8x8jJ2OnqqcRuw5YxAeHVQ82C7s5hLDLYIVvXHW63osdxonxGe GwHmsa3Tk2ne2JdXOiiLjSVDypopeRtNGXa65qXCUQfHWfSqdzIVyqDTz5xFxJIEwrGI onvbE+UYwk8Tyz3lw2ZhPuQG86zDJWcLuNjBEbY5eQuOgZDUGIKPutz3BJxh0H/zZ6mt p3kg== X-Gm-Message-State: AO0yUKXdsaxdgSNZIavJ14VCLykiCuOWQ4Cpgo23pjN0itYEw2SIBkRJ hPq/hCrG3NpnWkliEevWGF3PbiHC3yS3W/bpVGC8LBV5h7IgJGkHh3l4LYHLN1EXtgI4/lBa6SE NlDG8enfkBJe4K7aPE77SHGY= X-Received: by 2002:a05:622a:1195:b0:3b6:93fe:443c with SMTP id m21-20020a05622a119500b003b693fe443cmr4545175qtk.32.1676390809383; Tue, 14 Feb 2023 08:06:49 -0800 (PST) X-Google-Smtp-Source: AK7set/sEnuqybwasEnTIKsXPuDNbFtfBLGP5Rdb9VT+MZmD0i/JYP3burxJcVXXRGFrCCd/8jkGQw== X-Received: by 2002:a05:622a:1195:b0:3b6:93fe:443c with SMTP id m21-20020a05622a119500b003b693fe443cmr4545140qtk.32.1676390809133; Tue, 14 Feb 2023 08:06:49 -0800 (PST) Received: from [192.168.1.18] ([79.123.83.169]) by smtp.gmail.com with ESMTPSA id c193-20020ae9edca000000b007389403f7e6sm12246848qkg.9.2023.02.14.08.06.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Feb 2023 08:06:48 -0800 (PST) Message-ID: <4937b1c3-fc16-328f-7af2-13d1c42288e1@redhat.com> Date: Tue, 14 Feb 2023 16:06:47 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 To: Ulf Samuelsson , binutils@sourceware.org, Jan Beulich References: <5aa83cea-b8ad-5b36-12ec-6857a5c5541a@redhat.com> <73f54df1-c236-4c4a-c161-85ebe6d6f7b7@emagii.com> <7216fa28-4769-5bd2-a508-bf71184727fd@redhat.com> <324a63be-1403-edf1-23ad-6fd11e524529@emagii.com> From: Nick Clifton Subject: Re: RFC: generating a header using the linker (ASCII, ASCIZ commands) In-Reply-To: <324a63be-1403-edf1-23ad-6fd11e524529@emagii.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-GB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: Hi Ulf, >>> Note that if the linker can call an external tool to compute the CRC >>> based on the extracted text segment, and insert that into the resulting ELF file. >>> then this is superior to running a utility afterwards. >> >> Actually -- there might be a way to do this: A linker plugin.  The linker already >> has the architecture to support plugins, and you could create a new one which would >> scan the text section, compute a CRC and then insert the value into a header in the >> linked image... >> > OK, tell me more! Sure. The linker has the ability to run plugins via the use of the "-plugin " command line option. Currently there are two known plugins for the linker. One is used to process the dependencies of static archives (ld/libdep_plugin.c in the binutils sources) and one is used to pass LTO enabled object files back to the compiler for recompilation (lto-plugin/ in the gcc sources). The big problem with linker plugins however is the total lack of documentation on how to write them. Until the day comes when somebody writes a manual the only documentation is the source code itself. The place to start is the include/plugin-api.h file which defines the interface between plugins and the linker. Then take a look at the plugin sources mentioned above and the ld/plugin.c source file which is the linker's side of the coin. In essence what a plugin does is provide a selection of callback functions to the linker. These functions are called at various stages of the link, and can do pretty much anything. Since plugins are shared objects, they have full access to the linker's run-time memory space and can muck about as they please. Of course plugins are expected to behave nicely. Cheers Nick