libc: add clang FORTIFY support
This patch adds clang-style FORTIFY to Bionic. For more information on
FORTIFY, please see https://goo.gl/8HS2dW . This implementation works
for versions of clang that don't support diagnose_if, so please see the
"without diagnose_if" sections. We plan to swap to a diagnose_if-based
FORTIFY later this year (since it doesn't really add any features; it
just simplifies the implementation a lot, and it gives us much prettier
diagnostics)
Bug: 32073964
Test: Builds on angler, bullhead, marlin, sailfish. Bionic CTS tests
pass on Angler and Bullhead.
Change-Id: I607aecbeee81529709b1eee7bef5b0836151eb2b
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index cf50664..117de48 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -71,6 +71,8 @@
#include "private/bionic_fortify.h"
+struct __bionic_zero_size_is_okay_t __bionic_zero_size_is_okay;
+
//
// For more details see:
// http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
diff --git a/libc/bionic/getcwd.cpp b/libc/bionic/getcwd.cpp
index bcd6a57..c2a7e23 100644
--- a/libc/bionic/getcwd.cpp
+++ b/libc/bionic/getcwd.cpp
@@ -34,7 +34,7 @@
extern "C" int __getcwd(char* buf, size_t size);
-char* getcwd(char* buf, size_t size) {
+char* getcwd(char* buf, size_t size) __overloadable {
// You can't specify size 0 unless you're asking us to allocate for you.
if (buf != NULL && size == 0) {
errno = EINVAL;
diff --git a/libc/bionic/poll.cpp b/libc/bionic/poll.cpp
index 23ef90a..eded56a 100644
--- a/libc/bionic/poll.cpp
+++ b/libc/bionic/poll.cpp
@@ -37,7 +37,7 @@
extern "C" int __ppoll(pollfd*, unsigned int, timespec*, const kernel_sigset_t*, size_t);
extern "C" int __pselect6(int, fd_set*, fd_set*, fd_set*, timespec*, void*);
-int poll(pollfd* fds, nfds_t fd_count, int ms) {
+int poll(pollfd* fds, nfds_t fd_count, int ms) __overloadable {
timespec ts;
timespec* ts_ptr = NULL;
if (ms >= 0) {
@@ -47,7 +47,7 @@
return __ppoll(fds, fd_count, ts_ptr, NULL, 0);
}
-int ppoll(pollfd* fds, nfds_t fd_count, const timespec* ts, const sigset_t* ss) {
+int ppoll(pollfd* fds, nfds_t fd_count, const timespec* ts, const sigset_t* ss) __overloadable {
timespec mutable_ts;
timespec* mutable_ts_ptr = NULL;
if (ts != NULL) {