-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[compiler-rt] intercept macOs's freadlink call. #83679
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
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) Changesavailable since macOs Ventura. Full diff: https://github.com/llvm/llvm-project/pull/83679.diff 3 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 3ecdb55cdbf72f..9a43ada118da8a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10250,6 +10250,24 @@ INTERCEPTOR(int, cpuset_getaffinity, int level, int which, __int64_t id, SIZE_T
#define INIT_CPUSET_GETAFFINITY
#endif
+#if SANITIZER_INTERCEPT_FREADLINK
+INTERCEPTOR(SSIZE_T, freadlink, int fd, char *buf, SIZE_T bufsiz) {
+ void* ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, freadlink, fd, buf, bufsiz);
+ COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
+ SSIZE_T res = REAL(freadlink)(fd, buf, bufsiz);
+ if (res > 0)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, res);
+ if (res >= 0 && fd > 0)
+ COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
+ return res;
+}
+
+#define INIT_FREADLINK COMMON_INTERCEPT_FUNCTION(freadlink)
+#else
+#define INIT_FREADLINK
+#endif
+
#include "sanitizer_common_interceptors_netbsd_compat.inc"
namespace __sanitizer {
@@ -10569,6 +10587,7 @@ static void InitializeCommonInterceptors() {
INIT___XUNAME;
INIT_ARGP_PARSE;
INIT_CPUSET_GETAFFINITY;
+ INIT_FREADLINK;
INIT___PRINTF_CHK;
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index de55c736d0e144..42a06b3cc6f4d3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -598,6 +598,7 @@
#define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
#define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
#define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
+#define SANITIZER_INTERCEPT_FREADLINK SI_MAC
// This macro gives a way for downstream users to override the above
// interceptor macros irrespective of the platform they are on. They have
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Darwin/freadlink.c b/compiler-rt/test/sanitizer_common/TestCases/Darwin/freadlink.c
new file mode 100644
index 00000000000000..53658cdb66aa3d
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Darwin/freadlink.c
@@ -0,0 +1,29 @@
+// RUN: %clang -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ char symlink_path[PATH_MAX];
+ snprintf(symlink_path, sizeof(symlink_path), "%s_%d.symlink", argv[0],
+ getpid());
+ remove(symlink_path);
+ int res = symlink(argv[0], symlink_path);
+ assert(!res);
+
+ int fd;
+ char readlink_path[PATH_MAX];
+ fd = open(symlink_path, O_RDONLY);
+ ssize_t res2 = freadlink(fd, readlink_path, sizeof(readlink_path));
+ assert(res2 >= 0);
+ readlink_path[res2] = '\0';
+ assert(!strcmp(readlink_path, argv[0]));
+ close(fd);
+
+ return 0;
+}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
e166d0f
to
a3b9d38
Compare
a3b9d38
to
9a8cbae
Compare
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
Outdated
Show resolved
Hide resolved
available since macOs Ventura.
9a8cbae
to
da32a6f
Compare
Is this intended to break the build on Mac versions earlier than Ventura? Has llvm raised the minimum required version of Mac os from 10.14? |
Was unintended, thankfully we can check mac os sdk version. I ll produce a fix shortly. |
This commit seems to have prevented builds on macOS Big Sur.
|
which commit ? this one or this one ? |
This one.
|
It is already an old commit did you try to update ? Why I mentioned the other commit it s because it s supposed to fix it. |
I got the code for the main branch on Sept 28th and the build is failing. I think it is not fixed properly as it seems to include the following commits.
|
Ok thanks for confirming, looking into it. |
using __MAC_OS_X_VERSION_MIN_REQUIRED instead.
using __MAC_OS_X_VERSION_MIN_REQUIRED instead.
The lit test has been failing since it landed, see e.g. https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/2276/testReport/ I'll revert until this can be fixed. |
The lit test has been failing on green dragon since it landed, e.g. https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/2276/testReport/ This reverts commit a6ea0b0 and follow-up commits ce72c76, a280275, and d705bd2.
The lit test has been failing on green dragon since it landed, e.g. https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/2276/testReport/ This reverts commit a6ea0b0 and follow-up commits ce72c76, a280275, and d705bd2.
available since macOs Ventura.