From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by sourceware.org (Postfix) with ESMTPS id 734D73858002 for ; Mon, 13 Nov 2023 14:19:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 734D73858002 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 734D73858002 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699885153; cv=none; b=WRCSsMClhGsymcGxixbjPZikjq7JxcbhJVkXfxdmKfRzD+q3G58vA76QgFZjqr9H3F22TVfCXVbynyglbv4iK0w7jXiD4dkEAkyDdOYXFanVV1mZmOgRlaapgAseP2Wq+85kA0goE3AQgaZwgm1W7YS09zqjhi40lUQRSi5U/Cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699885153; c=relaxed/simple; bh=mGhaFHvB9uDRYgWT/nsZHxC0ZEqIktwL06GXg0kXN48=; h=DKIM-Signature:Date:Message-ID:From:To:Subject; b=SP2Cd564HOrGzt7rXHRmOtmIexg0NUPUayosJ0UfUVO4onNcvPNk9Wk0eaXna4h/in07d/N38mb+qygMpqiovfObUp9EPvIJuCqbhPzXpKKeVbTYPuL6MpZwYQXyQcgNc26AgNtTP7aMjKlOOieAlbeDEo0A4FwczjZBCfzwgFg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-1efad296d42so2709432fac.2 for ; Mon, 13 Nov 2023 06:19:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699885151; x=1700489951; darn=sourceware.org; h=subject:to:from:message-id:date:from:to:cc:subject:date:message-id :reply-to; bh=gKX3JFbW4Pi9VwXLDMmqpJvyj3o58K6Xzh9tbbdaM0I=; b=kn2ayaF9juGGKCvYjykQBZ3tndIc9BsByPjXtZm1Ot4BaCoxCSk62SaVPsyN47WFxK hMMwdp0uHOneJGyE/ODSVB1d2gnSTnE1dieukxv89H1nsaNNC6KFP9DBANQzOypUEqNW EUEmysRVT2tcpdRb64xgDySHPNvQcs5wIqGcOYz1x/qG9RxyotuvSwkrQ6NUmDGE9htF h+IDbcMOJeU5Ad45hEnENcqZ06T6JtPo0xs64xwBCuayiYsWBP0oc0V/c7ZHIzZKq8y0 rMAI0b14zMrxApxUBBB9QIHQEyEX5GexiU6zLQrNvqgoRw4dzXnkx7+4J1mamFXV3mhl kqCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699885151; x=1700489951; h=subject:to:from:message-id:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gKX3JFbW4Pi9VwXLDMmqpJvyj3o58K6Xzh9tbbdaM0I=; b=jO5aUh0NCFBtRp0X9/RPAC4rsrkP7L31wlCIRZoagZocijpKVSg+hq63gQpghVdBri +fRppOiX0bi3iCnELCUcgPYjNBDTiWM5vKefkMKmaDFv1YqnqpbgE03LQby7s19SkUAQ bQFePxc9TbHY+XUq4rbSn5rtS4/uLKLcGA+JdvDB9fgy4DkxkECWCkl8AJrafPRrUjZx qftbyPyBVUm8sl2siDuFPLOF2nNhy1N+MI1EYKeG1U6zuhN06+bRMQBsGv7+liNkNbjY tk4KKBxWPbbq2YPyla1OfTnSLBvhU951CrZXMEzI8ZEQrd/BaS3RpYNxujxM1z4LwyBt T4tQ== X-Gm-Message-State: AOJu0Yz+26Yn2pOoa5muyRMYsSpjUFLu3cNW3Jk1Ez+SowGa0XbIFHqS Kxa5wUNqb+3LoUCcYMtM54nQOE/jsD4= X-Google-Smtp-Source: AGHT+IHy5mgXw81V5tiyOpOGDIT+PEBbrEj/MOiHra+SlNt0vgJzD2UItyEdIZQFycueudP/1lGl8Q== X-Received: by 2002:a05:6871:692:b0:1ea:15e6:9420 with SMTP id l18-20020a056871069200b001ea15e69420mr9182646oao.52.1699885150964; Mon, 13 Nov 2023 06:19:10 -0800 (PST) Received: from localhost ([2804:7f0:3990:c9ca:141:6e80:cb8e:e051]) by smtp.gmail.com with ESMTPSA id y12-20020a62b50c000000b006c03f58b5b1sm3797811pfe.59.2023.11.13.06.19.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 06:19:10 -0800 (PST) Date: Mon, 13 Nov 2023 11:19:09 -0300 Message-ID: <079b4d1e36355219a756c1eea8f18e37.matheus.a.m.moreira@gmail.com> From: Matheus Afonso Martins Moreira To: binutils@sourceware.org Subject: Appending program headers to existing ELFs? X-Spam-Status: No, score=-1.4 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,T_SCC_BODY_TEXT_LINE 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: 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. Linux passes a pointer to the program header table of the running program via the auxiliary vector which is how I plan on accessing the data. 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. Given the address of the program header table, it is possible to obtain a pointer to the ELF header. However, no progress can be made from there since only the segments described by the program headers are loaded by the kernel which excludes the sections and the data I want to access. If I set the alloc flag on the new sections, objcopy will even warn me about the fact they're not loaded. 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? 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? I've been experimenting with linker scripts but with no success.