Commit 73123851 authored by Kudo Chien's avatar Kudo Chien Committed by Facebook GitHub Bot

Fix openNoInt building error after android ndk r21 (#1593)

Summary:
Android NDK bionic with FORTIFY will override original `open()` definition and making folly `wrapNoInt` template failed to deduct.
The issue may happen only after NDK r21 because [this commit landed after r21](https://android.googlesource.com/platform/bionic/+/9349b9e51b41d12fd054b925802b626ca2db0afb%5E%21/#F0)

References:
https://github.com/android/ndk/issues/1328
https://github.com/llvm/llvm-project/commit/0a0e411204a2baa520fd73a8d69b664f98b428ba

Pull Request resolved: https://github.com/facebook/folly/pull/1593

Test Plan:
Tested running `objdump -dr` on the object file generated in both `mode/opt`
and `mode/opt-gcc` build modes and confirmed the generated code was
identical.

Reviewed By: yfeldblum

Differential Revision: D28953120

Pulled By: simpkins

fbshipit-source-id: 225583a5a011e8456592a0bcfcd669fe966ea6af
parent ed173626
...@@ -35,7 +35,22 @@ namespace folly { ...@@ -35,7 +35,22 @@ namespace folly {
using namespace fileutil_detail; using namespace fileutil_detail;
int openNoInt(const char* name, int flags, mode_t mode) { int openNoInt(const char* name, int flags, mode_t mode) {
return int(wrapNoInt(open, name, flags, mode)); // Android NDK bionic with FORTIFY has this definition:
// https://android.googlesource.com/platform/bionic/+/9349b9e51b/libc/include/bits/fortify/fcntl.h
// ```
// __BIONIC_ERROR_FUNCTION_VISIBILITY
// int open(const char* pathname, int flags, mode_t modes, ...) __overloadable
// __errorattr(__open_too_many_args_error);
// ```
// This is originally to prevent open() with incorrect parameters.
//
// However, combined with folly wrapNotInt, template deduction will fail.
// In this case, we create a custom lambda to bypass the error.
// The solution is referenced from
// https://github.com/llvm/llvm-project/commit/0a0e411204a2baa520fd73a8d69b664f98b428ba
//
auto openWrapper = [&] { return open(name, flags, mode); };
return int(wrapNoInt(openWrapper));
} }
static int filterCloseReturn(int r) { static int filterCloseReturn(int r) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment