Skip to content

Commit

Permalink
Fix openNoInt building error after android ndk r21 (#1593)
Browse files Browse the repository at this point in the history
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:
android/ndk#1328
llvm/llvm-project@0a0e411

Pull Request resolved: #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
  • Loading branch information
Kudo Chien authored and facebook-github-bot committed Jun 27, 2021
1 parent ed17362 commit 7312385
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion folly/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ namespace folly {
using namespace fileutil_detail;

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) {
Expand Down

0 comments on commit 7312385

Please sign in to comment.