From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 705BE3858407 for ; Tue, 22 Mar 2022 15:49:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 705BE3858407 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=profian.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=profian.com Received: by mail-lj1-x22f.google.com with SMTP id s25so24523943lji.5 for ; Tue, 22 Mar 2022 08:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profian-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:subject:message-id:mime-version:content-disposition; bh=JDsHGHQno84YFCWgNZ8xEciaS3OKN/d9nwNsjuFYia0=; b=yTnudhSe24ruODtKaIV3pANgrwnN1/plGGnmlU35aJfXVdHotU1bk20tqh/kO41TOH TyXhsC2YMTBwx+ES+U7iDFWCx6cyBo/+50Kxf+z+ykD10QLMIXk63vW1JXkt4VlwNJTl Vgd/i0MYQdBH/OGx2ZY3tCxy0ww9rZCGGu/0J7Goy2LXvxXSNFKYbZ6wm9c+yyme1tGa dfSkBpl7tuNObRRbHVUVkx1gxbCvhKA9pLXV4StR2wdEvw6JEijGdv7nJIFm4QDmhUfE D+JGsJP0VRSZKJFIflMsDDAkisuOle2AcVGigtymL59tQHN722BlJ6M3V9Ecj6FlUa9e nR6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=JDsHGHQno84YFCWgNZ8xEciaS3OKN/d9nwNsjuFYia0=; b=IsSHv76xTKZSTvbstuFuAjUobMRiWXIJzpKEDO3E6BVskc3Zzt1xpmHVav6dggfuFY Jc/9J6y38o7NepEU5YoXFtC9p0oJ1TbM0/c9+jGVn53gt8YAD+rA7yL3B4AJOvZtF96a GaNhgLzj4fppKp0ycpP4xpuiTcsCLxMO4yCDkiRM9GBXO850JyVDBMZPfWGgXlKLz2mH W4ud/GL4LEVQeBVmtlx6jJW4Wzig5CTGIIkZ+im+iykNTGs9jZ8sbYDEdSubjGKT8VcS Eo+H7bKc2rWqf9m0rqKRWGseoSLdbIYXhtahpnou26BZvruK8aR1VPwkobkPRqT17xv2 JsKQ== X-Gm-Message-State: AOAM530Gqzjfsf4fYorXxFtNhutoTPVYvIRWCYwE14BLIKB34G0rIl2j WwOr2nT0X16QT6yycOqvtCfF1DyMgCUnuNtR X-Google-Smtp-Source: ABdhPJzqbhwIsGoOAvGT+nIenvU1dhx2Q2m5Nnc8HSE8cyE5m/VflUxc3eS2xsRV7DxwRBiUvwpOyw== X-Received: by 2002:a05:651c:1695:b0:249:8540:837a with SMTP id bd21-20020a05651c169500b002498540837amr7551856ljb.495.1647964184431; Tue, 22 Mar 2022 08:49:44 -0700 (PDT) Received: from localhost (91-154-92-187.elisa-laajakaista.fi. [91.154.92.187]) by smtp.gmail.com with ESMTPSA id g7-20020a2eb5c7000000b002497a261f02sm1248968ljn.41.2022.03.22.08.49.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 08:49:43 -0700 (PDT) Date: Tue, 22 Mar 2022 17:50:48 +0200 From: Jarkko Sakkinen To: gcc-help@gcc.gnu.org Subject: Stringify an offset Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2022 15:49:48 -0000 When implementing shims and executable blob for various confidential computing platforms like Intel SGX, AMD SEV-SNP and probably also upcoming ARMv9 REALMS, you often need to markup segments so that the loader knows to do how to do the "right thing". For instance, SGX has so called Thread Control Structure (TCS) pages, which are essentially entry points to the "enclaves", which is just a fancy name for executable blobs. TCS pages are contained within the enclave address space but need to be initialized in a special manner, so you need to hint the loader, which data segments contain them. Two ways that I know how to do that are both somewhat ugly hacks: 1. Use spare flags in p_flags. 2. Create a PT_NOTE with a name "TCS" and use p_descz to describe an offset. This is limits of course to 32-bit offset unless you pick from these to bad malwareish choices: a. Overwrite p_type with the other part of the address. b. Use two PT_NOTE entries for high and low parts of the address. I came up with solution that should be technically possible to implement in GCC that would scale all these needs and would not need anything substantially huge. I would be like to be able to do PT_NOTE's with a name formatted as follows: TCSxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Here x's represent zero padded hexadecimal offset of a label. Does GAS provide as of today something to "stringify" a label into address? If not, would that be something that could be added to GAS and GCC, or if it was contributed, would it be considered for upstream? There's dozens of similar cases in these technologies where this would solve the problem, so a solution that *specifically* sorts it out just for these TCS pages is not adequate. It was just one example. BR, Jarkko