Skip to content

Recommended GCC/Clang Flags for Nitro Enclave ARM64 Builds

0

For ARM64 workloads in Nitro Enclaves, what are the recommended compiler flags?

Specifically:

  1. Should we use -mcpu=neoverse-n1 (conservative) or -mcpu=neoverse-v1 (Graviton3-specific) or -mcpu=native (auto-detect)?

  2. Is it safe to enable:

    • -march=armv8.2-a+dotprod+fp16+crypto?
    • Advanced SIMD optimizations?
    • Link-time optimization (LTO)?
  3. Are there any flags that are UNSAFE in enclaves but safe on the host?

  4. Is there a difference between what works on the host instance vs inside the enclave for the SAME instance type?

Context: We're seeing binaries work on host but crash in enclave, suggesting the enclave kernel exposes a different CPU feature set than the host.

asked a year ago284 views

1 Answer
0

For ARM64 workloads in Nitro Enclaves, here are recommendations regarding compiler flags:

  1. Regarding CPU target selection:
  • For Graviton2-based instances, -mcpu=neoverse-n1 is the most appropriate choice
  • For Graviton3-based instances, -mcpu=neoverse-v1 would be appropriate
  • For Graviton4-based instances, -mcpu=neoverse-v2 would be appropriate
  • Using -mcpu=native is not recommended for enclave builds as it detects features from the host environment which may not match the enclave environment
  1. Regarding specific optimizations:
  • Amazon Linux 2023 packages are built with -march=armv8.2-a+crypto -mtune=neoverse-n1 for aarch64, suggesting these are safe baseline options
  • Auto-vectorization (like -ftree-vectorize) is used in AL2023 packages
  • Link Time Optimization (LTO) is also enabled in AL2023 packages
  • Standard optimization flags like -O2 or -O3 are generally safe
  1. Regarding unsafe flags:
  • There's no explicit information about flags that are unsafe specifically in enclaves but safe on the host
  • However, the issue you're experiencing suggests that assuming identical CPU feature sets between host and enclave may be problematic
  1. Regarding differences between host and enclave:
  • Your observation about binaries working on the host but crashing in the enclave suggests there may indeed be differences in the CPU feature sets exposed
  • This could be due to how the Nitro Enclave virtualizes or exposes CPU features differently than the host environment
  • To address this, using more conservative compiler flags that target a baseline feature set (like those used in AL2023) would be safer than assuming full feature parity

To resolve your crashing issues, I would recommend:

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.