Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible ODR violation #327

Open
SchrodingerZhu opened this issue May 8, 2021 · 1 comment
Open

Possible ODR violation #327

SchrodingerZhu opened this issue May 8, 2021 · 1 comment

Comments

@SchrodingerZhu
Copy link
Contributor

I encountered the following with gcc 10.2.0:

../src/test/func/two_alloc_types/main.cc:37:1: warning: ‘host_snmalloc_chunkmap_global_get’ violates the C++ One Definition Rule [-Wodr]
   37 | host_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);
      | ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type mismatch in parameter 1
  224 |   SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_chunkmap_global_get)(
      |                         ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type name ‘snmalloc_host::PagemapConfig’ should match type name ‘snmalloc::PagemapConfig’
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: ‘host_snmalloc_chunkmap_global_get’ was previously declared here
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../src/test/func/two_alloc_types/main.cc:35:1: warning: ‘enclave_snmalloc_chunkmap_global_get’ violates the C++ One Definition Rule [-Wodr]
   35 | enclave_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);
      | ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type mismatch in parameter 1
  224 |   SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_chunkmap_global_get)(
      |                         ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type name ‘snmalloc_enclave::PagemapConfig’ should match type name ‘snmalloc::PagemapConfig’
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: ‘enclave_snmalloc_chunkmap_global_get’ was previously declared here
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
[107/211] Linking CXX executable func-two_alloc_types-1
../src/test/func/two_alloc_types/main.cc:37:1: warning: ‘host_snmalloc_chunkmap_global_get’ violates the C++ One Definition Rule [-Wodr]
   37 | host_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);
      | ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type mismatch in parameter 1
  224 |   SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_chunkmap_global_get)(
      |                         ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type name ‘snmalloc_host::PagemapConfig’ should match type name ‘snmalloc::PagemapConfig’
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: ‘host_snmalloc_chunkmap_global_get’ was previously declared here
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../src/test/func/two_alloc_types/main.cc:35:1: warning: ‘enclave_snmalloc_chunkmap_global_get’ violates the C++ One Definition Rule [-Wodr]
   35 | enclave_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);
      | ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type mismatch in parameter 1
  224 |   SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_chunkmap_global_get)(
      |                         ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type name ‘snmalloc_enclave::PagemapConfig’ should match type name ‘snmalloc::PagemapConfig’
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: ‘enclave_snmalloc_chunkmap_global_get’ was previously declared here
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
[195/211] Linking CXX executable func-two_alloc_types-oe
../src/test/func/two_alloc_types/main.cc:37:1: warning: ‘host_snmalloc_chunkmap_global_get’ violates the C++ One Definition Rule [-Wodr]
   37 | host_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);
      | ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type mismatch in parameter 1
  224 |   SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_chunkmap_global_get)(
      |                         ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type name ‘snmalloc_host::PagemapConfig’ should match type name ‘snmalloc::PagemapConfig’
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: ‘host_snmalloc_chunkmap_global_get’ was previously declared here
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../src/test/func/two_alloc_types/main.cc:35:1: warning: ‘enclave_snmalloc_chunkmap_global_get’ violates the C++ One Definition Rule [-Wodr]
   35 | enclave_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);
      | ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type mismatch in parameter 1
  224 |   SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_chunkmap_global_get)(
      |                         ^
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: type name ‘snmalloc_enclave::PagemapConfig’ should match type name ‘snmalloc::PagemapConfig’
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: ‘enclave_snmalloc_chunkmap_global_get’ was previously declared here
../src/test/func/two_alloc_types/../../../override/malloc.cc:224:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used

@mjp41
Copy link
Member

mjp41 commented May 9, 2021

Looks like

extern "C" void*
enclave_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);
extern "C" void*
host_snmalloc_chunkmap_global_get(snmalloc::PagemapConfig const**);

in main.cc should be

extern "C" void*
enclave_snmalloc_chunkmap_global_get(snmalloc_enclave::PagemapConfig const**);
extern "C" void*
host_snmalloc_chunkmap_global_get(snmalloc_host::PagemapConfig const**);

But then the comparison of pagemap config will complain. @davidchisnall might have some thoughts on the right way to fix this. We might need to create an snmalloc_abi namespace to deal with this correctly, so that the config is just defined once.

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

No branches or pull requests

2 participants