Skip to content

enclave_common: add missing <algorithm> header for GCC 14 compat#1063

Closed
berrange wants to merge 1 commit intointel:mainfrom
berrange:psw-gcc14-compat-algo
Closed

enclave_common: add missing <algorithm> header for GCC 14 compat#1063
berrange wants to merge 1 commit intointel:mainfrom
berrange:psw-gcc14-compat-algo

Conversation

@berrange
Copy link
Contributor

@berrange berrange commented Oct 9, 2024

When building with GCC 14, various c++ stdlib functions are undefined:

sgx_enclave_common.cpp: In function ‘void* get_enclave_base_address_from_address(void*)’: sgx_enclave_common.cpp:164:23: error: ‘upper_bound’ is not a member of ‘std’; did you mean ‘lower_bound’?
  164 |     auto upper = std::upper_bound(s_enclave_base_address.begin(), s_enclave_base_address.end(), (uint64_t)target_address);
      |                       ^~~~~~~~~~~
      |                       lower_bound
sgx_enclave_common.cpp: In function ‘void* enclave_create_ex(void*, size_t, size_t, uint32_t, const void*, size_t, uint32_t, const void**, uint32_t*)’:
sgx_enclave_common.cpp:790:14: error: ‘sort’ is not a member of ‘std’; did you mean ‘qsort’?
  790 |         std::sort(s_enclave_base_address.begin(), s_enclave_base_address.end());
      |              ^~~~
      |              qsort
sgx_enclave_common.cpp: In function ‘bool enclave_delete(void*, uint32_t*)’:
sgx_enclave_common.cpp:1255:43: error: ‘remove’ is not a member of ‘std’; did you mean ‘move’?
 1255 |         s_enclave_base_address.erase(std::remove(s_enclave_base_address.begin(), s_enclave_base_address.end(), (uint64_t)base_address),
      |                                           ^~~~~~
      |                                           move

These stdlib functions are provided by bits/stl_algo.h, and prior to GCC 14, the <functional> header would pull in stl_algo.h.

With GCC 14, the <functional> header was changed to only pull in stl_algobase.h.

We must now use <algorithm> to get these definitions, which should work on all versions of GCC.

When building with GCC 14, various c++ stdlib functions are undefined:

sgx_enclave_common.cpp: In function ‘void* get_enclave_base_address_from_address(void*)’:
sgx_enclave_common.cpp:164:23: error: ‘upper_bound’ is not a member of ‘std’; did you mean ‘lower_bound’?
  164 |     auto upper = std::upper_bound(s_enclave_base_address.begin(), s_enclave_base_address.end(), (uint64_t)target_address);
      |                       ^~~~~~~~~~~
      |                       lower_bound
sgx_enclave_common.cpp: In function ‘void* enclave_create_ex(void*, size_t, size_t, uint32_t, const void*, size_t, uint32_t, const void**, uint32_t*)’:
sgx_enclave_common.cpp:790:14: error: ‘sort’ is not a member of ‘std’; did you mean ‘qsort’?
  790 |         std::sort(s_enclave_base_address.begin(), s_enclave_base_address.end());
      |              ^~~~
      |              qsort
sgx_enclave_common.cpp: In function ‘bool enclave_delete(void*, uint32_t*)’:
sgx_enclave_common.cpp:1255:43: error: ‘remove’ is not a member of ‘std’; did you mean ‘move’?
 1255 |         s_enclave_base_address.erase(std::remove(s_enclave_base_address.begin(), s_enclave_base_address.end(), (uint64_t)base_address),
      |                                           ^~~~~~
      |                                           move

These stdlib functions are provided by bits/stl_algo.h, and prior
to GCC 14, the <functional> header would pull in stl_algo.h.

With GCC 14, the <functional> header was changed to only pull in
stl_algobase.h.

We must now use <algorithm> to get these definitions, which should
work on all versions of GCC.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
@thunze thunze mentioned this pull request May 3, 2025
13 tasks
@phlip9
Copy link

phlip9 commented Jun 26, 2025

Just reporting that as of 2.26 release, GCC 14 build for sgx-psw is still broken without this patch

@berrange
Copy link
Contributor Author

This was fixed in the 2.27 release.

@berrange berrange closed this Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants