Nullability check for dlfcn module
Bugs: b/245972273
Test: adb shell
Change-Id: I0ecde8a0f1f71b6ec2262ff637d33c518578d54d
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index 68d8bc9..a8066a9 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -36,21 +36,23 @@
typedef struct {
/* Pathname of shared object that contains address. */
- const char* dli_fname;
+ const char* _Nullable dli_fname;
/* Address at which shared object is loaded. */
- void* dli_fbase;
+ void* _Nullable dli_fbase;
/* Name of nearest symbol with address lower than addr. */
- const char* dli_sname;
+ const char* _Nullable dli_sname;
/* Exact address of symbol named in dli_sname. */
- void* dli_saddr;
+ void* _Nullable dli_saddr;
} Dl_info;
-void* dlopen(const char* __filename, int __flag);
-int dlclose(void* __handle);
-char* dlerror(void);
-void* dlsym(void* __handle, const char* __symbol);
-void* dlvsym(void* __handle, const char* __symbol, const char* __version) __INTRODUCED_IN(24);
-int dladdr(const void* __addr, Dl_info* __info);
+void* _Nullable dlopen(const char* _Nullable __filename, int __flag);
+int dlclose(void* _Nonnull __handle);
+char* _Nullable dlerror(void);
+/* (RTLD_DEFAULT is null for LP64, but -1 for LP32) */
+void* _Nullable dlsym(void* __BIONIC_COMPLICATED_NULLNESS __handle, const char* _Nullable __symbol);
+/* (RTLD_DEFAULT is null for LP64, but -1 for LP32) */
+void* _Nullable dlvsym(void* __BIONIC_COMPLICATED_NULLNESS __handle, const char* _Nullable __symbol, const char* _Nullable __version) __INTRODUCED_IN(24);
+int dladdr(const void* _Nonnull __addr, Dl_info* _Nonnull __info);
#define RTLD_LOCAL 0
#define RTLD_LAZY 0x00001
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 939c092..3f70279 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -889,11 +889,14 @@
void* sym;
#if defined(__BIONIC__) && !defined(__LP64__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnonnull"
// RTLD_DEFAULT in lp32 bionic is not (void*)0
// so it can be distinguished from the NULL handle.
sym = dlsym(nullptr, "test");
ASSERT_TRUE(sym == nullptr);
ASSERT_STREQ("dlsym failed: library handle is null", dlerror());
+#pragma clang diagnostic pop
#endif
// Symbol that doesn't exist.
@@ -1008,9 +1011,12 @@
dlerror(); // Clear any pending errors.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnonnull"
// No symbol corresponding to NULL.
ASSERT_EQ(dladdr(nullptr, &info), 0); // Zero on error, non-zero on success.
ASSERT_TRUE(dlerror() == nullptr); // dladdr(3) doesn't set dlerror(3).
+#pragma clang diagnostic pop
// No symbol corresponding to a stack address.
ASSERT_EQ(dladdr(&info, &info), 0); // Zero on error, non-zero on success.