public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Stringify an offset
@ 2022-03-22 15:50 Jarkko Sakkinen
  0 siblings, 0 replies; only message in thread
From: Jarkko Sakkinen @ 2022-03-22 15:50 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-22 15:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22 15:50 Stringify an offset Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).