Re: [PATCH 4/5] selftests/sgx: Ensure expected enclave data buffer size and placement.

From: Jo Van Bulck
Date: Sat Aug 19 2023 - 04:10:14 EST


On 18.08.23 06:07, Huang, Kai wrote:
Could we use "used" attribute?

https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html

used

This attribute, attached to a variable with static storage, means that
the variable must be emitted even if it appears that the variable is
not referenced.

When applied to a static data member of a C++ class template, the
attribute also means that the member is instantiated if the class
itself is instantiated.

Thank you for pointing this out! I was not aware of this attribute, but it is indeed exactly what we need in this case and works as expected.


2. adding _attribute__((section(".data.encl_buffer"))) ensures that we
can control the expected location at the start of the .data section. I
think this is optional, as encl_buf always seems to be placed at the
start of .data in all my tests. But afaik this is not guaranteed as per
the C standard and such constraints on exact placement should better be
explicitly controlled in the linker script(?)

This looks sane.

Thanks, applying this in a separate commit as discussed.

Best,
Jo