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.133.124]) by sourceware.org (Postfix) with ESMTPS id 76DB43858C66 for ; Tue, 14 Nov 2023 12:47:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76DB43858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 76DB43858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699966051; cv=none; b=FHLPPisxSMo/S0VU4GvxpwT2MCUn3NfXrU9prGOm5HTjy4Kf5S59HqRfkiGyA0momaimrth+tl9liuw4GeUuIzxgaOhKJWSwi00Q1WPKaQWNRloQGNA1XHsIcyrrWHZVh067GLz9KfOQi16HOEK6+alvQU4cffokouJP4SWh8pE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699966051; c=relaxed/simple; bh=AQ58dl1chEJiiWqJt1iBz+txHDefF79v3aqb/OU+AdA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=aZ/s+YsQloxcLym6iPHE5PFdyf9m50hy3KZC+yDSWxGZQzIhbdxXtqplbcvbh9KGIDUKSo3Z3lZoPy7BnBjaNZIpZuCFqJefqFdEE26qmQ5vSRA9e+U/enwQZLA9wPYxTjsd2lNgXZlblTtvYunSt00ZWOhpcqyJNsTQJizvrws= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699966050; 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:autocrypt:autocrypt; bh=FMiYdRsP2Sp97UnW+CLm8+d9BtkzpEYqPEwhjpZzmKc=; b=gBidZElA8mQI4cODtkQVPggPcaOHQGn6oNRlKSOL6FJKyzf0fu7m7IHYNUgcWutm4P6tci 4PJOMavDahkLQJYFt53gIQ6Zk8CQtJFYAekHOij0rfBIC4EcqmJVB2xejCAGnsctbMUsNR lxI4x4z/NkFenSYLYGSXO5X7EmdVT30= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-494-XoQBUphSNCGSSvl93U_TBA-1; Tue, 14 Nov 2023 07:47:29 -0500 X-MC-Unique: XoQBUphSNCGSSvl93U_TBA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-420f5614aa9so67754701cf.3 for ; Tue, 14 Nov 2023 04:47:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699966047; x=1700570847; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FMiYdRsP2Sp97UnW+CLm8+d9BtkzpEYqPEwhjpZzmKc=; b=GqRU7uSTlj62jEMCwQSgSyi4RFRHDLDTjADB/en4e6IPxLll43UP3N+Rh9b+tJFmeN biiraAXrLu63Y0SXVMmVGY3dtUTFixKTEAAYOV2yL5WLuOjxEfg5PZZMzpsVt1Z3slZq f+iNuYFNOLIXKYOERL5gUBAM5lad8NiDv2UD6N9c3h0RE/9+Ym0Vx/Cx70pwSBYPqbPp V1hCBFVAVpLUYlemCrwHb7qlcRPN4wX7yNZGwk45vCSMu2mQjmWPAnnnMD0RU3Jr39d0 66KgA4GP0fQ8tv+JdP69HOnygBBAH7CNaO8RSGecRmJJ4dVW+COslcGyGucUQ25dpJct J8xA== X-Gm-Message-State: AOJu0Yzu/jRA08VN4X69qKbUfmEmwvhc9L/iGL3m48TbNvyE/kvcNfSy esyfR3vfD6OlETcJZ/KJv9btDFrHAU66tfL6J/78r2zUZU4nQdweyLr5FDiCrc00QvPwDuhEau/ Jx2ADWqX0Y/c1/3utO5Z8e9db5w== X-Received: by 2002:a05:622a:10e:b0:417:a974:889e with SMTP id u14-20020a05622a010e00b00417a974889emr2388110qtw.2.1699966047680; Tue, 14 Nov 2023 04:47:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHB4HoB6rioMRauhxEWibjIG7D5q0MYmZZNkdaiXBjMxkt7yLNW9PMZtDYX2vKkr3Q0521vRw== X-Received: by 2002:a05:622a:10e:b0:417:a974:889e with SMTP id u14-20020a05622a010e00b00417a974889emr2388092qtw.2.1699966047436; Tue, 14 Nov 2023 04:47:27 -0800 (PST) Received: from [192.168.1.11] ([80.168.197.243]) by smtp.gmail.com with ESMTPSA id fj12-20020a05622a550c00b00421c8069affsm2388131qtb.78.2023.11.14.04.47.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Nov 2023 04:47:27 -0800 (PST) Message-ID: Date: Tue, 14 Nov 2023 12:47:25 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Appending program headers to existing ELFs? To: Matheus Afonso Martins Moreira , binutils@sourceware.org References: <079b4d1e36355219a756c1eea8f18e37.matheus.a.m.moreira@gmail.com> From: Nick Clifton Autocrypt: addr=nickc@redhat.com; keydata= xsFNBFm/2cUBEADkvRqMWfAryJ52T4J/640Av5cam9ojdFih9MjcX7QWFxIzJfTFYq2z+nb4 omdfZosdCJL2zGcn6C0AxpHNvxR9HMDkEyFHKrjDh4xWU+pH4z9azQEqJh331X7UzbZldqQo 16VkuVavgsTJaHcXm+nGIBTcUbl2oiTtHhmuaYxx6JTMcFjC7vyO5mLBw78wt52HBYweJ0Nj HBvvH/JxbAAULSPRUC61K0exlO49VFbFETQNG1hZTKEji95fPbre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Zqf0uTDy3jP65OFhSkTEIy nYv1Mb4JJl3Sq+haUbfWLAV5nboSuHmiZE6Bz2+TjdoVkNwHBfpqxu6MlWka+P98SUcmY8iV hPy9QC1XFOGdFDFf1kYgHW27mFwds35NQhNARgftAVz9FZXruW6tFIIfisjr3rVjD9R8VgL7 l5vMr9ylOFpepnI6+wd2X1566HW7F1Zw1DIrY2NHL7kL5635bHrJY4n7o/n7Elk/Ca/MAqzd IZxz6orfXeImsqZ6ODn4Y47PToS3Tr3bMNN9N6tmOPQZkJGHDBExbhAi/Jp8fpWxMmpVCUl6 c85cOBCR4s8tZsvGYOjR3CvqKrX4bb8GElrhOvAJa6DdmZXc7AyoVMaTvhpq3gJYKmC64oqt 7zwIHwaCxTbP6C6oUp9ENRV7nHnXN3BlvIgCo4QEs6HkDzkmgYlCEOKBiDyVMSkPDZdsspa+ K4GlU2Swi/BDJMjtDxyo+K0M81LXXxOeRfEIfPtZ3ddxBKPva1uSsuz+pbN9d1JY8Ko5T/h1 6susi2ReUyNJEJaSnjO5z13TQ1U= In-Reply-To: <079b4d1e36355219a756c1eea8f18e37.matheus.a.m.moreira@gmail.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: 7bit X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no 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 Matheus, > I'd like to embed arbitrary data into existing ELF executables > in such a way that the data is automatically loaded onto memory > and is reachable by the program at runtime. I have to say that this does sound suspicious. Why can't you add the data at link time ? > With objcopy it is already possible to embed arbitrary files > to ELF files by placing them into sections: > > objcopy --add-section program.file1=file1 \ > --add-section program.file2=file2 \ > program program+files > > However, those sections are unreachable when the program actually runs. Hmm, could you create a new symbol for the section and reference the data that way. eg: objcopy \ --add-section foo=file1 \ --add-symbol foo_start=foo \ --set-section-flags foo=alloc,load \ a.out a.extra This assumes that you can access the symbol table at runtime. I have no idea if this is true for kernel images however. > So it seems to me that the solution is to add a new program header > to the ELF executable instead of a new section. How can this be done > with binutils tools? At the moment this can only be done by the linker, and it will only work if the input files are object files or relocatable binaries. ie if a final link has been performed then you are not going to be able to add new program header entries using the binutils tools. (At least not as they are today). > If it's not possible to do this with objcopy, can it be done with ld? > Is it possible to add a placeholder program header table entry at link > time so that it can be adjusted later by external tools to encompass the > newly added sections without needing to relink the whole executable? Possibly. With a linker script you can layout a PHDRS structure which describes the entries that should go into the program header. So in theory you can include an extra entry for use by later tools. I do not know if this has ever been done in practice however, so it may be that there are unknown bugs waiting to be discovered. Cheers Nick