folly icon indicating copy to clipboard operation
folly copied to clipboard

Potential FOLLY_HAVE_IFUNC false positive causing 'unsupported relocation type' error

Open maxirmx opened this issue 3 years ago • 0 comments

FOLLY_HAVE_IFUNC is checked with the following code snippet:

check_cxx_source_compiles("
  #pragma GCC diagnostic error \"-Wattributes\"
  extern \"C\" void (*test_ifunc(void))() { return 0; }
  void func() __attribute__((ifunc(\"test_ifunc\")));
  int main() { return 0; }"
  FOLLY_HAVE_IFUNC
)

This approach can lead to false positives because __attribute__((ifunc ...)) also requires linker support. An example of a false positive environment is Alpine 3.15 / clang 12 where the compiler supports the attribute but the linker does not support the required relocation type.

Correct check would be:

check_cxx_source_runs("
  #pragma GCC diagnostic error \"-Wattributes\"
  extern \"C\" int resolved_ifunc(void) { return 0; }
  extern \"C\" int (*test_ifunc(void))() { return resolved_ifunc; }
  int func() __attribute__((ifunc(\"test_ifunc\")));
  int main() { return func(); }"
  FOLLY_HAVE_IFUNC
)

maxirmx avatar Apr 09 '22 18:04 maxirmx